Skip to content

Commit

Permalink
Release/v3.38.0 hotfixes (#1702)
Browse files Browse the repository at this point in the history
* feat(CB2-14452-tyres-dfs): styling fix

* feat(adr-tank-inspections-fix): fix inspections (#1683)

* feat(adr-tank-inspections-fix): fix inspections

* feat(adr-tank-inspections-fix): fix unit test

* fix(CB2-15660): fix issue where delete of tc3 inspection was not propagated (#1690)

Co-authored-by: Thomas Evans <36958694+tomevs88@users.noreply.github.com>

* fix(CB2-15741): fix correct small trl eu vehicle cat (#1699)

* feat(feat/CB2-15735): bug fixed (#1701)

Co-authored-by: Tom Evans <thomas.evans@dvsa.gov.uk>

* feat(cb2-15734): hide required tag for subclass for small trl (#1700)

* fix(CB2-14452): reset autocomplete to default value when cleared (#1697)

* fix(CB2-14452): reset autocomplete to default value when cleared

* fix(CB2-14452): fix unit test

* fix(cb2-15660): fix un numbers (#1698)

* fix(CB2-15660): fix issue where delete of tc3 inspection was not propagated

* fix(CB2-15660): handle pre-populate UN Numbers

---------

Co-authored-by: Thomas Evans <36958694+tomevs88@users.noreply.github.com>

---------

Co-authored-by: Thomas Evans <36958694+tomevs88@users.noreply.github.com>
Co-authored-by: Tom Evans <thomas.evans@dvsa.gov.uk>
Co-authored-by: Brandon Thomas-Davies <87308252+BrandonT95@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 6, 2025
1 parent 584b452 commit 2be226f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ export class TechRecordSummaryComponent implements OnInit, OnDestroy, AfterViewI
});

this.form.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((changes) => {
this.handleFormState(changes);
// prevent merging of array of objects - always override
const isArray = (a: unknown, b: unknown) => (Array.isArray(a) ? b : undefined);
this.techRecordCalculated = mergeWith(cloneDeep(this.techRecordCalculated), changes, isArray);
this.technicalRecordService.updateEditingTechRecord(this.techRecordCalculated as TechRecordType<'put'>);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ describe('AutocompleteComponent', () => {
expect(control?.touched).toBeTruthy();
});

it('should propagate "" to form control when input is left empty', () => {
it('should propagate null and reset to form control when input is cleared', () => {
const findOptionValueSpy = jest.spyOn(autocompleteComponent, 'findOptionValue');
const control = component.form.get('foo');

autocompleteComponent.handleChange({ target: { value: '' } } as unknown as Event);

expect(findOptionValueSpy).toHaveBeenCalled();
expect(control?.value).toBe('');
expect(control?.touched).toBeTruthy();
expect(control?.value).toBeNull(); // use null to indicate the field is empty
expect(control?.touched).toBe(false);
});

it('should propagate "[INVALID_OPTION]" to form control when value is not an option', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export class AutocompleteComponent extends BaseControlComponent implements After
handleChangeForOption(value: string) {
const optionValue = this.findOptionValue(value);

// Handle case where input is cleared fully, so it returns to default state without triggering validation
if (optionValue === '') {
this.control?.patchValue(null);
this.control?.markAsPristine();
return;
}

this.control?.patchValue(optionValue ?? '[INVALID_OPTION]');
this.control?.markAsTouched();
this.control?.updateValueAndValidity();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ViewportScroller } from '@angular/common';
import { Component, OnDestroy, OnInit, inject, input } from '@angular/core';
import { ControlContainer, FormBuilder, FormGroup } from '@angular/forms';
import { ControlContainer, FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { ADRAdditionalNotesNumber } from '@dvsa/cvs-type-definitions/types/v3/tech-record/enums/adrAdditionalNotesNumber.enum.js';
import { ADRBodyDeclarationTypes } from '@dvsa/cvs-type-definitions/types/v3/tech-record/enums/adrBodyDeclarationType.enum.js';
Expand Down Expand Up @@ -131,12 +131,8 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {
'Reference number or UN number 1 is required when selecting Product List'
),
]),
techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo: this.fb.array(
[
this.fb.control<string | null>(null, [
this.commonValidators.maxLength(1500, 'UN number 1 must be less than or equal to 1500 characters'),
]),
],
techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo: this.fb.array<FormControl<string | null>>(
[],
[
this.adrValidators.requiresAllUnNumbersToBePopulated(),
this.adrValidators.requiresAUnNumberOrReferenceNumber(
Expand Down Expand Up @@ -312,9 +308,30 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy {
}

handleInitialiseUNNumbers() {
this.techRecord()?.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo?.forEach(() =>
this.addUNNumber()
);
const unNumbers = this.techRecord()?.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo;

// If there are un numbers, then prepopulate them
if (Array.isArray(unNumbers) && unNumbers.length > 0) {
unNumbers?.forEach((number, index) => {
this.form.controls.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo.push(
this.fb.control<string | null>(number, [
this.commonValidators.maxLength(
1500,
`UN number ${index + 1} must be less than or equal to 1500 characters`
),
])
);
});
}

// Otherwise, add a single empty UN number
else {
this.form.controls.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo.push(
this.fb.control<string | null>(null, [
this.commonValidators.maxLength(1500, 'UN number 1 must be less than or equal to 1500 characters'),
])
);
}
}

handleInitialiseSubsequentTankInspections() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
label="Vehicle subclass"
formControlName="techRecord_vehicleSubclass"
[options]="VEHICLE_SUBCLASS_OPTIONS"
[tags]="[{ label: TagTypeLabels.REQUIRED, colour: TagType.RED }]"
[tags]="getVehicleType() !== VehicleTypes.SMALL_TRL ? [{ label: TagTypeLabels.REQUIRED, colour: TagType.RED }] : []"
></govuk-checkbox-group>

<!-- Coupling type (TRL Only) -->
Expand Down Expand Up @@ -301,6 +301,7 @@ <h1>
formControlName="techRecord_euVehicleCategory"
[width]="FormNodeWidth.S"
[options]="EUCategoryOptions"
[tags]="getVehicleType() === VehicleTypes.SMALL_TRL ? [{ label: TagTypeLabels.REQUIRED, colour: TagType.RED }] : []"
></govuk-form-group-select>
</ng-template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
MONTHS,
PSV_EU_VEHICLE_CATEGORY_OPTIONS,
PSV_VEHICLE_CLASS_DESCRIPTION_OPTIONS,
SMALL_TRL_EU_VEHICLE_CATEGORY_OPTIONS,
SUSPENSION_TYRE_OPTIONS,
TRL_VEHICLE_CLASS_DESCRIPTION_OPTIONS,
TRL_VEHICLE_CONFIGURATION_OPTIONS,
Expand Down Expand Up @@ -318,6 +319,8 @@ export class VehicleSectionEditComponent implements OnInit, OnDestroy {
return HGV_EU_VEHICLE_CATEGORY_OPTIONS;
case VehicleTypes.PSV:
return PSV_EU_VEHICLE_CATEGORY_OPTIONS;
case VehicleTypes.SMALL_TRL:
return SMALL_TRL_EU_VEHICLE_CATEGORY_OPTIONS;
default:
return ALL_EU_VEHICLE_CATEGORY_OPTIONS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
{{ vm.techRecord_manufactureYear | defaultNullOrEmpty }}
</dd>
</div>
<ng-container *ngIf="
vm.techRecord_vehicleType === VehicleTypes.TRL
">
<div class="govuk-summary-list__row">
<ng-container *ngIf="vm.techRecord_vehicleType === VehicleTypes.TRL && vm.techRecord_euVehicleCategory !== 'o1' && vm.techRecord_euVehicleCategory !== 'o2'">

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Date of first use</dt>
<dd class="govuk-summary-list__value" id="test-techRecord_firstUseDate">
{{ vm.techRecord_firstUseDate | date: 'dd/MM/yyyy' | defaultNullOrEmpty }}
Expand Down Expand Up @@ -229,6 +228,7 @@
</dd>
</div>
</ng-container>

<ng-container *ngIf="
vm.techRecord_vehicleType === VehicleTypes.HGV ||
(vm.techRecord_vehicleType === VehicleTypes.TRL &&
Expand All @@ -247,8 +247,7 @@
</div>
</ng-container>

</dl>
<dl *ngIf="vm.techRecord_vehicleType === VehicleTypes.PSV" class="govuk-summary-list">
<ng-container *ngIf="vm.techRecord_vehicleType === VehicleTypes.PSV" class="govuk-summary-list">
<div class="govuk-summary-list__row">
<h3>
Seats:
Expand Down Expand Up @@ -308,5 +307,6 @@ <h3>
{{ vm.techRecord_alterationMarker | defaultNullOrEmpty }}
</dd>
</div>
</dl>
</ng-container>
</dl>
</ng-container>
5 changes: 5 additions & 0 deletions src/app/models/options.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const HGV_EU_VEHICLE_CATEGORY_OPTIONS: MultiOptions = getOptionsFromEnum(

export const PSV_EU_VEHICLE_CATEGORY_OPTIONS: MultiOptions = getOptionsFromEnum(PSVCategories);

export const SMALL_TRL_EU_VEHICLE_CATEGORY_OPTIONS: MultiOptions = [
{ label: 'O1', value: EUVehicleCategory.O1 },
{ label: 'O2', value: EUVehicleCategory.O2 },
];

export const ALL_EU_VEHICLE_CATEGORY_OPTIONS: MultiOptions = getOptionsFromEnum(EUVehicleCategory);

export const HGV_VEHICLE_CLASS_DESCRIPTION_OPTIONS: MultiOptions = [
Expand Down

0 comments on commit 2be226f

Please sign in to comment.