diff --git a/src/app/forms/custom-sections/body/__tests__/body.component.spec.ts b/src/app/forms/custom-sections/body/__tests__/body.component.spec.ts index 2c2cf2aca..42c17f52a 100644 --- a/src/app/forms/custom-sections/body/__tests__/body.component.spec.ts +++ b/src/app/forms/custom-sections/body/__tests__/body.component.spec.ts @@ -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', () => { @@ -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 = { diff --git a/src/app/forms/custom-sections/body/body.component.ts b/src/app/forms/custom-sections/body/body.component.ts index e90c65d90..c4c833d47 100644 --- a/src/app/forms/custom-sections/body/body.component.ts +++ b/src/app/forms/custom-sections/body/body.component.ts @@ -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', @@ -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'>, + }) + ) ); } }