Skip to content

Commit

Permalink
test: Test error message reset and validation on add button
Browse files Browse the repository at this point in the history
This tests the updates.
  • Loading branch information
regexowl committed Jan 20, 2025
1 parent 83bd818 commit 3e68494
Showing 1 changed file with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,34 @@ const selectTimezone = async () => {
await waitFor(() => user.click(amsterdamTimezone));
};

const addNtpServer = async (ntpServer: string) => {
const addNtpServerViaKeyDown = async (ntpServer: string) => {
const user = userEvent.setup();
const ntpServersInput = await screen.findByPlaceholderText(
/add ntp servers/i
);
await waitFor(() => user.type(ntpServersInput, ntpServer.concat(',')));
};

const addNtpServerViaAddButton = async (ntpServer: string) => {
const user = userEvent.setup();
const ntpServersInput = await screen.findByPlaceholderText(
/add ntp servers/i
);
const addServerBtn = await screen.findByRole('button', {
name: /add ntp server/i,
});
await waitFor(() => user.type(ntpServersInput, ntpServer));
await waitFor(() => user.click(addServerBtn));
};

const clearInput = async () => {
const user = userEvent.setup();
const clearInputBtn = await screen.findByRole('button', {
name: /clear input/i,
});
await waitFor(() => user.click(clearInputBtn));
};

const clickRevisitButton = async () => {
const user = userEvent.setup();
const expandable = await screen.findByTestId('timezone-expandable');
Expand Down Expand Up @@ -109,16 +129,22 @@ describe('Step Timezone', () => {
expect(
screen.queryByText('NTP server already exists.')
).not.toBeInTheDocument();
await addNtpServer('0.nl.pool.ntp.org');
await addNtpServer('0.nl.pool.ntp.org');
await addNtpServerViaKeyDown('0.nl.pool.ntp.org');
await addNtpServerViaKeyDown('0.nl.pool.ntp.org');
await screen.findByText('NTP server already exists.');
await clearInput();
expect(
screen.queryByText('NTP server already exists.')
).not.toBeInTheDocument();
await addNtpServerViaAddButton('0.nl.pool.ntp.org');
await screen.findByText('NTP server already exists.');
});

test('NTP server in an invalid format cannot be added', async () => {
await renderCreateMode();
await goToTimezoneStep();
expect(screen.queryByText('Invalid format.')).not.toBeInTheDocument();
await addNtpServer('this is not NTP server');
await addNtpServerViaKeyDown('this is not NTP server');
await screen.findByText('Invalid format.');
});

Expand Down Expand Up @@ -159,8 +185,8 @@ describe('Timezone request generated correctly', () => {
test('with NTP servers', async () => {
await renderCreateMode();
await goToTimezoneStep();
await addNtpServer('0.nl.pool.ntp.org');
await addNtpServer('1.nl.pool.ntp.org');
await addNtpServerViaKeyDown('0.nl.pool.ntp.org');
await addNtpServerViaKeyDown('1.nl.pool.ntp.org');
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);

Expand All @@ -182,8 +208,8 @@ describe('Timezone request generated correctly', () => {
await renderCreateMode();
await goToTimezoneStep();
await selectTimezone();
await addNtpServer('0.nl.pool.ntp.org');
await addNtpServer('1.nl.pool.ntp.org');
await addNtpServerViaKeyDown('0.nl.pool.ntp.org');
await addNtpServerViaKeyDown('1.nl.pool.ntp.org');
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);

Expand Down

0 comments on commit 3e68494

Please sign in to comment.