Skip to content

Commit

Permalink
fix(cb2-13830): fix NG0600 (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbardy2000 authored Sep 9, 2024
1 parent 3dbf906 commit d492d39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DynamicFormService } from '@services/dynamic-forms/dynamic-form.service
import { FormNodeEditTypes, FormNodeWidth } from '@services/dynamic-forms/dynamic-form.types';
import { ReferenceDataService } from '@services/reference-data/reference-data.service';
import { UserService } from '@services/user-service/user-service';
import { lastValueFrom, of } from 'rxjs';
import { asapScheduler, lastValueFrom, of } from 'rxjs';
import { BodyComponent } from '../body.component';

describe('BodyComponent', () => {
Expand Down Expand Up @@ -110,25 +110,9 @@ describe('BodyComponent', () => {
} as unknown as V3TechRecordModel;
component.techRecord = mockRecord;

const dispatchSpy = jest.spyOn(store, 'dispatch');
const dispatchSpy = jest.spyOn(asapScheduler, 'schedule');
component.updateHgvVehicleBodyType(mockRecord as TechRecordType<'hgv'>);
expect(dispatchSpy).toHaveBeenCalled();
expect(dispatchSpy).toHaveBeenCalledWith(
expect.objectContaining({
vehicleTechRecord: {
createdTimestamp: 'bar',
systemNumber: 'foo',
techRecord_bodyModel: 'model',
techRecord_bodyType_description: 'articulated',
techRecord_brakes_dtpNumber: '000000',
techRecord_chassisMake: 'chassisType',
techRecord_vehicleConfiguration: 'articulated',
techRecord_vehicleType: 'hgv',
techRecord_bodyType_code: 'a',
vin: 'testVin',
},
})
);
});
it('should not dispatch updateEditingTechRecord if vehicle is hgv and rigid', () => {
const mockRecord = {
Expand Down
31 changes: 22 additions & 9 deletions src/app/forms/custom-sections/body/body.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ import { ReferenceDataService } from '@services/reference-data/reference-data.se
import { State } from '@store/index';
import { selectReferenceDataByResourceKey } from '@store/reference-data';
import { updateBody, updateEditingTechRecord } from '@store/technical-records';
import { Observable, Subject, combineLatest, debounceTime, map, mergeMap, skipWhile, take, takeUntil } from 'rxjs';
import {
Observable,
Subject,
asapScheduler,
combineLatest,
debounceTime,
map,
mergeMap,
skipWhile,
take,
takeUntil,
} from 'rxjs';

@Component({
selector: 'app-body',
Expand Down Expand Up @@ -170,14 +181,16 @@ export class BodyComponent implements OnInit, OnChanges, OnDestroy {

updateHgvVehicleBodyType(record: TechRecordVehicleType<'hgv'>) {
if (record.techRecord_vehicleConfiguration === 'articulated') {
this.store.dispatch(
updateEditingTechRecord({
vehicleTechRecord: {
...this.techRecord,
techRecord_bodyType_description: 'articulated',
techRecord_bodyType_code: 'a',
} as TechRecordType<'put'>,
})
asapScheduler.schedule(() =>
this.store.dispatch(
updateEditingTechRecord({
vehicleTechRecord: {
...this.techRecord,
techRecord_bodyType_description: 'articulated',
techRecord_bodyType_code: 'a',
} as TechRecordType<'put'>,
})
)
);
}
}
Expand Down

0 comments on commit d492d39

Please sign in to comment.