From cc649ec7a391dd5b5fa005fef7e0179fd6384299 Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Tue, 15 Apr 2025 18:13:49 +0200 Subject: [PATCH] test: add test for linting and fixing blueprints --- .../Components/Blueprints/Blueprints.test.tsx | 42 ++++++++++++++++++- src/test/fixtures/editMode.ts | 7 +++- src/test/mocks/handlers.js | 8 ++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/test/Components/Blueprints/Blueprints.test.tsx b/src/test/Components/Blueprints/Blueprints.test.tsx index 57833673..bdb89d9d 100644 --- a/src/test/Components/Blueprints/Blueprints.test.tsx +++ b/src/test/Components/Blueprints/Blueprints.test.tsx @@ -7,7 +7,10 @@ import { http, HttpResponse } from 'msw'; import CreateImageWizard from '../../../Components/CreateImageWizard'; import LandingPage from '../../../Components/LandingPage/LandingPage'; import { IMAGE_BUILDER_API } from '../../../constants'; -import { emptyGetBlueprints } from '../../fixtures/blueprints'; +import { + emptyGetBlueprints, + mockBlueprintIds, +} from '../../fixtures/blueprints'; import { server } from '../../mocks/server'; import { renderCustomRoutesWithReduxRouter } from '../../testUtils'; @@ -18,6 +21,24 @@ const selectBlueprintById = async (bpId: string) => { return blueprint; }; +const selectBlueprintByNameAndId = async (name: string, bpId: string) => { + const user = userEvent.setup(); + const search = await screen.findByRole('textbox', { + name: /search input/i, + }); + + await waitFor(() => user.clear(search)); + await waitFor(() => user.type(search, name)); + expect(screen.getByRole('textbox', { name: /search input/i })).toHaveValue( + name + ); + + await screen.findByText('compliance'); + const blueprint = await screen.findByTestId(bpId); + await waitFor(() => user.click(blueprint)); + return blueprint; +}; + describe('Blueprints', () => { beforeEach(() => { vi.clearAllMocks(); @@ -167,6 +188,25 @@ describe('Blueprints', () => { ).not.toBeInTheDocument(); }); + test('blueprint linting and fixing', async () => { + renderCustomRoutesWithReduxRouter(); + + const id = mockBlueprintIds.compliance; + await selectBlueprintByNameAndId('compliance', id); + await screen.findByText('The selected blueprint has errors.'); + await screen.findByText("compliance: some thingy isn't right"); + + const button = await screen.findByRole('button', { + name: /fix errors automatically/i, + }); + user.click(button); + await waitFor(() => { + expect( + screen.queryByText('The selected blueprint has errors.') + ).not.toBeInTheDocument(); + }); + }); + describe('edit blueprint', () => { beforeEach(() => { vi.clearAllMocks(); diff --git a/src/test/fixtures/editMode.ts b/src/test/fixtures/editMode.ts index 0879ab7a..bcf29027 100644 --- a/src/test/fixtures/editMode.ts +++ b/src/test/fixtures/editMode.ts @@ -674,7 +674,12 @@ export const complianceBlueprintResponse: BlueprintResponse = { id: mockBlueprintIds['compliance'], description: mockBlueprintDescriptions['compliance'], lint: { - errors: [], + errors: [ + { + name: 'compliance', + description: "some thingy isn't right", + }, + ], }, }; diff --git a/src/test/mocks/handlers.js b/src/test/mocks/handlers.js index c5d7891c..c1fcdab4 100644 --- a/src/test/mocks/handlers.js +++ b/src/test/mocks/handlers.js @@ -211,6 +211,14 @@ export const handlers = [ const id = params['id']; return HttpResponse.json({ id: id }); }), + http.post( + `${IMAGE_BUILDER_API}/experimental/blueprints/:id/fixup`, + ({ params }) => { + const id = params['id']; + getMockBlueprintResponse(id).lint.errors = []; + return HttpResponse(null, { status: 200 }); + } + ), http.post(`${IMAGE_BUILDER_API}/experimental/recommendations`, () => { return HttpResponse.json(mockPkgRecommendations); }),