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

fix(cb2-12006): prevent error message duplication #1492

Merged
merged 2 commits into from
Jul 19, 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 @@ -131,11 +131,11 @@ describe('TechRecordChangeTypeComponent', () => {

describe('handleSubmit', () => {
it('should add an error when no vehicle type is selected', () => {
const addErrorSpy = jest.spyOn(errorService, 'addError');
const setErrorsSpy = jest.spyOn(errorService, 'setErrors');

component.handleSubmit(null as unknown as VehicleTypes);

expect(addErrorSpy).toHaveBeenCalledWith({ error: 'You must provide a new vehicle type', anchorLink: 'selectedVehicleType' });
expect(setErrorsSpy).toHaveBeenCalledWith([{ error: 'You must provide a new vehicle type', anchorLink: 'selectedVehicleType' }]);
});

it('should dispatch the changeVehicleType action', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ export class ChangeVehicleTypeComponent implements OnInit {

handleSubmit(selectedVehicleType: VehicleTypes): void {
if (!selectedVehicleType) {
return this.globalErrorService.addError({ error: 'You must provide a new vehicle type', anchorLink: 'selectedVehicleType' });
return this.globalErrorService.setErrors([{ error: 'You must provide a new vehicle type', anchorLink: 'selectedVehicleType' }]);
}

if (
selectedVehicleType === VehicleTypes.TRL
&& ((this.techRecord as TechRecordTypeByVehicle<'trl'>)?.techRecord_euVehicleCategory === EUVehicleCategory.O1
|| (this.techRecord as TechRecordTypeByVehicle<'trl'>)?.techRecord_euVehicleCategory === EUVehicleCategory.O2)
) {
return this.globalErrorService.addError({
return this.globalErrorService.setErrors([{
error: 'You cannot change vehicle type to TRL when EU vehicle category is set to \'O1\' or \'O2\'',
anchorLink: 'selectedVehicleType',
});
}]);
}

this.store.dispatch(changeVehicleType({ techRecord_vehicleType: selectedVehicleType }));
Expand Down
Loading