Skip to content

Commit

Permalink
mes-9547-vehicleDetailsDuplicateFix (#1626)
Browse files Browse the repository at this point in the history
* Changed logic to display vehicle details correctly

* Refactored html if statements into tested typescript functions

* updated snyk
  • Loading branch information
RLCorp authored Aug 5, 2024
1 parent 9e8228e commit 4eb8b51
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .snyk
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ ignore:
SNYK-JS-INFLIGHT-6095116:
- '*':
reason: Missing Release of Resource after Effective Lifetime - Remediation not yet available
expires: 2024-08-01T09:00:00.119Z
expires: 2024-09-01T09:00:00.119Z
created: 2023-12-04T09:00:00.122Z
SNYK-JS-MICROMATCH-6838728:
- '*':
reason: Remediation not yet available
expires: 2024-08-01T09:00:00.119Z
expires: 2024-09-01T09:00:00.119Z
created: 2024-05-14T09:00:00.0Z
SNYK-JS-BRACES-6838727:
- '*':
Expand Down
50 changes: 40 additions & 10 deletions src/app/pages/view-test-result/__tests__/view-test-result.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,30 +563,60 @@ describe('ViewTestResultPage', () => {
expect(component.getVehicleDetails())
.toEqual(null);
});
it('should return null if there a no test result and the category is not B', () => {
it('should return null if there a no test result and the category is not B or ADI2', () => {
component.testResult = { activityCode: '1' } as TestResultSchemasUnion;
spyOn(component, 'isCategoryB')
.and
.returnValue(false);
component.testCategory = TestCategory.SC;
expect(component.getVehicleDetails())
.toEqual(null);
});
it('should return Dual controls if dualControls is true and the category is B', () => {
component.testResult = { vehicleDetails: { dualControls: true } } as TestResultSchemasUnion;
spyOn(component, 'isCategoryB')
.and
.returnValue(true);
component.testCategory = TestCategory.B;
expect(component.getVehicleDetails())
.toEqual(['Dual controls']);
});
it('should return School car if schoolCar is true and the category is B', () => {
component.testResult = { vehicleDetails: { schoolCar: true } } as TestResultSchemasUnion;
spyOn(component, 'isCategoryB')
.and
.returnValue(true);
component.testCategory = TestCategory.B;
expect(component.getVehicleDetails())
.toEqual(['School car']);
});
it('should return School car and Dual controls' +
' if schoolCar is true and the category is B', () => {
component.testResult = {
vehicleDetails: {
schoolCar: true,
dualControls: true,
},
} as TestResultSchemasUnion;
component.testCategory = TestCategory.B;
expect(component.getVehicleDetails())
.toEqual(['Dual controls', 'School car']);
});
it('should return Dual controls if dualControls is true and the category is ADI2', () => {
component.testResult = { vehicleDetails: { dualControls: true } } as TestResultSchemasUnion;
component.testCategory = TestCategory.ADI2;
expect(component.getVehicleDetails())
.toEqual(['Dual controls']);
});
it('should return School car if schoolCar is true and the category is ADI2', () => {
component.testResult = { vehicleDetails: { schoolCar: true } } as TestResultSchemasUnion;
component.testCategory = TestCategory.ADI2;
expect(component.getVehicleDetails())
.toEqual(['School car']);
});
it('should return School car and Dual controls' +
' if schoolCar is true and the category is ADI2', () => {
component.testResult = {
vehicleDetails: {
schoolCar: true,
dualControls: true,
},
} as TestResultSchemasUnion;
component.testCategory = TestCategory.ADI2;
expect(component.getVehicleDetails())
.toEqual(['Dual controls', 'School car']);
});
});

describe('getCandidateDetails', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,160 @@ describe('VehicleDetailsCardComponent', () => {
});
});

describe('displayVehicleDetailsSeparator', () => {
it('should return true if instructorRegistrationNumber is defined', () => {
spyOnProperty(component, 'instructorRegistrationNumber').and.returnValue(12345);
expect(component.displayVehicleDetailsSeparator).toBeTruthy();
});

it('should return true if shouldShowDimensions is true', () => {
spyOnProperty(component, 'shouldShowDimensions').and.returnValue(true);
expect(component.displayVehicleDetailsSeparator).toBeTruthy();
});

it('should return true if schoolBike is defined', () => {
spyOnProperty(component, 'schoolBike').and.returnValue('Yes');
expect(component.displayVehicleDetailsSeparator).toBeTruthy();
});

it('should return true if trainerPRN is defined and is not ADI3', () => {
spyOn(component, 'isADI3').and.returnValue(false);
spyOnProperty(component, 'trainerPRN').and.returnValue(12345);
expect(component.displayVehicleDetailsSeparator).toBeTruthy();
});

it('should return true if isADI2 is true', () => {
spyOn(component, 'isADI2').and.returnValue(true);
expect(component.displayVehicleDetailsSeparator).toBeTruthy();
});

it('should return true if isADI3 is true', () => {
spyOn(component, 'isADI3').and.returnValue(true);
expect(component.displayVehicleDetailsSeparator).toBeTruthy();
});

it('should return false if all conditions are false or undefined', () => {
spyOnProperty(component, 'instructorRegistrationNumber').and.returnValue(undefined);
spyOnProperty(component, 'shouldShowDimensions').and.returnValue(false);
spyOnProperty(component, 'schoolBike').and.returnValue(undefined);
spyOn(component, 'isADI3').and.returnValue(false);
spyOn(component, 'isADI2').and.returnValue(false);
spyOnProperty(component, 'trainerPRN').and.returnValue(undefined);
expect(component.displayVehicleDetailsSeparator).toBeFalsy();
});
});

describe('showInstructorRegistrationNumberSeparator', () => {
it('returns true if shouldShowDimensions is true', () => {
spyOnProperty(component, 'shouldShowDimensions').and.returnValue(true);
expect(component.showInstructorRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if schoolBike is defined', () => {
spyOnProperty(component, 'schoolBike').and.returnValue('Yes');
expect(component.showInstructorRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if isADI2 is true', () => {
spyOn(component, 'isADI2').and.returnValue(true);
expect(component.showInstructorRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if isADI3 is true', () => {
spyOn(component, 'isADI3').and.returnValue(true);
expect(component.showInstructorRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if trainerPRN is defined and isADI3 is false', () => {
spyOn(component, 'isADI3').and.returnValue(false);
spyOnProperty(component, 'trainerPRN').and.returnValue(12345);
expect(component.showInstructorRegistrationNumberSeparator).toBeTruthy();
});

it('returns false if all conditions are false or undefined', () => {
spyOnProperty(component, 'shouldShowDimensions').and.returnValue(false);
spyOnProperty(component, 'schoolBike').and.returnValue(undefined);
spyOn(component, 'isADI2').and.returnValue(false);
spyOn(component, 'isADI3').and.returnValue(false);
spyOnProperty(component, 'trainerPRN').and.returnValue(undefined);
expect(component.showInstructorRegistrationNumberSeparator).toBeFalsy();
});
});

describe('showRegistrationNumberSeparator', () => {
it('returns true if isADI2 is true', () => {
spyOn(component, 'isADI2').and.returnValue(true);
expect(component.showRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if isADI3 is true', () => {
spyOn(component, 'isADI3').and.returnValue(true);
expect(component.showRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if trainerPRN is defined and isADI3 is false', () => {
spyOn(component, 'isADI3').and.returnValue(false);
spyOnProperty(component, 'trainerPRN').and.returnValue(12345);
expect(component.showRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if schoolBike is defined', () => {
spyOnProperty(component, 'schoolBike').and.returnValue('Yes');
expect(component.showRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if displayRegistration is true', () => {
spyOn(component, 'displayRegistration').and.returnValue(true);
expect(component.showRegistrationNumberSeparator).toBeTruthy();
});

it('returns true if vehicleDetails is defined', () => {
component.vehicleDetails = ['detail1', 'detail2'];
expect(component.showRegistrationNumberSeparator).toBeTruthy();
});

it('returns false if all conditions are false or undefined', () => {
spyOn(component, 'isADI2').and.returnValue(false);
spyOn(component, 'isADI3').and.returnValue(false);
spyOnProperty(component, 'trainerPRN').and.returnValue(undefined);
spyOnProperty(component, 'schoolBike').and.returnValue(undefined);
spyOn(component, 'displayRegistration').and.returnValue(false);
component.vehicleDetails = undefined;
expect(component.showRegistrationNumberSeparator).toBeFalsy();
});
});

describe('shouldShowDimensionsSeparator', () => {
it('returns true if isADI2 is true', () => {
spyOn(component, 'isADI2').and.returnValue(true);
expect(component.shouldShowDimensionsSeparator).toBeTruthy();
});

it('returns true if schoolBike is defined', () => {
spyOnProperty(component, 'schoolBike').and.returnValue('Yes');
expect(component.shouldShowDimensionsSeparator).toBeTruthy();
});

it('returns true if isADI3 is true', () => {
spyOn(component, 'isADI3').and.returnValue(true);
expect(component.shouldShowDimensionsSeparator).toBeTruthy();
});

it('returns true if trainerPRN is defined and isADI3 is false', () => {
spyOn(component, 'isADI3').and.returnValue(false);
spyOnProperty(component, 'trainerPRN').and.returnValue(12345);
expect(component.shouldShowDimensionsSeparator).toBeTruthy();
});

it('returns false if all conditions are false or undefined', () => {
spyOn(component, 'isADI2').and.returnValue(false);
spyOn(component, 'isADI3').and.returnValue(false);
spyOnProperty(component, 'schoolBike').and.returnValue(undefined);
spyOnProperty(component, 'trainerPRN').and.returnValue(undefined);
expect(component.shouldShowDimensionsSeparator).toBeFalsy();
});
});

describe('shouldShowExtraDimensions', () => {
[
TestCategory.CM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ <h2 class="des-header-style-4" id="view-test-result-vehicle-details-title">Vehic

<data-row
*ngIf="registrationNumber"
[shouldHaveSeperator]="!!((isADI2() || isADI3()) ||
(!isADI3() && trainerPRN) ||
schoolBike ||
displayRegistration() ||
vehicleDetails)"
[shouldHaveSeperator]="showRegistrationNumberSeparator"
[label]="'Vehicle registration number'"
[value]="registrationNumber"
>
Expand All @@ -31,7 +27,7 @@ <h2 class="des-header-style-4" id="view-test-result-vehicle-details-title">Vehic
<data-row-custom
*ngIf="vehicleDetails"
[label]="'Vehicle details'"
[shouldHaveSeperator]="!!instructorRegistrationNumber || shouldShowDimensions"
[shouldHaveSeperator]="displayVehicleDetailsSeparator"
>
<span class="mes-data" *ngIf="vehicleDetails?.length === 0">None</span>
<span class="mes-data">{{ getFlattenArray(vehicleDetails) }}</span>
Expand All @@ -41,20 +37,13 @@ <h2 class="des-header-style-4" id="view-test-result-vehicle-details-title">Vehic
*ngIf="instructorRegistrationNumber"
[label]="'Instructor registration number'"
[value]="instructorRegistrationNumber"
[shouldHaveSeperator]="!!(shouldShowDimensions ||
schoolBike ||
isADI2() ||
isADI3() ||
(!isADI3() && trainerPRN))"
[shouldHaveSeperator]="showInstructorRegistrationNumberSeparator"
>
</data-row>

<data-row-custom
*ngIf="shouldShowDimensions"
[shouldHaveSeperator]="!!(isADI2() ||
schoolBike ||
isADI3() ||
(!isADI3() && trainerPRN))"
[shouldHaveSeperator]="shouldShowDimensionsSeparator"
[label]="'Vehicle dimensions'"
>
<ion-grid>
Expand Down Expand Up @@ -90,19 +79,11 @@ <h2 class="des-header-style-4" id="view-test-result-vehicle-details-title">Vehic
<data-row
*ngIf="isADI2()"
[label]="'Training Records'"
[shouldHaveSeperator]="(displayVehicleDetails && !isADI3()) || isADI3()"
[shouldHaveSeperator]="isADI3()"
[value]="trainingRecords"
>
</data-row>

<data-row
*ngIf="displayVehicleDetails && !isADI3()"
[shouldHaveSeperator]="false"
[label]="'Vehicle Details'"
[value]="schoolCarDualControls"
>
</data-row>

<data-row *ngIf="isADI3()" [shouldHaveSeperator]="false" [label]="'Dual controls'" [value]="dualControls">
</data-row>
</ion-grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ export class VehicleDetailsCardComponent {
}
}

public get shouldShowDimensionsSeparator(): boolean {
return !!(this.isADI2() ||
this.schoolBike ||
this.isADI3() ||
(!this.isADI3() && this.trainerPRN))
}

public get shouldShowExtraDimensions(): boolean {
switch (this.category) {
case TestCategory.CM:
Expand Down Expand Up @@ -126,6 +133,14 @@ export class VehicleDetailsCardComponent {
return get(this.instructorDetails, 'registrationNumber');
}

public get showInstructorRegistrationNumberSeparator(): boolean {
return !!(this.shouldShowDimensions ||
this.schoolBike ||
this.isADI2() ||
this.isADI3() ||
(!this.isADI3() && this.trainerPRN))
}

public get transmission(): string {
return get(this.data, 'gearboxCategory');
}
Expand All @@ -134,6 +149,14 @@ export class VehicleDetailsCardComponent {
return get(this.data, 'registrationNumber');
}

public get showRegistrationNumberSeparator(): boolean {
return !!((this.isADI2() || this.isADI3()) ||
(!this.isADI3() && this.trainerPRN) ||
this.schoolBike ||
this.displayRegistration() ||
this.vehicleDetails)
}

public get vehicleLength(): string {
return get(this.data, 'vehicleLength', '?')
.toString();
Expand Down Expand Up @@ -173,8 +196,12 @@ export class VehicleDetailsCardComponent {
return get(this.trainerData, 'trainingRecords', false) ? 'Yes' : 'No';
}

public get displayVehicleDetails(): boolean {
return get(this.data, 'schoolCar', false) || get(this.data, 'dualControls', false);
public get displayVehicleDetailsSeparator(): boolean {
return !!(this.instructorRegistrationNumber
|| this.shouldShowDimensions
|| this.schoolBike
|| (!this.isADI3() && this.trainerPRN)
|| (this.isADI2() || this.isADI3()))
}

public get schoolCarDualControls(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/view-test-result/view-test-result.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class ViewTestResultPage extends BasePageComponent implements OnInit {
}

getVehicleDetails(): string[] {
if (!this.testResult || !this.isCategoryB()) {
if (!this.testResult || !isAnyOf(this.testCategory, [TestCategory.B, TestCategory.ADI2])) {
return null;
}

Expand Down

0 comments on commit 4eb8b51

Please sign in to comment.