test: Add more test coverage for Timezone step
This adds more tests for the Timezone step: - 'Step Timezone' -> 'revisit step button on Review works' - 'Timezone request generated correctly' - 'Timezone edit mode'
This commit is contained in:
parent
c851d4abac
commit
b8915da3fd
4 changed files with 172 additions and 5 deletions
|
|
@ -1,10 +1,19 @@
|
|||
import type { Router as RemixRouter } from '@remix-run/router';
|
||||
import { screen, waitFor } from '@testing-library/react';
|
||||
import { screen, waitFor, within } from '@testing-library/react';
|
||||
import { userEvent } from '@testing-library/user-event';
|
||||
|
||||
import { CREATE_BLUEPRINT, EDIT_BLUEPRINT } from '../../../../../constants';
|
||||
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
|
||||
import { timezoneCreateBlueprintRequest } from '../../../../fixtures/editMode';
|
||||
import {
|
||||
blueprintRequest,
|
||||
clickBack,
|
||||
clickNext,
|
||||
enterBlueprintName,
|
||||
interceptBlueprintRequest,
|
||||
interceptEditBlueprintRequest,
|
||||
openAndDismissSaveAndBuildModal,
|
||||
renderEditMode,
|
||||
verifyCancelButton,
|
||||
} from '../../wizardTestUtils';
|
||||
import { clickRegisterLater, renderCreateMode } from '../../wizardTestUtils';
|
||||
|
|
@ -28,6 +37,42 @@ const goToTimezoneStep = async () => {
|
|||
await clickNext(); // Timezone
|
||||
};
|
||||
|
||||
const goToReviewStep = async () => {
|
||||
await clickNext();
|
||||
await clickNext();
|
||||
await clickNext();
|
||||
await enterBlueprintName();
|
||||
await clickNext();
|
||||
};
|
||||
|
||||
const selectTimezone = async () => {
|
||||
const user = userEvent.setup();
|
||||
const timezoneDropdown = await screen.findByPlaceholderText(
|
||||
/select a timezone/i
|
||||
);
|
||||
await waitFor(() => user.type(timezoneDropdown, 'Europe/Am'));
|
||||
const amsterdamTimezone = await screen.findByText('Europe/Amsterdam');
|
||||
await waitFor(() => user.click(amsterdamTimezone));
|
||||
};
|
||||
|
||||
const selectNtpServers = async () => {
|
||||
const user = userEvent.setup();
|
||||
const ntpServersInput = await screen.findByPlaceholderText(
|
||||
/add ntp servers/i
|
||||
);
|
||||
await waitFor(() => user.type(ntpServersInput, '0.nl.pool.ntp.org,'));
|
||||
await waitFor(() => user.type(ntpServersInput, '1.nl.pool.ntp.org,'));
|
||||
};
|
||||
|
||||
const clickRevisitButton = async () => {
|
||||
const user = userEvent.setup();
|
||||
const expandable = await screen.findByTestId('timezone-expandable');
|
||||
const revisitButton = await within(expandable).findByTestId(
|
||||
'revisit-timezone'
|
||||
);
|
||||
await waitFor(() => user.click(revisitButton));
|
||||
};
|
||||
|
||||
describe('Step Timezone', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
|
@ -55,8 +100,100 @@ describe('Step Timezone', () => {
|
|||
await goToTimezoneStep();
|
||||
await verifyCancelButton(router);
|
||||
});
|
||||
|
||||
test('revisit step button on Review works', async () => {
|
||||
await renderCreateMode();
|
||||
await goToTimezoneStep();
|
||||
await goToReviewStep();
|
||||
await clickRevisitButton();
|
||||
await screen.findByRole('heading', { name: /Timezone/ });
|
||||
});
|
||||
});
|
||||
|
||||
// TO DO 'Step Timezone' -> 'revisit step button on Review works'
|
||||
// TO DO 'Timezone request generated correctly'
|
||||
// TO DO 'Timezone edit mode'
|
||||
describe('Timezone request generated correctly', () => {
|
||||
test('with timezone selected', async () => {
|
||||
await renderCreateMode();
|
||||
await goToTimezoneStep();
|
||||
await selectTimezone();
|
||||
await goToReviewStep();
|
||||
// informational modal pops up in the first test only as it's tied
|
||||
// to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage
|
||||
await openAndDismissSaveAndBuildModal();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {
|
||||
timezone: {
|
||||
timezone: 'Europe/Amsterdam',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await waitFor(() => {
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
|
||||
test('with NTP servers', async () => {
|
||||
await renderCreateMode();
|
||||
await goToTimezoneStep();
|
||||
await selectNtpServers();
|
||||
await goToReviewStep();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {
|
||||
timezone: {
|
||||
ntpservers: ['0.nl.pool.ntp.org', '1.nl.pool.ntp.org'],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await waitFor(() => {
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
|
||||
test('with timezone and NTP servers', async () => {
|
||||
await renderCreateMode();
|
||||
await goToTimezoneStep();
|
||||
await selectTimezone();
|
||||
await selectNtpServers();
|
||||
await goToReviewStep();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {
|
||||
timezone: {
|
||||
timezone: 'Europe/Amsterdam',
|
||||
ntpservers: ['0.nl.pool.ntp.org', '1.nl.pool.ntp.org'],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await waitFor(() => {
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Timezone edit mode', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test('edit mode works', async () => {
|
||||
const id = mockBlueprintIds['timezone'];
|
||||
await renderEditMode(id);
|
||||
|
||||
// starts on review step
|
||||
const receivedRequest = await interceptEditBlueprintRequest(
|
||||
`${EDIT_BLUEPRINT}/${id}`
|
||||
);
|
||||
const expectedRequest = timezoneCreateBlueprintRequest;
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue