Skip to content

Commit

Permalink
fix(cb2-12006): prevent error message duplication (#1492)
Browse files Browse the repository at this point in the history
* fix(cb2-12006): prevent error message duplication

* fix(cb2-12006): fix unit test
  • Loading branch information
pbardy2000 authored Jul 19, 2024
1 parent 688c526 commit 340bdd9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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

0 comments on commit 340bdd9

Please sign in to comment.