Admin-teksten en merklogo: Weergavenaam, Wachtwoord wijzigen, Eerste account aanmaken, logo per thema

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 14:36:10 +01:00
co-authored by Claude Sonnet 5.5
parent cd81723bf5
commit 55dcab121b
20 changed files with 350 additions and 25 deletions
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest';
import { screen } from '@testing-library/react';
import { renderWithProviders } from '@/test/utils';
import { BrandLogo } from '@/components/layout/BrandLogo';
describe('BrandLogo', () => {
it('falls back to the application name with its dot when the site has no logo', () => {
renderWithProviders(<BrandLogo logo={null} />);
expect(screen.getByTestId('brand-fallback')).toHaveTextContent('SlpModularCms');
expect(screen.queryByTestId('brand-logo')).not.toBeInTheDocument();
});
it('shows the default (unthemed) admin the same way', () => {
renderWithProviders(<BrandLogo />);
expect(screen.getByTestId('brand-fallback')).toBeInTheDocument();
});
it('draws the logo for both colour modes, named for screen readers', () => {
renderWithProviders(<BrandLogo logo={{ onLight: '/admin/l.png', onDark: '/admin/d.png' }} />);
const images = screen.getAllByRole('img', { hidden: true });
expect(images).toHaveLength(2);
expect(images.map((i) => i.getAttribute('src'))).toEqual(['/admin/l.png', '/admin/d.png']);
images.forEach((i) => expect(i).toHaveAttribute('alt', 'SlpModularCms'));
expect(screen.queryByTestId('brand-fallback')).not.toBeInTheDocument();
});
});
@@ -0,0 +1,36 @@
import { useTranslation } from 'react-i18next';
import { cn } from '@/lib/utils';
import { getBrand } from '@/lib/brand';
import type { BrandLogo as BrandLogoFiles } from '@/lib/brand';
interface BrandLogoProps {
/** Overrides the site brand; mainly for tests and, later, a logo loaded from site settings. */
logo?: BrandLogoFiles | null;
className?: string;
}
/**
* The site's logo, or, when it has none, the application name with its dot (what the admin always
* showed). The single place the admin draws the brand: do not hardcode it elsewhere.
*/
export function BrandLogo({ logo, className }: BrandLogoProps) {
const { t } = useTranslation();
const resolved = logo === undefined ? getBrand().logo : logo;
const name = t('common.appName');
if (resolved === null) {
return (
<div className={cn('flex items-center gap-2', className)} data-testid="brand-fallback">
<span className="h-3 w-3 rounded-full bg-primary" aria-hidden="true" />
<span className="text-lg font-semibold">{name}</span>
</div>
);
}
return (
<div className={cn('flex items-center', className)} data-testid="brand-logo">
<img src={resolved.onLight} alt={name} className="h-10 w-auto dark:hidden" />
<img src={resolved.onDark} alt={name} className="hidden h-10 w-auto dark:block" />
</div>
);
}
+2 -1
View File
@@ -1,5 +1,6 @@
import { Menu } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { BrandLogo } from './BrandLogo';
interface MobileBarProps {
onMenuOpen: () => void;
@@ -22,7 +23,7 @@ export function MobileBar({ onMenuOpen }: MobileBarProps) {
>
<Menu className="size-5" />
</button>
<span className="font-semibold">{t('common.appName')}</span>
<BrandLogo className="[&_img]:h-8 [&_span]:text-base" />
</header>
);
}
@@ -81,6 +81,28 @@ describe('InviteUserDialog', () => {
expect(await screen.findByTestId('form-error-banner')).toBeInTheDocument();
});
it('shows the specific conflict message instead of a generic error', async () => {
server.use(
http.post(`${API_BASE}/api/v1/Users/invite`, () =>
HttpResponse.json(
{ status: 409, title: 'Conflict', detail: 'Er staat al een openstaande uitnodiging voor dit e-mailadres.' },
{ status: 409 },
),
),
);
await openDialog();
await userEvent.type(screen.getByTestId('invite-dialog-email'), 'dup@example.com');
await userEvent.click(screen.getByTestId('invite-dialog-role'));
const opts = await screen.findAllByRole('option');
await userEvent.click(opts.find((o) => o.textContent === 'User')!);
await userEvent.click(screen.getByTestId('invite-dialog-submit'));
expect(await screen.findByTestId('form-error-banner')).toHaveTextContent(
'Er staat al een openstaande uitnodiging voor dit e-mailadres.',
);
});
it('resets to step 1 when dialog is closed and reopened', async () => {
await openDialog();
await userEvent.type(screen.getByTestId('invite-dialog-email'), 'test@example.com');
@@ -24,7 +24,7 @@ import { FormErrorBanner } from '@/components/ui/FormErrorBanner';
import { FieldError } from '@/components/ui/FieldError';
import { useInviteUser } from '@/features/users/services/useUsers';
import { inviteUserSchema, type InviteUserFormData } from '@/features/users/schemas/users';
import { NetworkError } from '@/lib/api-client';
import { NetworkError, ProblemDetailsError } from '@/lib/api-client';
interface InviteUserDialogProps {
open: boolean;
@@ -40,6 +40,9 @@ export function InviteUserDialog({ open, onOpenChange }: InviteUserDialogProps)
onError: (err) => {
if (err instanceof NetworkError) {
setServerError(t('errors.network'));
} else if (err instanceof ProblemDetailsError && err.status === 409 && err.problem.detail) {
// The server words the conflict (user exists / open invitation exists) in Dutch.
setServerError(err.problem.detail);
} else {
setServerError(t('errors.generic'));
}
@@ -6,6 +6,7 @@ import { renderApp, mockAuthenticated, mockGuest } from '@/test/utils';
import { server } from '@/mocks/server';
import { API_BASE } from '@/features/auth/mocks/fixtures';
import { _resetSetupStatusCache } from '@/router';
import i18n from '@/i18n/config';
beforeEach(() => {
_resetSetupStatusCache();
@@ -22,6 +23,23 @@ describe('ProfilePage', () => {
expect(screen.getByTestId('profile-role-badge')).toBeInTheDocument();
});
it('titles the password card with what it does, not "Security"', async () => {
mockAuthenticated();
renderApp('/profile');
const title = await screen.findByTestId('profile-security-title', {}, { timeout: 10000 });
expect(title).toHaveTextContent(i18n.t('profile.securityTitle'));
expect(title).not.toHaveTextContent('Security');
expect(i18n.t('profile.securityTitle', { lng: 'nl' })).toBe('Wachtwoord wijzigen');
});
it('labels the name field "Weergavenaam" in Dutch', () => {
expect(i18n.t('profile.name', { lng: 'nl' })).toBe('Weergavenaam');
expect(i18n.t('inviteComplete.nameLabel', { lng: 'nl' })).toBe('Weergavenaam');
expect(i18n.t('setup.nameLabel', { lng: 'nl' })).toBe('Weergavenaam');
expect(i18n.t('setup.title', { lng: 'nl' })).toBe('Eerste account aanmaken');
});
it('pre-fills name and email from authenticated user', async () => {
mockAuthenticated();
renderApp('/profile');
@@ -265,7 +265,9 @@ export function ProfilePage() {
{/* Security card */}
<Card>
<CardHeader>
<CardTitle className="text-base">Security</CardTitle>
<CardTitle className="text-base" data-testid="profile-security-title">
{t('profile.securityTitle')}
</CardTitle>
</CardHeader>
<CardContent>
<Button
@@ -0,0 +1,39 @@
import { describe, expect, it, vi } from 'vitest';
import { screen } from '@testing-library/react';
import { renderWithProviders } from '@/test/utils';
import { DeleteUserDialog } from '@/features/users/components/DeleteUserDialog';
import type { UserListItem } from '@/features/users/services/types';
function userItem(overrides: Partial<UserListItem>): UserListItem {
return {
id: '22222222-2222-2222-2222-222222222222',
email: 'info@x.nl',
name: 'Bryan',
role: 'User',
isActive: true,
createdAt: '2026-01-01T00:00:00Z',
invitationPending: false,
inviteLink: null,
...overrides,
} as UserListItem;
}
function renderDialog(user: UserListItem) {
return renderWithProviders(
<DeleteUserDialog user={user} open onOpenChange={vi.fn()} onConfirm={vi.fn()} isPending={false} />,
);
}
describe('DeleteUserDialog', () => {
it('names the person and their e-mail address', async () => {
renderDialog(userItem({}));
expect(await screen.findByTestId('delete-user-dialog')).toHaveTextContent('Bryan (info@x.nl)');
});
it('does not repeat the address when the account has no display name', async () => {
renderDialog(userItem({ name: 'info@x.nl' }));
const text = (await screen.findByTestId('delete-user-dialog')).textContent ?? '';
expect(text).toContain('info@x.nl');
expect(text).not.toContain('info@x.nl (info@x.nl)');
});
});
@@ -28,6 +28,9 @@ export function DeleteUserDialog({
const { t } = useTranslation();
if (!user) return null;
// Accounts without a display name come back with the e-mail address as their name; "a@b (a@b)" is noise.
const hasName = user.name.trim() !== '' && user.name.toLowerCase() !== user.email.toLowerCase();
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-md" data-testid="delete-user-dialog">
@@ -36,7 +39,9 @@ export function DeleteUserDialog({
<DialogDescription>
{user.invitationPending
? t('users.delete.descriptionPending', { email: user.email })
: t('users.delete.description', { name: user.name, email: user.email })}
: hasName
? t('users.delete.description', { name: user.name, email: user.email })
: t('users.delete.descriptionNoName', { email: user.email })}
</DialogDescription>
</DialogHeader>
<DialogFooter className="gap-2">
@@ -37,8 +37,8 @@
}
},
"setup": {
"title": "System Setup",
"nameLabel": "Full name",
"title": "Create first account",
"nameLabel": "Display name",
"emailLabel": "Email",
"passwordLabel": "Password",
"confirmPasswordLabel": "Confirm password",
@@ -53,7 +53,7 @@
"inviteComplete": {
"title": "Complete your account",
"emailLabel": "Email",
"nameLabel": "Full name",
"nameLabel": "Display name",
"passwordLabel": "Password",
"confirmPasswordLabel": "Confirm password",
"submitButton": "Complete setup",
@@ -113,6 +113,7 @@
"delete": {
"title": "Delete user",
"description": "Are you sure you want to delete {{name}} ({{email}})? This action cannot be undone.",
"descriptionNoName": "Are you sure you want to delete {{email}}? This action cannot be undone.",
"descriptionPending": "Are you sure you want to delete the pending invitation for {{email}}? This action cannot be undone.",
"confirmButton": "Delete",
"success": "{{name}} has been deleted."
@@ -151,12 +152,13 @@
},
"profile": {
"title": "My Profile",
"name": "Full name",
"name": "Display name",
"email": "Email address",
"role": "Role",
"save": "Save changes",
"saving": "Saving…",
"saveSuccess": "Profile updated successfully",
"securityTitle": "Change password",
"changePassword": "Change password",
"changePasswordDialog": {
"title": "Change Password",
@@ -37,8 +37,8 @@
}
},
"setup": {
"title": "Systeeminstallatie",
"nameLabel": "Volledige naam",
"title": "Eerste account aanmaken",
"nameLabel": "Weergavenaam",
"emailLabel": "E-mail",
"passwordLabel": "Wachtwoord",
"confirmPasswordLabel": "Wachtwoord bevestigen",
@@ -53,7 +53,7 @@
"inviteComplete": {
"title": "Account voltooien",
"emailLabel": "E-mail",
"nameLabel": "Volledige naam",
"nameLabel": "Weergavenaam",
"passwordLabel": "Wachtwoord",
"confirmPasswordLabel": "Wachtwoord bevestigen",
"submitButton": "Setup voltooien",
@@ -113,6 +113,7 @@
"delete": {
"title": "Gebruiker verwijderen",
"description": "Weet je zeker dat je {{name}} ({{email}}) wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
"descriptionNoName": "Weet je zeker dat je {{email}} wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
"descriptionPending": "Weet je zeker dat je de openstaande uitnodiging voor {{email}} wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
"confirmButton": "Verwijderen",
"success": "{{name}} is verwijderd."
@@ -151,12 +152,13 @@
},
"profile": {
"title": "Mijn profiel",
"name": "Volledige naam",
"name": "Weergavenaam",
"email": "E-mailadres",
"role": "Rol",
"save": "Wijzigingen opslaan",
"saving": "Opslaan…",
"saveSuccess": "Profiel succesvol bijgewerkt",
"securityTitle": "Wachtwoord wijzigen",
"changePassword": "Wachtwoord wijzigen",
"changePasswordDialog": {
"title": "Wachtwoord wijzigen",
+26
View File
@@ -0,0 +1,26 @@
import { describe, expect, it } from 'vitest';
import { getBrand, themeLogo } from '@/lib/brand';
describe('themeLogo', () => {
it('points at the emitted logo files under the app base path', () => {
expect(themeLogo(true, '/admin/')).toEqual({
onLight: '/admin/brand-logo-on-light.png',
onDark: '/admin/brand-logo-on-dark.png',
});
});
it('tolerates a base without trailing slash and the dev root', () => {
expect(themeLogo(true, '/admin')?.onLight).toBe('/admin/brand-logo-on-light.png');
expect(themeLogo(true, '/')?.onDark).toBe('/brand-logo-on-dark.png');
});
it('has no logo when the theme ships none', () => {
expect(themeLogo(false)).toBeNull();
});
});
describe('getBrand', () => {
it('has no logo without a theme (the default admin is unchanged)', () => {
expect(getBrand().logo).toBeNull();
});
});
+33
View File
@@ -0,0 +1,33 @@
/**
* The site's brand as the admin shows it: one place, so where it comes from can change later
* without touching the components that draw it.
*
* Today the logo is a build-time theme asset (themes/<VITE_THEME>/logo-on-*.png, emitted by
* vite.config.ts). When brand settings become editable (site settings), only getBrand() changes:
* it would return the stored logo URLs instead, and BrandLogo keeps working as is.
*/
export interface BrandLogo {
/** For light backgrounds (dark ink). */
onLight: string;
/** For dark backgrounds (light ink). */
onDark: string;
}
export interface Brand {
/** Absent when the site has no logo: callers fall back to the application name. */
logo: BrandLogo | null;
}
declare const __THEME_HAS_LOGO__: boolean | undefined;
export function themeLogo(hasLogo: boolean, base: string = import.meta.env.BASE_URL): BrandLogo | null {
if (!hasLogo) return null;
const prefix = base.endsWith('/') ? base : `${base}/`;
return { onLight: `${prefix}brand-logo-on-light.png`, onDark: `${prefix}brand-logo-on-dark.png` };
}
export function getBrand(): Brand {
// Defined by vite.config.ts; absent where that config does not run.
const hasLogo = typeof __THEME_HAS_LOGO__ !== 'undefined' && __THEME_HAS_LOGO__;
return { logo: themeLogo(hasLogo) };
}