unit tests for endorsements computed

This commit is contained in:
Katie Kroell 2023-10-13 14:12:43 -04:00
parent 20a9af13ba
commit 31f7f072e7
2 changed files with 119 additions and 5 deletions

View file

@ -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 () => { test('first vehicle is auto-selected if only one vehicle on policy', async () => {
// Arrange // Arrange
const vin = getRandomString(17, 17); const vin = getRandomString(17, 17);

View file

@ -102,12 +102,12 @@ export default {
return mappedData; return mappedData;
}, },
noCoverageForSelectedVehicle() { noCoverageForSelectedVehicle() {
const vehicle = this.policyVehicles.find((policyVehicle) => const vehicle = this.policyVehicles?.find((policyVehicle) =>
policyVehicle.vin === this.selectedVehicleVin); policyVehicle.vin === this.selectedVehicleVin);
return (vehicle?.coverages?.length ?? 0) === 0; return (vehicle?.coverages?.length ?? 0) === 0;
}, },
deductibleForSelectedVehicle() { deductibleForSelectedVehicle() {
const vehicle = this.policyVehicles.find((policyVehicle) => const vehicle = this.policyVehicles?.find((policyVehicle) =>
policyVehicle?.vin === this.selectedVehicleVin); policyVehicle?.vin === this.selectedVehicleVin);
if (!vehicle) { if (!vehicle) {
return undefined; return undefined;
@ -118,7 +118,7 @@ export default {
: 0; : 0;
}, },
endorsementsForSelectedVehicle() { endorsementsForSelectedVehicle() {
const vehicle = this.policyVehicles.find((policyVehicle) => const vehicle = this.policyVehicles?.find((policyVehicle) =>
policyVehicle?.vin === this.selectedVehicleVin); policyVehicle?.vin === this.selectedVehicleVin);
if (vehicle?.endorsements?.length > 0) { if (vehicle?.endorsements?.length > 0) {
return vehicle.endorsements; return vehicle.endorsements;
@ -126,7 +126,7 @@ export default {
return []; return [];
}, },
repairWaivedForSelectedVehicle() { repairWaivedForSelectedVehicle() {
const vehicle = this.policyVehicles.find((policyVehicle) => const vehicle = this.policyVehicles?.find((policyVehicle) =>
policyVehicle.vin === this.selectedVehicleVin); policyVehicle.vin === this.selectedVehicleVin);
return vehicle?.endorsements?.includes(endorsementOptions.REPAIR_WAIVED) ?? false; return vehicle?.endorsements?.includes(endorsementOptions.REPAIR_WAIVED) ?? false;
}, },
@ -161,7 +161,7 @@ export default {
}, },
beforeMount() { beforeMount() {
if (this.policyVehicles?.length === 1) { if (this.policyVehicles?.length === 1) {
this.selectedVehicleVin = this.policyVehicles[0].vin; this.selectedVehicleVin = this.policyVehicles[0]?.vin;
} }
}, },
methods: methods: