Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mes-motNoDetailsNotShowingOnSearchCompleted #1801

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}))
);

Expand Down
4 changes: 3 additions & 1 deletion src/store/tests/vehicle-details/vehicle-details.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading