Berichten: instellingen naar tabblad, schakelaar rechts in de kop, toegankelijke tabs met ?tab=settings

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 18:08:14 +01:00
co-authored by Claude Sonnet 5.5
parent eb6472ea61
commit fccb85a983
8 changed files with 335 additions and 94 deletions
@@ -38,6 +38,11 @@ async function openPage() {
await screen.findByTestId('messages-title', {}, LONG);
}
async function openSettings() {
await userEvent.click(await screen.findByTestId('contact-tab-settings'));
await screen.findByTestId('contact-panel-settings');
}
describe('Berichten navigation', () => {
it('shows the sidebar entry when the module is loaded and the API answers', async () => {
capabilities(WITH_CONTACT);
@@ -90,6 +95,7 @@ describe('Berichten navigation', () => {
describe('Form switch', () => {
it('shows the first-time hint while off and switches on and off with the server answer', async () => {
await openPage();
await openSettings();
expect(await screen.findByTestId('contact-switch-hint')).toBeInTheDocument();
const toggle = screen.getByTestId('contact-switch-toggle');
expect(toggle).toHaveAttribute('aria-checked', 'false');
@@ -115,7 +121,7 @@ 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' });
const toggle = await screen.findByRole('switch', { name: 'Contact form on/off' });
expect(toggle).toHaveAttribute('aria-checked', 'false');
expect(toggle).toHaveTextContent('Off');
@@ -168,6 +174,7 @@ describe('Form switch', () => {
describe('Recipient address', () => {
it('shows the field, says that the server setting applies, and never an address it was not given', async () => {
await openPage();
await openSettings();
expect(await screen.findByTestId('contact-recipient-card')).toBeInTheDocument();
expect(screen.getByTestId('contact-recipient-input')).toHaveValue('');
@@ -180,6 +187,7 @@ describe('Recipient address', () => {
it('saves a valid address, shows where it comes from and offers to go back', async () => {
await openPage();
await openSettings();
const input = await screen.findByTestId('contact-recipient-input');
await userEvent.type(input, ' inbox@example.org ');
@@ -196,6 +204,7 @@ describe('Recipient address', () => {
it('does not save an invalid address (client side), and says so', async () => {
await openPage();
await openSettings();
const input = await screen.findByTestId('contact-recipient-input');
await userEvent.type(input, 'not-an-address');
@@ -208,6 +217,7 @@ describe('Recipient address', () => {
it('shows a translated message when the server refuses the address', async () => {
await openPage();
await openSettings();
server.use(
http.put(`${API_BASE}/api/v1/contact-settings/recipient`, () =>
HttpResponse.json(
@@ -233,6 +243,7 @@ describe('Recipient address', () => {
it('goes back to the server setting when cleared', async () => {
await openPage();
await openSettings();
await userEvent.type(
await screen.findByTestId('contact-recipient-input'),
'inbox@example.org',
@@ -260,6 +271,7 @@ describe('Recipient address', () => {
),
);
await openPage();
await openSettings();
expect(await screen.findByTestId('contact-no-recipient-banner')).toHaveTextContent(
'No recipient address is set',
@@ -709,3 +721,58 @@ describe('Clickable row', () => {
expect(await screen.findByTestId('contact-message-body')).toHaveTextContent('Hallo');
});
});
describe('Tabs and header switch', () => {
it('opens on the messages tab with the switch level with the title and no settings blocks', async () => {
await openPage();
expect(await screen.findByRole('tab', { name: 'Messages', selected: true })).toBeInTheDocument();
expect(screen.getByRole('tabpanel')).toHaveAttribute('id', 'contact-panel-messages');
expect(await screen.findByTestId(`contact-row-${MSG_NEW}`)).toBeInTheDocument();
expect(screen.queryByTestId('contact-recipient-card')).not.toBeInTheDocument();
expect(screen.queryByTestId('contact-switch-card')).not.toBeInTheDocument();
const header = screen.getByTestId('messages-title').parentElement as HTMLElement;
const toggle = within(header).getByRole('switch', { name: 'Contact form on/off' });
expect(toggle).toHaveAttribute('title', 'Contact form on/off');
expect(toggle).toHaveTextContent('Off');
});
it('moves the explanation, hints and recipient to the Settings tab', async () => {
await openPage();
await openSettings();
expect(screen.getByRole('tab', { name: 'Settings', selected: true })).toBeInTheDocument();
const card = await screen.findByTestId('contact-switch-card');
expect(card).toHaveTextContent('While the form is off');
expect(screen.getByTestId('contact-switch-state')).toBeInTheDocument();
expect(screen.getByTestId('contact-recipient-card')).toBeInTheDocument();
expect(screen.queryByTestId('messages-range')).not.toBeInTheDocument();
// the switch stays in the header
expect(screen.getAllByRole('switch')).toHaveLength(1);
await userEvent.click(screen.getByTestId('contact-tab-messages'));
expect(await screen.findByTestId(`contact-row-${MSG_NEW}`)).toBeInTheDocument();
});
it('opens directly on the Settings tab from the URL', async () => {
capabilities(WITH_CONTACT);
renderApp('/messages?tab=settings');
expect(await screen.findByTestId('contact-recipient-card', {}, LONG)).toBeInTheDocument();
expect(screen.getByRole('tab', { name: 'Settings', selected: true })).toBeInTheDocument();
});
it('supports the arrow keys, Home and End on the tabs', async () => {
await openPage();
const messagesTab = await screen.findByRole('tab', { name: 'Messages' });
messagesTab.focus();
await userEvent.keyboard('{ArrowRight}');
expect(await screen.findByRole('tab', { name: 'Settings', selected: true })).toHaveFocus();
expect(screen.getByRole('tabpanel')).toHaveAttribute('aria-labelledby', 'contact-tab-settings');
await userEvent.keyboard('{ArrowRight}');
expect(await screen.findByRole('tab', { name: 'Messages', selected: true })).toHaveFocus();
await userEvent.keyboard('{End}');
expect(await screen.findByRole('tab', { name: 'Settings', selected: true })).toHaveFocus();
await userEvent.keyboard('{Home}');
expect(await screen.findByRole('tab', { name: 'Messages', selected: true })).toHaveFocus();
expect(screen.getByRole('tab', { name: 'Settings' })).toHaveAttribute('tabindex', '-1');
});
});