From 647c47c86a03ebfa710944875098acf1b0ac227d Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Tue, 23 Apr 2024 09:43:46 -0400 Subject: [PATCH] unit test WIP --- src/layouts/vin-lookup/vin-lookup.spec.js | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/layouts/vin-lookup/vin-lookup.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index 1d94f19e..cf76f334 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -121,6 +121,17 @@ const vehicleWithNoAdditionalPartsOrQuestionsMockResponse = { } }; +const partsOrQuestionsErrorMockResponse = { + data: { + partsOrQuestions: [ + { + parts: null + } + ], + partQuestions: null + } +}; + jest.mock('bootstrap', () => ({ getInstance: jest.fn(), getOrCreateInstance: jest.fn() @@ -517,6 +528,37 @@ describe('vin-lookup.vue', () => { ); }); }); + test( + 'Error in getPartsOrQuestions call => bailout true and navigate forward with CLICKED_FORWARD_WITH_BAILOUT scenario', + async () => { + const user = userEvent.setup(); + mountOptions.global.stubs.vinQuestion = false; + getPartsOrQuestions.mockResponse = partsOrQuestionsErrorMockResponse; + + jest.spyOn(VinLookupComponent.methods, lookupVehicleByVin.methodName) + .mockResolvedValue(lookupVehicleByVin.mockResponse); + jest.spyOn(vehicleQuestionsMixin.methods, getPartsOrQuestions.methodName) + .mockResolvedValue(getPartsOrQuestions.mockResponse); + + const { container } = render(VinLookupComponent, mountOptions); + + const vinInput = container.querySelector(vinInputSelector); + await user.type(vinInput, mockValidVin); + + const continueButton = container.querySelector(continueButtonQuerySelector); + await user.click(continueButton); + + await flushPromises(); + await waitFor(() => { + expect(mockRouter.navigate).toHaveBeenCalledTimes(1); + expect(mockRouter.navigate) + .toHaveBeenCalledWith( + navigationScenarios.CLICKED_FORWARD_WITH_BAILOUT, + mockRoute + ); + }); + } + ); }); }); });