diff --git a/src/app/pages/waiting-room-to-car/components/vehicle-registration/__tests__/vehicle-registration.spec.ts b/src/app/pages/waiting-room-to-car/components/vehicle-registration/__tests__/vehicle-registration.spec.ts index 0ece97a3a..8e4c67385 100644 --- a/src/app/pages/waiting-room-to-car/components/vehicle-registration/__tests__/vehicle-registration.spec.ts +++ b/src/app/pages/waiting-room-to-car/components/vehicle-registration/__tests__/vehicle-registration.spec.ts @@ -69,6 +69,25 @@ describe('VehicleRegistrationComponent', () => { }); }); + describe('updateMotList', () => { + it('should emit vrnSearchListUpdate with passed param', () => { + spyOn(component.vrnSearchListUpdate, 'emit'); + component.updateMotList('ABC123'); + expect(component.vrnSearchListUpdate.emit).toHaveBeenCalledWith('ABC123'); + }); + it('should set hasCalledMOT to true', () => { + component.hasCalledMOT = false; + component.updateMotList('ABC123'); + expect(component.hasCalledMOT).toBeTrue(); + }); + it('should call updateIsSearchingForMOT with false', () => { + spyOn(component, 'updateIsSearchingForMOT'); + component.hasCalledMOT = false; + component.updateMotList('ABC123'); + expect(component.updateIsSearchingForMOT).toHaveBeenCalledWith(false); + }); + }); + describe('updateIsSearchingForMOT', () => { it('should set isSearchingForMOT to true and emit the new value', () => { spyOn(component.motSearchingStatusChange, 'emit'); diff --git a/src/app/pages/waiting-room-to-car/components/vehicle-registration/vehicle-registration.ts b/src/app/pages/waiting-room-to-car/components/vehicle-registration/vehicle-registration.ts index 682c89739..1c6f4d614 100644 --- a/src/app/pages/waiting-room-to-car/components/vehicle-registration/vehicle-registration.ts +++ b/src/app/pages/waiting-room-to-car/components/vehicle-registration/vehicle-registration.ts @@ -100,6 +100,15 @@ export class VehicleRegistrationComponent implements OnChanges { this.motDetailsUpdate.emit(undefined); } + updateMotList(vrn: string) { + // Emit the vehicle registration number to update the search list + this.vrnSearchListUpdate.emit(vrn); + // Set the flag indicating that the MOT call has been made + this.hasCalledMOT = true; + // Stop the search spinner + this.updateIsSearchingForMOT(false); + } + async getMOT(value: string) { this.motButtonPressed.emit(); this.clearData(); @@ -118,13 +127,14 @@ export class VehicleRegistrationComponent implements OnChanges { }) ) .subscribe(async (val) => { - if (+val.status === HttpStatusCodes.NO_CONTENT) { - this.noMotData.emit(true); - } // Assign the API response to the motData property this.motData = val; - // Emit the vehicle registration number to update the search list - this.vrnSearchListUpdate.emit(value); + // If there is mot data, emit noMotData and leave the function early + if (+this.motData.status === HttpStatusCodes.NO_CONTENT) { + this.noMotData.emit(true); + this.updateMotList(value); + return; + } // If the MOT status is not valid, open the reconfirm modal if (this.motData?.data?.status === MotStatusCodes.NOT_VALID) { @@ -137,10 +147,7 @@ export class VehicleRegistrationComponent implements OnChanges { } this.failedMOTModalOutcome.emit(ModalEvent.CONFIRM); } - // Set the flag indicating that the MOT call has been made - this.hasCalledMOT = true; - // Stop the search spinner - this.updateIsSearchingForMOT(false); + this.updateMotList(value); // If motData is not null, emit the vehicle details if (this.motData) { this.motDetailsUpdate.emit(this.motData?.data); diff --git a/src/store/tests/vehicle-details/cat-a-mod1/vehicle-details.cat-a-mod1.reducer.ts b/src/store/tests/vehicle-details/cat-a-mod1/vehicle-details.cat-a-mod1.reducer.ts index a36b22875..1404230d3 100644 --- a/src/store/tests/vehicle-details/cat-a-mod1/vehicle-details.cat-a-mod1.reducer.ts +++ b/src/store/tests/vehicle-details/cat-a-mod1/vehicle-details.cat-a-mod1.reducer.ts @@ -99,7 +99,9 @@ export const vehicleDetailsCatAMod1Reducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/cat-a-mod2/vehicle-details.cat-a-mod2.reducer.ts b/src/store/tests/vehicle-details/cat-a-mod2/vehicle-details.cat-a-mod2.reducer.ts index 11dcf075c..8b45fdfae 100644 --- a/src/store/tests/vehicle-details/cat-a-mod2/vehicle-details.cat-a-mod2.reducer.ts +++ b/src/store/tests/vehicle-details/cat-a-mod2/vehicle-details.cat-a-mod2.reducer.ts @@ -99,7 +99,9 @@ export const vehicleDetailsCatAMod2Reducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/cat-adi-part2/vehicle-details.cat-adi-part2.reducer.ts b/src/store/tests/vehicle-details/cat-adi-part2/vehicle-details.cat-adi-part2.reducer.ts index 4e9582832..b26b26f96 100644 --- a/src/store/tests/vehicle-details/cat-adi-part2/vehicle-details.cat-adi-part2.reducer.ts +++ b/src/store/tests/vehicle-details/cat-adi-part2/vehicle-details.cat-adi-part2.reducer.ts @@ -107,7 +107,9 @@ export const vehicleDetailsCatADIPart2Reducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/cat-adi-part3/vehicle-details.cat-adi-part3.reducer.ts b/src/store/tests/vehicle-details/cat-adi-part3/vehicle-details.cat-adi-part3.reducer.ts index 0cc91448d..a39e15e28 100644 --- a/src/store/tests/vehicle-details/cat-adi-part3/vehicle-details.cat-adi-part3.reducer.ts +++ b/src/store/tests/vehicle-details/cat-adi-part3/vehicle-details.cat-adi-part3.reducer.ts @@ -106,7 +106,9 @@ export const vehicleDetailsCatADIPart3Reducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/cat-b/vehicle-details.cat-b.reducer.ts b/src/store/tests/vehicle-details/cat-b/vehicle-details.cat-b.reducer.ts index 41e0505f0..6470b920e 100644 --- a/src/store/tests/vehicle-details/cat-b/vehicle-details.cat-b.reducer.ts +++ b/src/store/tests/vehicle-details/cat-b/vehicle-details.cat-b.reducer.ts @@ -107,7 +107,9 @@ export const vehicleDetailsReducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/cat-c/vehicle-details.cat-c.reducer.ts b/src/store/tests/vehicle-details/cat-c/vehicle-details.cat-c.reducer.ts index efc23f10f..a4e5f9e5c 100644 --- a/src/store/tests/vehicle-details/cat-c/vehicle-details.cat-c.reducer.ts +++ b/src/store/tests/vehicle-details/cat-c/vehicle-details.cat-c.reducer.ts @@ -101,7 +101,9 @@ export const vehicleDetailsCatCReducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/cat-cpc/vehicle-details.cat-cpc.reducer.ts b/src/store/tests/vehicle-details/cat-cpc/vehicle-details.cat-cpc.reducer.ts index e219e8387..3764cc825 100644 --- a/src/store/tests/vehicle-details/cat-cpc/vehicle-details.cat-cpc.reducer.ts +++ b/src/store/tests/vehicle-details/cat-cpc/vehicle-details.cat-cpc.reducer.ts @@ -102,7 +102,9 @@ export const vehicleDetailsCatCPCReducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/cat-d/vehicle-details.cat-d.reducer.ts b/src/store/tests/vehicle-details/cat-d/vehicle-details.cat-d.reducer.ts index 20c343f02..a79619ece 100644 --- a/src/store/tests/vehicle-details/cat-d/vehicle-details.cat-d.reducer.ts +++ b/src/store/tests/vehicle-details/cat-d/vehicle-details.cat-d.reducer.ts @@ -98,7 +98,9 @@ export const vehicleDetailsCatDReducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/cat-manoeuvres/vehicle-details.cat-manoeuvre.reducer.ts b/src/store/tests/vehicle-details/cat-manoeuvres/vehicle-details.cat-manoeuvre.reducer.ts index 259497d2d..fcbd697d3 100644 --- a/src/store/tests/vehicle-details/cat-manoeuvres/vehicle-details.cat-manoeuvre.reducer.ts +++ b/src/store/tests/vehicle-details/cat-manoeuvres/vehicle-details.cat-manoeuvre.reducer.ts @@ -90,7 +90,9 @@ export const vehicleDetailsCatManoeuvreReducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })) ); diff --git a/src/store/tests/vehicle-details/vehicle-details.reducer.ts b/src/store/tests/vehicle-details/vehicle-details.reducer.ts index 5649f17b2..9354d19b9 100644 --- a/src/store/tests/vehicle-details/vehicle-details.reducer.ts +++ b/src/store/tests/vehicle-details/vehicle-details.reducer.ts @@ -78,7 +78,9 @@ export const vehicleDetailsReducer = createReducer( ), on(vehicleDetailsActions.VRNListUpdated, (state, { vrn }) => ({ ...state, - previouslySearchedRegNumbers: [...(state?.previouslySearchedRegNumbers || []), vrn], + previouslySearchedRegNumbers: state?.previouslySearchedRegNumbers?.includes(vrn) + ? state.previouslySearchedRegNumbers + : [...(state?.previouslySearchedRegNumbers || []), vrn], })), on( vehicleDetailsActions.GearboxCategoryChanged,