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-13830): fix NG0600 #1579

Merged
merged 1 commit into from
Sep 9, 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 @@ -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
Loading