Admin Berichten: toggle-switch, statusicoon, archiveren/terugzetten (CMS-U10)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -113,6 +113,39 @@ describe('Form switch', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('is a real switch: named, stateful, 44px, with the state as text, usable by keyboard', async () => {
|
||||
await openPage();
|
||||
const toggle = await screen.findByRole('switch', { name: 'Contact form on the website' });
|
||||
|
||||
expect(toggle).toHaveAttribute('aria-checked', 'false');
|
||||
expect(toggle).toHaveTextContent('Off');
|
||||
expect(toggle.className).toContain('min-h-11');
|
||||
expect(toggle.className).toContain('min-w-11');
|
||||
|
||||
toggle.focus();
|
||||
await userEvent.keyboard(' ');
|
||||
await waitFor(() => expect(toggle).toHaveAttribute('aria-checked', 'true'));
|
||||
expect(toggle).toHaveTextContent('On');
|
||||
|
||||
await userEvent.keyboard('{Enter}');
|
||||
await waitFor(() => expect(toggle).toHaveAttribute('aria-checked', 'false'));
|
||||
});
|
||||
|
||||
it('is disabled while saving', async () => {
|
||||
await openPage();
|
||||
server.use(
|
||||
http.put(`${API_BASE}/api/v1/contact-settings`, async () => {
|
||||
await new Promise((r) => setTimeout(r, 300));
|
||||
return HttpResponse.json({ enabled: true, hostEnabled: true });
|
||||
}),
|
||||
);
|
||||
const toggle = await screen.findByTestId('contact-switch-toggle');
|
||||
await userEvent.click(toggle);
|
||||
|
||||
expect(toggle).toBeDisabled();
|
||||
await waitFor(() => expect(toggle).not.toBeDisabled());
|
||||
});
|
||||
|
||||
it('shows a translated error and keeps the state when the switch fails', async () => {
|
||||
await openPage();
|
||||
server.use(
|
||||
@@ -304,19 +337,59 @@ describe('Message detail', () => {
|
||||
expect(getMockContactMessages().find((m) => m.id === MSG_READ)?.status).toBe('read');
|
||||
});
|
||||
|
||||
it('changes the status through the select', async () => {
|
||||
it('has no status select; the status is an icon with its name as text', async () => {
|
||||
await openPage();
|
||||
await userEvent.click(await screen.findByTestId(`contact-open-${MSG_READ}`));
|
||||
await userEvent.selectOptions(
|
||||
await screen.findByTestId('contact-status-select'),
|
||||
'archived',
|
||||
);
|
||||
|
||||
const dialog = await screen.findByTestId('contact-message-dialog');
|
||||
expect(within(dialog).queryByTestId('contact-status-select')).not.toBeInTheDocument();
|
||||
expect(within(dialog).queryByRole('combobox')).not.toBeInTheDocument();
|
||||
const icon = within(dialog).getByTestId('status-icon-read');
|
||||
expect(icon).toHaveTextContent('Read');
|
||||
expect(icon).toHaveAttribute('title', 'Read');
|
||||
expect(icon.querySelector('svg')).toHaveAttribute('aria-hidden', 'true');
|
||||
});
|
||||
|
||||
it('archives a message and restores it to read', async () => {
|
||||
await openPage();
|
||||
await userEvent.click(await screen.findByTestId(`contact-open-${MSG_READ}`));
|
||||
|
||||
await userEvent.click(await screen.findByTestId('contact-archive-button'));
|
||||
await waitFor(() =>
|
||||
expect(getMockContactMessages().find((m) => m.id === MSG_READ)?.status).toBe(
|
||||
'archived',
|
||||
),
|
||||
);
|
||||
expect(
|
||||
await within(screen.getByTestId('contact-message-dialog')).findByTestId(
|
||||
'status-icon-archived',
|
||||
),
|
||||
).toHaveTextContent('Archived');
|
||||
expect(screen.queryByTestId('contact-archive-button')).not.toBeInTheDocument();
|
||||
|
||||
await userEvent.click(await screen.findByTestId('contact-restore-button'));
|
||||
await waitFor(() =>
|
||||
expect(getMockContactMessages().find((m) => m.id === MSG_READ)?.status).toBe('read'),
|
||||
);
|
||||
expect(await screen.findByTestId('contact-archive-button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the same status icon and name in the list', async () => {
|
||||
await openPage();
|
||||
const readRow = await screen.findByTestId(`contact-row-${MSG_READ}`);
|
||||
const newRow = screen.getByTestId(`contact-row-${MSG_NEW}`);
|
||||
|
||||
expect(within(readRow).getByTestId('status-icon-read')).toHaveTextContent('Read');
|
||||
expect(within(newRow).getByTestId('status-icon-new')).toHaveTextContent('New');
|
||||
await userEvent.click(screen.getByTestId('contact-filter-spam'));
|
||||
expect(await screen.findByTestId('status-icon-spam')).toHaveTextContent('Spam');
|
||||
});
|
||||
|
||||
it('shows the subject exactly as the site sent it, capitals included', async () => {
|
||||
await openPage();
|
||||
const row = await screen.findByTestId(`contact-row-${MSG_NEW}`);
|
||||
expect(row).toHaveTextContent('Website');
|
||||
expect(row).not.toHaveTextContent('website'); // case-sensitive: no lower-case slug
|
||||
});
|
||||
|
||||
it('shows the translated mail error and the next attempt, never the raw code', async () => {
|
||||
|
||||
Reference in New Issue
Block a user