Skip to content

Commit

Permalink
feat(cb2-10319): add unit tests and fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcrawleyy committed Jan 3, 2024
1 parent 9a5e794 commit b3244c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { DynamicFormsModule } from '@forms/dynamic-forms.module';
import { mockVehicleTechnicalRecord } from '@mocks/mock-vehicle-technical-record.mock';
import { provideMockStore } from '@ngrx/store/testing';
import { initialAppState } from '@store/index';
import { CustomFormControl } from '@forms/services/dynamic-form.types';
import { WarningsEnum } from '@shared/enums/warnings.enum';
import { DimensionsComponent } from './dimensions.component';

describe('DimensionsComponent', () => {
Expand All @@ -29,4 +31,23 @@ describe('DimensionsComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
describe('initialiseWarnings', () => {
beforeEach(() => {
// eslint-disable-next-line no-restricted-syntax
component.techRecord = mockVehicleTechnicalRecord('hgv');
component.ngOnInit();
});
it('should populate the meta.warning property on the length control if value > 12000', () => {
const control: CustomFormControl = component.form.get('techRecord_dimensions_length') as unknown as CustomFormControl;
control.patchValue(12001);
component.initialiseWarnings();
expect(control.meta.warning).toBe(WarningsEnum.DIMENSIONS_LENGTH_WARNING);
});
it('should populate the meta.warning property on the width control if value > 2600', () => {
const control: CustomFormControl = component.form.get('techRecord_dimensions_width') as unknown as CustomFormControl;
control.patchValue(2601);
component.initialiseWarnings();
expect(control.meta.warning).toBe(WarningsEnum.DIMENSIONS_WIDTH_WARNING);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { TrlDimensionsTemplate } from '@forms/templates/trl/trl-dimensions.templ
import { VehicleTypes } from '@models/vehicle-tech-record.model';
import { WarningsEnum } from '@shared/enums/warnings.enum';
import { debounceTime, Subject, takeUntil } from 'rxjs';
import { DimensionLabelEnum } from '@shared/enums/dimension-label.enum';

@Component({
selector: 'app-dimensions',
Expand Down Expand Up @@ -79,7 +78,7 @@ export class DimensionsComponent implements OnInit, OnChanges, OnDestroy {
}

isWidthControl(control: CustomFormControl): boolean {
return control.meta.name === 'techRecord_dimensions_height';
return control.meta.name === 'techRecord_dimensions_width';
}
shouldDisplayLengthWarning(control: CustomFormControl): boolean {
return parseInt(control.value, 10) > 12000;
Expand Down
2 changes: 1 addition & 1 deletion src/app/forms/templates/trl/trl-dimensions.template.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ValidatorNames } from '@forms/models/validators.enum';
import { TagType } from '@shared/components/tag/tag.component';
import { DimensionLabelEnum } from '@shared/enums/dimension-label.enum';
import {
FormNode, FormNodeEditTypes, FormNodeTypes, TagTypeLabels,
} from '../../services/dynamic-form.types';
import { DimensionLabelEnum } from '@shared/enums/dimension-label.enum';

export const TrlDimensionsTemplate: FormNode = {
name: 'dimensionsSection',
Expand Down

0 comments on commit b3244c7

Please sign in to comment.