From 31f7f072e70b60f8262c05eb283ff7ec25141ac1 Mon Sep 17 00:00:00 2001 From: Katie Kroell Date: Fri, 13 Oct 2023 14:12:43 -0400 Subject: [PATCH] unit tests for endorsements computed --- .../policy-vehicles/policy-vehicles.spec.js | 114 ++++++++++++++++++ .../policy-vehicles/policy-vehicles.vue | 10 +- 2 files changed, 119 insertions(+), 5 deletions(-) diff --git a/src/layouts/policy-vehicles/policy-vehicles.spec.js b/src/layouts/policy-vehicles/policy-vehicles.spec.js index 39b50c15..6bb10a35 100644 --- a/src/layouts/policy-vehicles/policy-vehicles.spec.js +++ b/src/layouts/policy-vehicles/policy-vehicles.spec.js @@ -458,6 +458,120 @@ describe('policy-vehicles.vue', () => { }); }); + describe('endorsementsForSelectedVehicle computed property', () => { + it('policyVehicles is null => empty endorsements array returned', () => { + // Arrange + const testValues = { + policyVehicles: null + }; + + // Act + const result = policyVehicles.computed.endorsementsForSelectedVehicle.call(testValues); + const expected = []; + + // Assert + expect(result).toStrictEqual(expected); + }); + + it('policyVehicles is empty => empty endorsements array returned', () => { + // Arrange + const testValues = { + policyVehicles: [] + }; + + // Act + const result = policyVehicles.computed.endorsementsForSelectedVehicle.call(testValues); + const expected = []; + + // Assert + expect(result).toStrictEqual(expected); + }); + + it('selectedVehicleVin does not match any vin in policyVehicles => empty endorsements array returned', () => { + // Arrange + const selectedVin = getRandomString(17, 17); + const otherVin = getRandomString(17, 17); + const testValues = { + selectedVehicleVin: selectedVin, + policyVehicles: [ + { + vin: otherVin + } + ] + }; + + // Act + const result = policyVehicles.computed.endorsementsForSelectedVehicle.call(testValues); + const expected = []; + + // Assert + expect(result).toStrictEqual(expected); + }); + + it('vehicle VIN match with endorsements null => empty endorsements array returned', () => { + // Arrange + const vin = getRandomString(17, 17); + const testValues = { + selectedVehicleVin: vin, + policyVehicles: [ + { + vin, + endorsements: null + } + ] + }; + + // Act + const result = policyVehicles.computed.endorsementsForSelectedVehicle.call(testValues); + const expected = []; + + // Assert + expect(result).toStrictEqual(expected); + }); + + it('vehicle VIN match with empty endorsements => empty endorsements array returned', () => { + // Arrange + const vin = getRandomString(17, 17); + const testValues = { + selectedVehicleVin: vin, + policyVehicles: [ + { + vin, + endorsements: [] + } + ] + }; + + // Act + const result = policyVehicles.computed.endorsementsForSelectedVehicle.call(testValues); + const expected = []; + + // Assert + expect(result).toStrictEqual(expected); + }); + + it('vehicle VIN match with endorsements => endorsements array returned', () => { + // Arrange + const vin = getRandomString(17, 17); + const endorsements = [getRandomString(10, 20)]; + const testValues = { + selectedVehicleVin: vin, + policyVehicles: [ + { + vin, + endorsements + } + ] + }; + + // Act + const result = policyVehicles.computed.endorsementsForSelectedVehicle.call(testValues); + + // Assert + expect(result).toStrictEqual(endorsements); + }); + }); + test('first vehicle is auto-selected if only one vehicle on policy', async () => { // Arrange const vin = getRandomString(17, 17); diff --git a/src/layouts/policy-vehicles/policy-vehicles.vue b/src/layouts/policy-vehicles/policy-vehicles.vue index 18ecfbf1..8ea67941 100644 --- a/src/layouts/policy-vehicles/policy-vehicles.vue +++ b/src/layouts/policy-vehicles/policy-vehicles.vue @@ -102,12 +102,12 @@ export default { return mappedData; }, noCoverageForSelectedVehicle() { - const vehicle = this.policyVehicles.find((policyVehicle) => + const vehicle = this.policyVehicles?.find((policyVehicle) => policyVehicle.vin === this.selectedVehicleVin); return (vehicle?.coverages?.length ?? 0) === 0; }, deductibleForSelectedVehicle() { - const vehicle = this.policyVehicles.find((policyVehicle) => + const vehicle = this.policyVehicles?.find((policyVehicle) => policyVehicle?.vin === this.selectedVehicleVin); if (!vehicle) { return undefined; @@ -118,7 +118,7 @@ export default { : 0; }, endorsementsForSelectedVehicle() { - const vehicle = this.policyVehicles.find((policyVehicle) => + const vehicle = this.policyVehicles?.find((policyVehicle) => policyVehicle?.vin === this.selectedVehicleVin); if (vehicle?.endorsements?.length > 0) { return vehicle.endorsements; @@ -126,7 +126,7 @@ export default { return []; }, repairWaivedForSelectedVehicle() { - const vehicle = this.policyVehicles.find((policyVehicle) => + const vehicle = this.policyVehicles?.find((policyVehicle) => policyVehicle.vin === this.selectedVehicleVin); return vehicle?.endorsements?.includes(endorsementOptions.REPAIR_WAIVED) ?? false; }, @@ -161,7 +161,7 @@ export default { }, beforeMount() { if (this.policyVehicles?.length === 1) { - this.selectedVehicleVin = this.policyVehicles[0].vin; + this.selectedVehicleVin = this.policyVehicles[0]?.vin; } }, methods: