Contact: ontvangstadres uit de site-instellingen (instelling > env), PUT /contact-settings/recipient en Berichten-veld (CMS-U11)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -165,6 +165,112 @@ 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();
|
||||
|
||||
expect(await screen.findByTestId('contact-recipient-card')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('contact-recipient-input')).toHaveValue('');
|
||||
expect(screen.getByTestId('contact-recipient-source')).toHaveTextContent(
|
||||
'server setting applies',
|
||||
);
|
||||
expect(screen.queryByTestId('contact-recipient-reset')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('contact-no-recipient-banner')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('saves a valid address, shows where it comes from and offers to go back', async () => {
|
||||
await openPage();
|
||||
const input = await screen.findByTestId('contact-recipient-input');
|
||||
|
||||
await userEvent.type(input, ' inbox@example.org ');
|
||||
await userEvent.click(screen.getByTestId('contact-recipient-save'));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('contact-recipient-source')).toHaveTextContent(
|
||||
'Messages go to this address',
|
||||
),
|
||||
);
|
||||
expect(screen.getByTestId('contact-recipient-input')).toHaveValue('inbox@example.org');
|
||||
expect(screen.getByTestId('contact-recipient-reset')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not save an invalid address (client side), and says so', async () => {
|
||||
await openPage();
|
||||
const input = await screen.findByTestId('contact-recipient-input');
|
||||
|
||||
await userEvent.type(input, 'not-an-address');
|
||||
await userEvent.click(screen.getByTestId('contact-recipient-save'));
|
||||
|
||||
expect(await screen.findByTestId('contact-recipient-invalid')).toHaveTextContent(
|
||||
'valid e-mail address',
|
||||
);
|
||||
});
|
||||
|
||||
it('shows a translated message when the server refuses the address', async () => {
|
||||
await openPage();
|
||||
server.use(
|
||||
http.put(`${API_BASE}/api/v1/contact-settings/recipient`, () =>
|
||||
HttpResponse.json(
|
||||
{
|
||||
status: 400,
|
||||
title: 'Validation failed',
|
||||
errors: { recipientEmail: ['invalid'] },
|
||||
},
|
||||
{ status: 400 },
|
||||
),
|
||||
),
|
||||
);
|
||||
await userEvent.type(
|
||||
await screen.findByTestId('contact-recipient-input'),
|
||||
'jan@example.org',
|
||||
);
|
||||
await userEvent.click(screen.getByTestId('contact-recipient-save'));
|
||||
|
||||
const error = await screen.findByTestId('contact-recipient-error');
|
||||
expect(error).toHaveTextContent('valid e-mail address');
|
||||
expect(error).not.toHaveTextContent('Validation failed');
|
||||
});
|
||||
|
||||
it('goes back to the server setting when cleared', async () => {
|
||||
await openPage();
|
||||
await userEvent.type(
|
||||
await screen.findByTestId('contact-recipient-input'),
|
||||
'inbox@example.org',
|
||||
);
|
||||
await userEvent.click(screen.getByTestId('contact-recipient-save'));
|
||||
await userEvent.click(await screen.findByTestId('contact-recipient-reset'));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('contact-recipient-source')).toHaveTextContent(
|
||||
'server setting applies',
|
||||
),
|
||||
);
|
||||
expect(screen.getByTestId('contact-recipient-input')).toHaveValue('');
|
||||
});
|
||||
|
||||
it('warns (but does not block the switch) while there is no address at all', async () => {
|
||||
server.use(
|
||||
http.get(`${API_BASE}/api/v1/contact-settings`, () =>
|
||||
HttpResponse.json({
|
||||
enabled: false,
|
||||
hostEnabled: true,
|
||||
recipientEmail: null,
|
||||
recipientSource: 'none',
|
||||
}),
|
||||
),
|
||||
);
|
||||
await openPage();
|
||||
|
||||
expect(await screen.findByTestId('contact-no-recipient-banner')).toHaveTextContent(
|
||||
'No recipient address is set',
|
||||
);
|
||||
expect(screen.getByTestId('contact-recipient-source')).toHaveTextContent(
|
||||
'no recipient address yet',
|
||||
);
|
||||
expect(screen.getByTestId('contact-switch-toggle')).not.toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Message list', () => {
|
||||
it('shows the inbox without spam and the unread counter', async () => {
|
||||
await openPage();
|
||||
|
||||
Reference in New Issue
Block a user