Admin: maskowanie e-maili userow w panelu (jan@fitos.pl -> j*n@f****.pl; lista, konsola, sirownie, wnioski, logi; pelny adres zna tylko user)
This commit is contained in:
@@ -24,6 +24,7 @@ import { Topbar } from '../topbar';
|
||||
import { Brandmark } from './Brandmark';
|
||||
import { Avatar } from './Avatar';
|
||||
import { buildInfo } from '../lib/build-info';
|
||||
import { maskEmail } from '../lib/format';
|
||||
import { cn } from '../lib/utils';
|
||||
|
||||
interface NavItem {
|
||||
@@ -191,7 +192,9 @@ export default function Layout() {
|
||||
const isTrainer = useIsTrainer();
|
||||
const build = buildInfo();
|
||||
const fullName =
|
||||
[user?.firstName, user?.lastName].filter(Boolean).join(' ') || user?.email || '?';
|
||||
[user?.firstName, user?.lastName].filter(Boolean).join(' ') ||
|
||||
user?.nickname ||
|
||||
(user ? maskEmail(user.email) : '?');
|
||||
const roles = [
|
||||
user?.isAdmin ? t('nav.roleAdmin') : null,
|
||||
isTrainer ? t('nav.roleTrainer') : t('nav.roleMember'),
|
||||
@@ -210,7 +213,9 @@ export default function Layout() {
|
||||
<div className="mb-3 flex items-center gap-2.5">
|
||||
<Avatar name={fullName} size={32} />
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-[13px] font-bold">{user?.firstName || user?.email}</div>
|
||||
<div className="truncate text-[13px] font-bold">
|
||||
{user?.firstName || user?.nickname || (user ? maskEmail(user.email) : '')}
|
||||
</div>
|
||||
<div className="text-[11.5px] text-dim">{roles}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ActivityLog } from '../api/types';
|
||||
import { Badge, type BadgeColor } from './ui';
|
||||
import i18n from '../i18n';
|
||||
import { fmtDate, fmtDateTime, fmtTime } from '../lib/format';
|
||||
import { fmtDate, fmtDateTime, fmtTime, maskEmail } from '../lib/format';
|
||||
|
||||
const t = (key: string, options?: Record<string, unknown>): string =>
|
||||
String(i18n.t(`logs:${key}`, options as never));
|
||||
@@ -27,7 +27,7 @@ export function formatLogDate(iso: string) {
|
||||
|
||||
export function actorName(log: ActivityLog) {
|
||||
const { firstName, lastName, email } = log.actor;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || email;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || maskEmail(email);
|
||||
}
|
||||
|
||||
/** Nazwa obiektu z szczegółów wpisu (tytuł planu, nazwa siłowni, nazwa obwodu). */
|
||||
@@ -111,7 +111,7 @@ export function LogTable({ logs }: { logs: ActivityLog[] }) {
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<div className="font-semibold">{actorName(log)}</div>
|
||||
<div className="text-[0.875rem] text-dim">{log.actor.email}</div>
|
||||
<div className="text-[0.875rem] text-dim">{maskEmail(log.actor.email)}</div>
|
||||
<div className="font-mono text-[0.75rem] text-dim/70" title={log.actor.id}>
|
||||
{log.actor.id}
|
||||
</div>
|
||||
|
||||
@@ -2,9 +2,10 @@ import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Search, X } from 'lucide-react';
|
||||
import type { User } from '../api/types';
|
||||
import { maskEmail } from '../lib/format';
|
||||
|
||||
export function userLabel(u: User): string {
|
||||
return [u.firstName, u.lastName].filter(Boolean).join(' ') || u.email;
|
||||
return [u.firstName, u.lastName].filter(Boolean).join(' ') || maskEmail(u.email);
|
||||
}
|
||||
|
||||
/** Przeszukiwalny wybór użytkownika (listę pobiera strona) — wzór: GymPicker z członkostw. */
|
||||
@@ -102,7 +103,7 @@ export function UserPicker({
|
||||
>
|
||||
<span className="min-w-0 truncate">{userLabel(u)}</span>
|
||||
{u.firstName && (
|
||||
<span className="shrink-0 text-[0.875rem] text-dim">{u.email}</span>
|
||||
<span className="shrink-0 text-[0.875rem] text-dim">{maskEmail(u.email)}</span>
|
||||
)}
|
||||
</button>
|
||||
))
|
||||
|
||||
@@ -15,6 +15,27 @@ export function displayName(
|
||||
return u.nickname || [u.firstName, u.lastName].filter(Boolean).join(' ') || fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maska adresu e-mail do wyświetlania w panelu admina: pierwsza i ostatnia litera
|
||||
* local part, pierwsza litera domeny i TLD — reszta jako gwiazdki (np. jan@fitos.pl → j*n@f****.pl).
|
||||
*/
|
||||
export function maskEmail(email: string | null | undefined): string {
|
||||
if (!email) return '—';
|
||||
const at = email.indexOf('@');
|
||||
if (at < 1) return '*';
|
||||
const local = email.slice(0, at);
|
||||
const localMask =
|
||||
local.length <= 2
|
||||
? `${local.slice(0, 1)}${'*'.repeat(Math.max(local.length - 1, 1))}`
|
||||
: `${local.slice(0, 1)}${'*'.repeat(local.length - 2)}${local.slice(-1)}`;
|
||||
const domain = email.slice(at + 1);
|
||||
const dot = domain.indexOf('.');
|
||||
const firstLabel = dot < 0 ? domain : domain.slice(0, dot);
|
||||
const rest = dot < 0 ? '' : domain.slice(dot);
|
||||
const domainMask = `${firstLabel.slice(0, 1)}${'*'.repeat(Math.max(firstLabel.length - 1, 1))}${rest}`;
|
||||
return `${localMask}@${domainMask}`;
|
||||
}
|
||||
|
||||
export function fmtDate(iso: string | null | undefined): string {
|
||||
if (!iso) return '—';
|
||||
return new Date(iso).toLocaleDateString(currentTag(), {
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
import type { BadgeColor } from '../components/ui';
|
||||
import { Avatar } from '../components/Avatar';
|
||||
import { formatAvailability } from '../lib/availability';
|
||||
import { fmtDate } from '../lib/format';
|
||||
import { fmtDate, maskEmail } from '../lib/format';
|
||||
import i18n from '../i18n';
|
||||
import { useTopbar } from '../topbar';
|
||||
|
||||
@@ -47,7 +47,7 @@ function claimTypeLabel(claim: GymClaim) {
|
||||
|
||||
function applicantName(claim: GymClaim) {
|
||||
const { firstName, lastName, email } = claim.user;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || email;
|
||||
return [firstName, lastName].filter(Boolean).join(' ') || maskEmail(email);
|
||||
}
|
||||
|
||||
/** Pobranie pliku przez `apiBlob` (Bearer + rotacja 401) → tymczasowy <a download>. */
|
||||
@@ -284,7 +284,7 @@ export function VerificationDetail() {
|
||||
<InfoItem label={tr('companyNameLabel')}>{claim.companyName || '—'}</InfoItem>
|
||||
<InfoItem label={tr('nipLabel')}>{claim.nip || '—'}</InfoItem>
|
||||
<InfoItem label={tr('phoneLabel')}>{claim.phone || '—'}</InfoItem>
|
||||
<InfoItem label={tr('emailLabel')}>{claim.email || '—'}</InfoItem>
|
||||
<InfoItem label={tr('emailLabel')}>{claim.email ? maskEmail(claim.email) : '—'}</InfoItem>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
@@ -297,7 +297,7 @@ export function VerificationDetail() {
|
||||
{applicantName(claim)}
|
||||
</span>
|
||||
</InfoItem>
|
||||
<InfoItem label={tr('emailLabel')}>{claim.user.email}</InfoItem>
|
||||
<InfoItem label={tr('emailLabel')}>{maskEmail(claim.user.email)}</InfoItem>
|
||||
{claim.user.phone != null && (
|
||||
<InfoItem label={tr('phoneLabel')}>{claim.user.phone}</InfoItem>
|
||||
)}
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
} from '../../components/ui';
|
||||
import { AvailabilityEditor } from '../../components/AvailabilityEditor';
|
||||
import { dayFull, formatDayRangeClock, normalizeAvailability } from '../../lib/availability';
|
||||
import { fmtDate, fmtDateTime } from '../../lib/format';
|
||||
import { fmtDate, fmtDateTime, maskEmail } from '../../lib/format';
|
||||
import { GYM_ROLE_META, GYM_ROLE_ORDER } from '../../lib/roles';
|
||||
import { useAdminUsers } from '../users/user-queries';
|
||||
import { useGymAuditLogs, useGymMembers, useGymRelated } from '../../api/queries';
|
||||
@@ -70,7 +70,16 @@ function HoursList({ gym }: { gym: Gym }) {
|
||||
}
|
||||
|
||||
function memberLabel(m: AdminGymMemberItem): string {
|
||||
return [m.user.firstName, m.user.lastName].filter(Boolean).join(' ') || m.user.email;
|
||||
return personName(m.user);
|
||||
}
|
||||
|
||||
/* Nazwa osoby; fallback na zamaskowany e-mail. */
|
||||
function personName(p: {
|
||||
firstName?: string | null;
|
||||
lastName?: string | null;
|
||||
email: string;
|
||||
}): string {
|
||||
return [p.firstName, p.lastName].filter(Boolean).join(' ') || maskEmail(p.email);
|
||||
}
|
||||
|
||||
/* Rola jako pigułki — te same etykiety co na członkostwach usera. */
|
||||
@@ -122,7 +131,7 @@ function MembersTable({
|
||||
>
|
||||
<td className="px-3 py-2.5 align-top">
|
||||
<div className="font-semibold">{memberLabel(m)}</div>
|
||||
<div className="text-[0.78rem] text-dim">{m.user.email}</div>
|
||||
<div className="text-[0.78rem] text-dim">{maskEmail(m.user.email)}</div>
|
||||
</td>
|
||||
<td className="px-3 py-2.5 align-top">
|
||||
<RoleBadges roles={m.roles} />
|
||||
@@ -590,8 +599,7 @@ export default function GymDetail() {
|
||||
to={`/users/${c.user.id}`}
|
||||
className="font-semibold hover:text-accent-text"
|
||||
>
|
||||
{[c.user.firstName, c.user.lastName].filter(Boolean).join(' ') ||
|
||||
c.user.email}
|
||||
{personName(c.user)}
|
||||
</Link>
|
||||
<Badge
|
||||
color={
|
||||
@@ -631,14 +639,10 @@ export default function GymDetail() {
|
||||
to={`/users/${inv.user.id}`}
|
||||
className="font-semibold hover:text-accent-text"
|
||||
>
|
||||
{[inv.user.firstName, inv.user.lastName].filter(Boolean).join(' ') ||
|
||||
inv.user.email}
|
||||
{personName(inv.user)}
|
||||
</Link>
|
||||
<span className="text-[0.76rem] text-dim">
|
||||
{t('invitedBy')}{' '}
|
||||
{[inv.invitedBy.firstName, inv.invitedBy.lastName]
|
||||
.filter(Boolean)
|
||||
.join(' ') || inv.invitedBy.email}
|
||||
{t('invitedBy')} {personName(inv.invitedBy)}
|
||||
</span>
|
||||
<Badge
|
||||
color={
|
||||
|
||||
@@ -8,10 +8,10 @@ import { Badge, Card, EmptyState, ErrorText, Loading, Select } from '../../compo
|
||||
import { formatDayRangeClock, normalizeAvailability } from '../../lib/availability';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { fmtDate } from '../../lib/format';
|
||||
import { fmtDate, maskEmail } from '../../lib/format';
|
||||
|
||||
function ownerLabel(o: AdminGymListItem['owners'][number]): string {
|
||||
return [o.firstName, o.lastName].filter(Boolean).join(' ') || o.email;
|
||||
return [o.firstName, o.lastName].filter(Boolean).join(' ') || maskEmail(o.email);
|
||||
}
|
||||
|
||||
/* Wiersz listy — klik na całej szerokości prowadzi do konsoli siłowni w panelu admina;
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
Loading,
|
||||
StatCell,
|
||||
} from '../../components/ui';
|
||||
import { fmtDate, fmtDateTime, displayName } from '../../lib/format';
|
||||
import { fmtDate, fmtDateTime, displayName, maskEmail } from '../../lib/format';
|
||||
import {
|
||||
detailsText,
|
||||
actionLabel,
|
||||
@@ -39,14 +39,14 @@ import { GYM_ROLE_META, GYM_ROLE_ORDER } from '../../lib/roles';
|
||||
import { UserRestrictionModal } from './UserRestrictionModal';
|
||||
import { useAdminUser, useUserActivity, useUserClaims } from './user-queries';
|
||||
|
||||
/** Nazwa wyświetlana użytkownika (nick → imię+nazwisko → e-mail). */
|
||||
/** Nazwa wyświetlana użytkownika (nick → imię+nazwisko → zamaskowany e-mail). */
|
||||
export function userDisplayName(u: {
|
||||
nickname?: string | null;
|
||||
firstName?: string | null;
|
||||
lastName?: string | null;
|
||||
email: string;
|
||||
}): string {
|
||||
return displayName(u) === '—' ? u.email : displayName(u);
|
||||
return displayName(u) === '—' ? maskEmail(u.email) : displayName(u);
|
||||
}
|
||||
|
||||
/* Rola jako pigułki — te same etykiety co w konsoli siłowni. */
|
||||
@@ -150,7 +150,7 @@ export default function UserDetail() {
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 border-b border-line px-4 py-3 text-[0.85rem] text-dim sm:px-5">
|
||||
<span className="flex items-center gap-2.5">
|
||||
<Avatar name={name} size={30} />
|
||||
<b className="text-ink">{user.email}</b>
|
||||
<b className="text-ink">{maskEmail(user.email)}</b>
|
||||
</span>
|
||||
<span className="flex flex-wrap items-center gap-1.5">
|
||||
{user.status === 'SUSPENDED' && (
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Building2, Check, ChevronDown, ShieldCheck, Trash2, UserPlus } from 'lu
|
||||
import { api } from '../../api/client';
|
||||
import type { Gym, GymRole, User } from '../../api/types';
|
||||
import { ADMIN_ROLE_META, GYM_ROLE_META } from '../../lib/roles';
|
||||
import { todayStr } from '../../lib/format';
|
||||
import { todayStr, maskEmail } from '../../lib/format';
|
||||
import { GymPicker } from '../../components/GymPicker';
|
||||
import { GymRolePicker } from '../../components/GymRolePicker';
|
||||
import {
|
||||
@@ -222,7 +222,8 @@ export default function UserForm() {
|
||||
return;
|
||||
}
|
||||
|
||||
// EDYCJA: PATCH konta (tożsamość/dostęp), potem porządkowanie członkostw
|
||||
// EDYCJA: PATCH konta (tożsamość/dostęp), potem porządkowanie członkostw.
|
||||
// E-mail w edycji jest ukryty (zna go tylko user) — PATCH przenosi niezmieniony adres.
|
||||
const patchBody: Record<string, unknown> = {
|
||||
email: form.email.trim(),
|
||||
firstName: form.firstName || null,
|
||||
@@ -315,12 +316,18 @@ export default function UserForm() {
|
||||
/>
|
||||
</Field>
|
||||
<Field label={t('auth:email')}>
|
||||
<Input
|
||||
type="email"
|
||||
value={form.email}
|
||||
onChange={(e) => setForm({ ...form, email: e.target.value })}
|
||||
required
|
||||
/>
|
||||
{isEdit ? (
|
||||
// w edycji e-mail jest zamaskowany i tylko do odczytu (zna go tylko user);
|
||||
// PATCH poniżej przenosi niezmieniony, pełny adres z formularza
|
||||
<Input value={maskEmail(form.email)} readOnly disabled />
|
||||
) : (
|
||||
<Input
|
||||
type="email"
|
||||
value={form.email}
|
||||
onChange={(e) => setForm({ ...form, email: e.target.value })}
|
||||
required
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
<Field label={t('birthDate')}>
|
||||
<Input
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Badge, Card, EmptyState, ErrorText, ListRow, Loading } from '../../comp
|
||||
import { Avatar } from '../../components/Avatar';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { ageFromBirthDate, fmtDate } from '../../lib/format';
|
||||
import { ageFromBirthDate, fmtDate, maskEmail } from '../../lib/format';
|
||||
import { userDisplayName } from './UserDetail';
|
||||
|
||||
export default function UsersList() {
|
||||
@@ -65,7 +65,7 @@ export default function UsersList() {
|
||||
}
|
||||
meta={
|
||||
<>
|
||||
{u.email}
|
||||
{maskEmail(u.email)}
|
||||
{ageFromBirthDate(u.birthDate) != null
|
||||
? ` · ${t('ageWord', { age: ageFromBirthDate(u.birthDate) })}`
|
||||
: ''}
|
||||
|
||||
@@ -268,6 +268,12 @@ describe('admin GymDetail (konsola)', () => {
|
||||
expect(within(table).getByText('Anna Kowalska')).toBeInTheDocument();
|
||||
const trainerRow = within(table).getByText('Jan Nowak').closest('tr');
|
||||
expect(within(trainerRow as HTMLElement).getByText('Trener')).toBeInTheDocument();
|
||||
// członkowie: e-maile zamaskowane; pełne adresy nigdy w DOM
|
||||
expect(within(table).getByText('j*n@f****.pl')).toBeInTheDocument();
|
||||
expect(within(table).getByText('a**a@f****.pl')).toBeInTheDocument();
|
||||
expect(screen.queryByText('jan@fitos.pl')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('anna@fitos.pl')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('ola@fitos.pl')).not.toBeInTheDocument();
|
||||
// brak przycisków w tabeli — akcje członka dopiero w menu z kliknięcia wiersza
|
||||
expect(within(table).queryAllByRole('button')).toHaveLength(0);
|
||||
|
||||
|
||||
@@ -93,10 +93,13 @@ describe('admin Logs page', () => {
|
||||
expect(await screen.findByText('20.08.2026')).toBeInTheDocument();
|
||||
// szczegóły jako naturalny tekst (tytuł i actorId są w innych kolumnach)
|
||||
expect(await screen.findByText('start: 2026-08-24')).toBeInTheDocument();
|
||||
// ID aktora pod e-mailem w kolumnie „Użytkownik"
|
||||
// ID aktora w kolumnie „Użytkownik"
|
||||
expect(screen.getAllByText('user-1').length).toBeGreaterThan(0);
|
||||
// aktor: e-mail pod imieniem i nazwiskiem
|
||||
expect(screen.getByText('anna@test.local')).toBeInTheDocument();
|
||||
// aktor: zamaskowany e-mail pod imieniem i nazwiskiem; pełny adres nigdy w DOM
|
||||
expect(screen.getByText('a**a@t***.local')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('j*n@t***.local').length).toBeGreaterThan(0);
|
||||
expect(screen.queryByText('anna@test.local')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('jan@test.local')).not.toBeInTheDocument();
|
||||
// etykiety akcji
|
||||
expect(screen.getAllByText('Plan aktywowany').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText('Sesja zakończona').length).toBeGreaterThan(0);
|
||||
@@ -161,7 +164,8 @@ describe('admin Logs page', () => {
|
||||
// wyszukiwarka jest w menu kontekstowym (Layout) — filtr ustawiamy przez store
|
||||
act(() => useListSearch.getState().setQuery('logs', 'anna'));
|
||||
expect(screen.queryByText('Jan Kowalski')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('anna@test.local')).toBeInTheDocument();
|
||||
// LOG2: aktor Anna bez nazwiska — widoczna sama pierwsza imienna część
|
||||
expect(screen.getByText('Anna')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an error when the logs request fails', async () => {
|
||||
|
||||
@@ -135,8 +135,9 @@ describe('admin UserDetail (konsola użytkownika)', () => {
|
||||
expect(await screen.findByRole('heading', { level: 2, name: 'jano' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: 'Wróć' })).toHaveAttribute('href', '/users');
|
||||
|
||||
// panel podsumowania: e-mail + nick + badge admina + pasek danych administracyjnych
|
||||
expect(screen.getByText('jan@test.local')).toBeInTheDocument();
|
||||
// panel podsumowania: zamaskowany e-mail + nick + badge admina + pasek danych administracyjnych
|
||||
expect(screen.getByText('j*n@t***.local')).toBeInTheDocument();
|
||||
expect(screen.queryByText('jan@test.local')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('@jano')).toBeInTheDocument();
|
||||
expect(screen.getByText('Admin')).toBeInTheDocument();
|
||||
expect(screen.getByText('Ostatnie logowanie')).toBeInTheDocument();
|
||||
|
||||
@@ -279,10 +279,14 @@ describe('admin UserForm — kreator edycji', () => {
|
||||
{ match: '/admin/gyms', reply: () => ({ gyms: [GYM_A, GYM_B] }) },
|
||||
{ match: '/admin/users', reply: () => ({ users: [EDITED] }) },
|
||||
]);
|
||||
renderForm('/users/u1/edit');
|
||||
const { container } = renderForm('/users/u1/edit');
|
||||
// dane i członkostwo wczytane z użytkownika — krok 3 jest też w edycji
|
||||
expect(await screen.findByDisplayValue('jan@test.local')).toBeInTheDocument();
|
||||
expect(screen.getByDisplayValue('Jan')).toBeInTheDocument();
|
||||
expect(await screen.findByDisplayValue('Jan')).toBeInTheDocument();
|
||||
// w edycji e-mail zamaskowany i tylko do odczytu (pełny adres zna tylko user)
|
||||
const emailInput = container.querySelector('input[type="email"]');
|
||||
expect(emailInput).toBeNull();
|
||||
const masked = container.querySelector('input[readonly]') as HTMLInputElement | null;
|
||||
expect(masked?.value).toBe('j*n@t***.local');
|
||||
expect(screen.getByDisplayValue('1996-05-05')).toBeInTheDocument();
|
||||
expect(await screen.findByText('Członkostwa w siłowniach')).toBeInTheDocument();
|
||||
expect(screen.getByDisplayValue('Fit Factory')).toBeInTheDocument();
|
||||
@@ -296,7 +300,7 @@ describe('admin UserForm — kreator edycji', () => {
|
||||
]);
|
||||
const user = userEvent.setup();
|
||||
renderForm('/users/u1/edit');
|
||||
await screen.findByDisplayValue('jan@test.local');
|
||||
await screen.findByDisplayValue('Jan');
|
||||
|
||||
// edycja = tożsamość/dostęp: zmiana nazwiska; skłon ról bez zmian = zero żądań członkostw
|
||||
const inputs = document.querySelectorAll('input');
|
||||
@@ -308,8 +312,10 @@ describe('admin UserForm — kreator edycji', () => {
|
||||
const accountPatch = calls.find(
|
||||
(c) => c.init?.method === 'PATCH' && c.url === `${API_BASE}/admin/users/u1`,
|
||||
);
|
||||
// e-mail niewidoczny w formularzu, ale PATCH przenosi go bez zmian
|
||||
expect(JSON.parse(accountPatch?.init?.body as string)).toMatchObject({
|
||||
lastName: 'Nowak',
|
||||
email: 'jan@test.local',
|
||||
isAdmin: true,
|
||||
});
|
||||
expect(calls.some((c) => c.url.includes('/memberships'))).toBe(false);
|
||||
|
||||
@@ -96,8 +96,11 @@ describe('admin UsersList page', () => {
|
||||
it('lists users fetched from the API', async () => {
|
||||
mockFetchSequence(jsonResponse(200, { users: [U1, U2] }));
|
||||
renderUsers();
|
||||
expect(await screen.findByText('jan@test.local · wiek: 30')).toBeInTheDocument();
|
||||
expect(screen.getByText('admin@test.local')).toBeInTheDocument();
|
||||
// meta z zamaskowanym e-mailem; pełny adres nigdy nie trafia do DOM
|
||||
expect(await screen.findByText('j*n@t***.local · wiek: 30')).toBeInTheDocument();
|
||||
expect(screen.getByText('a***n@t***.local')).toBeInTheDocument();
|
||||
expect(screen.queryByText('jan@test.local')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('admin@test.local')).not.toBeInTheDocument();
|
||||
// 'Admin' appears both as the user name link and as the admin badge
|
||||
expect(screen.getAllByText('Admin')).toHaveLength(2);
|
||||
});
|
||||
@@ -105,11 +108,12 @@ describe('admin UsersList page', () => {
|
||||
it('filters users by the search box', async () => {
|
||||
mockFetchSequence(jsonResponse(200, { users: [U1, U2] }));
|
||||
renderUsers();
|
||||
await screen.findByText('jan@test.local · wiek: 30');
|
||||
await screen.findByText('j*n@t***.local · wiek: 30');
|
||||
// wyszukiwarka jest w menu kontekstowym (Layout) — filtr ustawiamy przez store
|
||||
act(() => useListSearch.getState().setQuery('users', 'admin'));
|
||||
expect(screen.queryByText('jan@test.local · wiek: 30')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('admin@test.local')).toBeInTheDocument();
|
||||
expect(screen.queryByText('j*n@t***.local · wiek: 30')).not.toBeInTheDocument();
|
||||
// wyszukiwarka dopasowuje po pełnym e-mailu (serwerowo po q), lecz UI pokazuje maskę
|
||||
expect(screen.getByText('a***n@t***.local')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an error when the users request fails', async () => {
|
||||
|
||||
@@ -160,8 +160,9 @@ test('kliknięcie w użytkownika otwiera konsolę administracyjną', async ({ pa
|
||||
// topbar = kategoria „Użytkownik”, nazwa dopiero w treści (h2) + „← Wróć”
|
||||
await expect(page.getByRole('heading', { level: 1, name: 'Użytkownik' })).toBeVisible();
|
||||
await expect(page.getByRole('heading', { level: 2, name: 'Jan Kowalski' })).toBeVisible();
|
||||
// panel podsumowania: e-mail + pasek danych administracyjnych
|
||||
await expect(page.getByText('jan@fitos.pl')).toBeVisible();
|
||||
// panel podsumowania: zamaskowany e-mail + pasek danych administracyjnych (pełny adres zna tylko user)
|
||||
await expect(page.getByText('j*n@f****.pl')).toBeVisible();
|
||||
await expect(page.getByText('jan@fitos.pl')).toHaveCount(0);
|
||||
await expect(page.getByText('Ostatnie logowanie')).toBeVisible();
|
||||
await expect(page.getByText('Członkostwa', { exact: true })).toBeVisible();
|
||||
await expect(page.getByText('Konto od')).toBeVisible();
|
||||
@@ -425,7 +426,9 @@ test('kreator edycji: zapis bez zmian członkostw wysyła tylko PATCH konta', as
|
||||
await page.getByRole('button', { name: 'Edytuj' }).click();
|
||||
await expect(page).toHaveURL(/\/users\/user-1\/edit$/);
|
||||
await expect(page.getByRole('heading', { name: 'Edycja użytkownika' })).toBeVisible();
|
||||
await expect(page.locator('input[type="email"]')).toHaveValue('jan@fitos.pl');
|
||||
// e-mail w edycji zamaskowany i tylko do odczytu (pełny adres zna tylko user)
|
||||
await expect(page.locator('input[readonly]')).toHaveValue('j*n@f****.pl');
|
||||
await expect(page.locator('input[type="email"]')).toHaveCount(0);
|
||||
// pełny edytor: krok członkostw wczytany (skłon ról bez zmian = zero żądań członkostw)
|
||||
await expect(page.getByRole('heading', { name: 'Członkostwa w siłowniach' })).toBeVisible();
|
||||
await expect(page.getByRole('combobox', { name: 'Szukaj siłowni' })).toHaveValue('Fit Factory');
|
||||
|
||||
@@ -38,9 +38,10 @@ test('szczegóły wniosku o nową realną: dane siłowni + wnioskodawca', async
|
||||
|
||||
// dane siłowni (typ nowa realna)
|
||||
await expect(page.getByText('ul. Długa 5, Warszawa')).toBeVisible();
|
||||
// wnioskodawca
|
||||
// wnioskodawca — e-mail zamaskowany (pełny adres zna tylko user)
|
||||
await expect(page.getByText('Anna Nowa')).toBeVisible();
|
||||
await expect(page.getByText('nowa@fitos.pl').first()).toBeVisible();
|
||||
await expect(page.getByText('n**a@f****.pl').first()).toBeVisible();
|
||||
await expect(page.getByText('nowa@fitos.pl')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('szczegóły wniosku o weryfikację: siłownia + dokument do pobrania', async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user