Skip to content

Commit

Permalink
feat(cb2-14459): unit test progress
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonT95 committed Dec 11, 2024
1 parent b677100 commit 1016db8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('BodySectionEditComponent', () => {
let componentRef: ComponentRef<BodySectionEditComponent>;
let fixture: ComponentFixture<BodySectionEditComponent>;
let formGroupDirective: FormGroupDirective;
let technicalRecordService: TechnicalRecordService;
let store: MockStore;
let optionsService: MultiOptionsService;

beforeEach(async () => {
formGroupDirective = new FormGroupDirective([], []);
Expand All @@ -63,13 +63,13 @@ describe('BodySectionEditComponent', () => {
TechnicalRecordService,
{ provide: ReferenceDataService, useValue: mockReferenceDataService },
ChangeDetectorRef,
MultiOptionsService,
{ provide: MultiOptionsService, useValue: { getOptions: jest.fn(), loadOptions: jest.fn() } },
],
}).compileComponents();

store = TestBed.inject(MockStore);
controlContainer = TestBed.inject(ControlContainer);
technicalRecordService = TestBed.inject(TechnicalRecordService);
optionsService = TestBed.inject(MultiOptionsService);

fixture = TestBed.createComponent(BodySectionEditComponent);
component = fixture.componentInstance;
Expand Down Expand Up @@ -162,4 +162,42 @@ describe('BodySectionEditComponent', () => {
expect(emittedValue).toBe(true);
});
});

describe('addControlsBasedOffVehicleType', () => {
it('should add vehicle specific controls to the form', () => {
const addControlSpy = jest.spyOn(component.form, 'addControl');
const vehicleControlsSpy = jest
.spyOn(component, 'controlsBasedOffVehicleType', 'get')
.mockReturnValue(component.psvFields);
component.addControlsBasedOffVehicleType();
expect(vehicleControlsSpy).toHaveBeenCalled();
expect(addControlSpy).toHaveBeenCalled();
});
});

describe('loadOptions', () => {
it('should load the options based off the vehicle type (PSV)', () => {
const optionServSpy = jest.spyOn(optionsService, 'loadOptions');
const mockTechRecord = mockVehicleTechnicalRecord('psv');
componentRef.setInput('techRecord', mockTechRecord);
component.loadOptions();
expect(optionServSpy).toHaveBeenCalledWith(ReferenceDataResourceType.PsvMake);
});

it('should load the options based off the vehicle type (HGV)', () => {
const optionServSpy = jest.spyOn(optionsService, 'loadOptions');
const mockTechRecord = mockVehicleTechnicalRecord('hgv');
componentRef.setInput('techRecord', mockTechRecord);
component.loadOptions();
expect(optionServSpy).toHaveBeenCalledWith(ReferenceDataResourceType.HgvMake);
});

it('should load the options based off the vehicle type (TRL)', () => {
const optionServSpy = jest.spyOn(optionsService, 'loadOptions');
const mockTechRecord = mockVehicleTechnicalRecord('trl');
componentRef.setInput('techRecord', mockTechRecord);
component.loadOptions();
expect(optionServSpy).toHaveBeenCalledWith(ReferenceDataResourceType.TrlMake);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ export class BodySectionEditComponent implements OnInit, OnDestroy {
get controlsBasedOffVehicleType() {
switch (this.techRecord().techRecord_vehicleType) {
case 'hgv':
case 'trl':
return this.hgvAndTrailerFields;
case 'psv':
return this.psvFields;
case 'trl':
return this.hgvAndTrailerFields;
default:
return {};
}
Expand Down

0 comments on commit 1016db8

Please sign in to comment.