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

feat(cb2-13762): add test codes to test names #1568

Merged
merged 5 commits into from
Sep 2, 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
@@ -1,4 +1,5 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TestTypesTaxonomy } from '@api/test-types';
import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type';
import { TEST_TYPES_GROUP7 } from '@forms/models/testTypeId.enum';
Expand All @@ -8,7 +9,6 @@ import { TestResultModel } from '@models/test-results/test-result.model';
import { TestType, resultOfTestEnum } from '@models/test-types/test-type.model';
import { V3TechRecordModel, VehicleTypes } from '@models/vehicle-tech-record.model';
import { Store } from '@ngrx/store';
import { TechnicalRecordService } from '@services/technical-record/technical-record.service';
import { TestTypesService } from '@services/test-types/test-types.service';
import { TagType, TagTypes } from '@shared/components/tag/tag.component';
import { techRecord } from '@store/technical-records';
Expand All @@ -28,8 +28,8 @@ export class VehicleHeaderComponent {

constructor(
private testTypesService: TestTypesService,
private techRecordService: TechnicalRecordService,
private store: Store
private store: Store,
private activatedRoute: ActivatedRoute
) {}

get test(): TestType | undefined {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class VehicleHeaderComponent {
}

get testCode(): string | undefined {
const testCode = this.testResult?.testTypes[0].testCode;
const testCode = this.testResult?.testTypes[0].testCode || this.activatedRoute.snapshot?.data?.['testCode'];
return testCode ? `(${testCode})` : '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TestRecordCreateRoutes } from '@models/routes.enum';
import { contingencyTestResolver } from 'src/app/resolvers/contingency-test/contingency-test.resolver';
import { defectsTaxonomyResolver } from 'src/app/resolvers/defects-taxonomy/defects-taxonomy.resolver';
import { requiredStandardsResolver } from 'src/app/resolvers/required-standards/required-standards.resolver';
import { testCodeResolver } from 'src/app/resolvers/test-code/test-code.resolver';
import { testStationsResolver } from 'src/app/resolvers/test-stations/test-stations.resolver';
import { testTypeTaxonomyResolver } from 'src/app/resolvers/test-type-taxonomy/test-type-taxonomy.resolver';
import { CreateTestRecordComponent } from './views/create-test-record/create-test-record.component';
Expand Down Expand Up @@ -38,6 +39,7 @@ const routes: Routes = [
TestTypeTaxonomy: testTypeTaxonomyResolver,
defectTaxonomy: defectsTaxonomyResolver,
testStations: testStationsResolver,
testCode: testCodeResolver,
},
data: { title: 'Test details', roles: Roles.TestResultCreateContingency, breadcrumbPreserveQueryParams: true },
canActivate: [RoleGuard],
Expand Down
33 changes: 33 additions & 0 deletions src/app/resolvers/test-code/test-code.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { inject } from '@angular/core';
import { ResolveFn } from '@angular/router';
import { TestTypesService } from '@api/test-types';
import { Store, select } from '@ngrx/store';
import { TechnicalRecordService } from '@services/technical-record/technical-record.service';
import { techRecord } from '@store/technical-records';
import { Observable, map, switchMap } from 'rxjs';

export const testCodeResolver: ResolveFn<Observable<string | undefined>> = (route) => {
const store = inject(Store);
const testTypesService = inject(TestTypesService);
const techRecordService = inject(TechnicalRecordService);
const testTypeId: string | undefined = route.queryParams['testType'];

// fetch test code from back-end (because its not provided by reference data)
return store.pipe(
select(techRecord),
switchMap((record) => {
return testTypesService.getTestTypesid(
String(testTypeId),
['defaultTestCode'],
record!.techRecord_vehicleType,
techRecordService.getVehicleSize(record!) as string,
record!.techRecord_vehicleConfiguration!,
record!.techRecord_noOfAxles!,
record!.techRecord_euVehicleCategory!,
techRecordService.getVehicleClassDescription(record!) as string,
techRecordService.getVehicleSubClass(record!)?.[0] as string
);
}),
map((response) => response.defaultTestCode)
);
};
4 changes: 1 addition & 3 deletions src/app/resolvers/test-result/test-result.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const testResultResolver: ResolveFn<boolean> = () => {
return action$.pipe(
ofType(fetchSelectedTestResultSuccess, fetchSelectedTestResultFailed),
take(1),
map((action) => {
return action.type === fetchSelectedTestResultSuccess.type;
})
map((action) => action.type === fetchSelectedTestResultSuccess.type)
);
};
19 changes: 19 additions & 0 deletions src/app/services/technical-record/technical-record.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,23 @@ export class TechnicalRecordService {

return false;
}

getVehicleSize(techRecord: V3TechRecordModel) {
return techRecord.techRecord_vehicleType === 'psv' ? techRecord.techRecord_vehicleSize : undefined;
}

getVehicleClassDescription(techRecord: V3TechRecordModel) {
return techRecord.techRecord_vehicleType === 'psv' ||
techRecord.techRecord_vehicleType === 'hgv' ||
techRecord.techRecord_vehicleType === 'trl' ||
techRecord.techRecord_vehicleType === 'motorcycle'
? techRecord.techRecord_vehicleClass_description
: undefined;
}

getVehicleSubClass(techRecord: V3TechRecordModel) {
return techRecord.techRecord_vehicleType === 'car' || techRecord.techRecord_vehicleType === 'lgv'
? techRecord.techRecord_vehicleSubclass
: undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,6 @@ describe('TestResultsEffects', () => {
reasonForAbandoning: '',
seatbeltInstallationCheckDate: false,
secondaryCertificateNumber: null,
testCode: 'undefined',
testExpiryDate: '',
testResult: resultOfTestEnum.fail,
testTypeEndTimestamp: '',
Expand Down Expand Up @@ -768,7 +767,6 @@ describe('TestResultsEffects', () => {
testResult: resultOfTestEnum.fail,
testTypeEndTimestamp: '',
testTypeId: '126',
testCode: 'undefined',
testTypeName: '',
testTypeStartTimestamp: '',
},
Expand Down
18 changes: 1 addition & 17 deletions src/app/store/test-records/effects/test-records.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,22 +280,7 @@ export class TestResultsEffects {
take(1)
)
),
switchMap(([action, editedTestResult, testType, testStation, user]) => {
return this.testTypesService
.getTestTypesid(
String(testType?.id),
['defaultTestCode'],
editedTestResult!.vehicleType,
editedTestResult!.vehicleSize,
editedTestResult!.vehicleConfiguration!,
editedTestResult!.noOfAxles,
editedTestResult!.euVehicleCategory!,
String(editedTestResult!.vehicleClass!),
String(editedTestResult!.vehicleSubclass!)
)
.pipe(map((res) => [action, editedTestResult, testType, testStation, user, res.defaultTestCode] as const));
}),
concatMap(([action, editedTestResult, testTypeTaxonomy, testStation, user, testCode]) => {
concatMap(([action, editedTestResult, testTypeTaxonomy, testStation, user]) => {
const id = action.testType;

const vehicleType = editedTestResult?.vehicleType;
Expand Down Expand Up @@ -326,7 +311,6 @@ export class TestResultsEffects {
});

mergedForms.testTypes[0].testTypeId = id;
mergedForms.testTypes[0].testCode = String(testCode);
mergedForms.testTypes[0].name = testTypeTaxonomy?.name ?? '';
mergedForms.testTypes[0].testTypeName = testTypeTaxonomy?.testTypeName ?? '';
mergedForms.typeOfTest = (testTypeTaxonomy?.typeOfTest as TypeOfTest) ?? TypeOfTest.CONTINGENCY;
Expand Down
Loading