Skip to content

Commit

Permalink
test: Add edit tests for hostname
Browse files Browse the repository at this point in the history
This adds an edit test for the Hostname step.
  • Loading branch information
regexowl authored and lucasgarfield committed Dec 12, 2024
1 parent 9b69344 commit a5966b2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import type { Router as RemixRouter } from '@remix-run/router';
import { screen, waitFor, within } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';

import { CREATE_BLUEPRINT } from '../../../../../constants';
import { CREATE_BLUEPRINT, EDIT_BLUEPRINT } from '../../../../../constants';
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import { hostnameCreateBlueprintRequest } from '../../../../fixtures/editMode';
import {
blueprintRequest,
clickBack,
clickNext,
enterBlueprintName,
getNextButton,
interceptBlueprintRequest,
interceptEditBlueprintRequest,
openAndDismissSaveAndBuildModal,
renderEditMode,
verifyCancelButton,
} from '../../wizardTestUtils';
import { clickRegisterLater, renderCreateMode } from '../../wizardTestUtils';
Expand Down Expand Up @@ -166,4 +170,20 @@ describe('Hostname request generated correctly', () => {
});
});

// TO DO 'Hostname edit mode'
describe('Hostname edit mode', () => {
beforeEach(() => {
vi.clearAllMocks();
});

test('edit mode works', async () => {
const id = mockBlueprintIds['hostname'];
await renderEditMode(id);

// starts on review step
const receivedRequest = await interceptEditBlueprintRequest(
`${EDIT_BLUEPRINT}/${id}`
);
const expectedRequest = hostnameCreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
});
10 changes: 10 additions & 0 deletions src/test/fixtures/blueprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const mockBlueprintIds = {
packages: 'b3437c4e-f6f8-4270-8d32-323ac60bc929',
timezone: 'c535dc6e-93b0-4592-ad29-fe46ba7dac73',
locale: '6e982b49-cd2e-4ad0-9962-39315a0ed9d1',
hostname: '05677f58-56c5-4c1e-953b-c8a93da70cc5',
firstBoot: 'd0a8376e-e44e-47b3-845d-30f5199a35b6',
details: '58991b91-4b98-47e0-b26d-8d908678ddb3',
compliance: '21571945-fe23-45e9-8afb-4aa073b8d735',
Expand All @@ -58,6 +59,7 @@ export const mockBlueprintNames = {
packages: 'packages',
timezone: 'timezone',
locale: 'locale',
hostname: 'hostname',
firstBoot: 'firstBoot',
details: 'details',
compliance: 'compliance',
Expand All @@ -81,6 +83,7 @@ export const mockBlueprintDescriptions = {
packages: '',
timezone: '',
locale: '',
hostname: '',
firstBoot: '',
details: 'This is a test description for the Details step.',
compliance: '',
Expand Down Expand Up @@ -286,6 +289,13 @@ export const mockGetBlueprints: GetBlueprintsApiResponse = {
version: 1,
last_modified_at: '2021-09-08T21:00:00.000Z',
},
{
id: mockBlueprintIds['hostname'],
name: mockBlueprintNames['hostname'],
description: mockBlueprintDescriptions['hostname'],
version: 1,
last_modified_at: '2021-09-08T21:00:00.000Z',
},
{
id: mockBlueprintIds['firstBoot'],
name: mockBlueprintNames['firstBoot'],
Expand Down
29 changes: 23 additions & 6 deletions src/test/fixtures/editMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ export const timezoneCreateBlueprintRequest: CreateBlueprintRequest = {
},
};

export const timezoneBlueprintResponse: BlueprintResponse = {
...timezoneCreateBlueprintRequest,
id: mockBlueprintIds['timezone'],
description: mockBlueprintDescriptions['timezone'],
};

export const localeCreateBlueprintRequest: CreateBlueprintRequest = {
...baseCreateBlueprintRequest,
name: mockBlueprintNames['locale'],
Expand All @@ -445,18 +451,27 @@ export const localeCreateBlueprintRequest: CreateBlueprintRequest = {
},
};

export const timezoneBlueprintResponse: BlueprintResponse = {
...timezoneCreateBlueprintRequest,
id: mockBlueprintIds['timezone'],
description: mockBlueprintDescriptions['timezone'],
};

export const localeBlueprintResponse: BlueprintResponse = {
...localeCreateBlueprintRequest,
id: mockBlueprintIds['locale'],
description: mockBlueprintDescriptions['locale'],
};

export const hostnameCreateBlueprintRequest: CreateBlueprintRequest = {
...baseCreateBlueprintRequest,
name: mockBlueprintNames['hostname'],
description: mockBlueprintDescriptions['hostname'],
customizations: {
hostname: 'base-image',
},
};

export const hostnameBlueprintResponse: BlueprintResponse = {
...hostnameCreateBlueprintRequest,
id: mockBlueprintIds['hostname'],
description: mockBlueprintDescriptions['hostname'],
};

export const firstBootCreateBlueprintRequest: CreateBlueprintRequest = {
...baseCreateBlueprintRequest,
name: mockBlueprintNames['firstBoot'],
Expand Down Expand Up @@ -545,6 +560,8 @@ export const getMockBlueprintResponse = (id: string) => {
return timezoneBlueprintResponse;
case mockBlueprintIds['locale']:
return localeBlueprintResponse;
case mockBlueprintIds['hostname']:
return hostnameBlueprintResponse;
case mockBlueprintIds['firstBoot']:
return firstBootBlueprintResponse;
case mockBlueprintIds['details']:
Expand Down

0 comments on commit a5966b2

Please sign in to comment.