updated tests

This commit is contained in:
Jason Wheeler 2023-01-17 15:41:48 -05:00
parent de0add665c
commit 71364d4134
5 changed files with 154 additions and 147 deletions

View file

@ -7,7 +7,6 @@ import { shallowMount } from "@vue/test-utils";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import { useMainStore } from "@/store";
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
import store from "@/store";
jest.mock("@/helpers/damage-helper", () => ({
isGlassAvailableForCarId: jest.fn().mockImplementation(() => true),
@ -40,6 +39,12 @@ describe("address-lookup.vue", () => {
carId: "C0000",
},
},
{
vin: "TEST_VIN",
vehicle: {
carId: "C0000",
},
},
],
});
@ -47,6 +52,7 @@ describe("address-lookup.vue", () => {
customerQuestions: {
addressQuestions: mockRegistrationAddress,
},
});
// Act
@ -55,8 +61,7 @@ describe("address-lookup.vue", () => {
// Assert
expect(wrapper.findComponent({ ref: "alertNonServiceableZip" }).isVisible()).toBe(true);
});
});
/*
test("if the address matches a different vehicle display the Matched Different VehicleAlert", async () => {
// Arrange
const mockRegistrationAddress = {
@ -77,7 +82,7 @@ describe("address-lookup.vue", () => {
],
});
store.commit(storeMutations.UPDATE_CAR_ID, "CARID2");
useMainStore().order.vehicle.carId = "CARID2";
await wrapper.setData({
customerQuestions: {
@ -125,7 +130,7 @@ describe("address-lookup.vue", () => {
},
});
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
useMainStore().order.vehicle.carId = "CARID";
await wrapper.setData({
customerQuestions: {
@ -159,7 +164,7 @@ describe("address-lookup.vue", () => {
},
});
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
useMainStore().order.vehicle.carId = "CARID";
await wrapper.setData({
customerQuestions: {
@ -177,7 +182,7 @@ describe("address-lookup.vue", () => {
});
});
/*
describe("navigation", () => {
test("if the back button is clicked, navigate back", async () => {
// Arrange
@ -256,7 +261,7 @@ describe("address-lookup.vue", () => {
],
});
store.commit(storeMutations.UPDATE_CAR_ID, "CARID_A");
useMainStore().order.vehicle.carId = "CARID_A";
const carsFound = [
{
@ -322,7 +327,7 @@ describe("address-lookup.vue", () => {
],
});
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
useMainStore().order.vehicle.carId = "CARID";
await wrapper.setData({
customerQuestions: {
@ -361,6 +366,8 @@ describe("address-lookup.vue", () => {
isSelectedGlassAvailableForVehicle: false,
});
useMainStore().order.vehicle.carId = "CARID";
let carsFound = [
{
vin: "TEST_VIN2",
@ -397,6 +404,8 @@ describe("address-lookup.vue", () => {
const { wrapper } = setupMocks({}, {});
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
useMainStore().order.vehicle.carId = "C0000";
// Act
wrapper.vm.navigateForward(carsFound);
@ -430,12 +439,15 @@ describe("address-lookup.vue", () => {
const { wrapper } = setupMocks({});
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
useMainStore().order.vehicle.carId = "CARID3";
// Act
wrapper.vm.navigateForward(carsFound);
// Assert
expect(wrapper.vm.navigateForwardWithSingleCarMatch).toHaveBeenCalledTimes(1);
});
});
describe("registration and service zips", () => {
@ -451,9 +463,19 @@ describe("address-lookup.vue", () => {
const { wrapper } = setupMocks({
isZipServiceable: true,
isStatePermissible: true,
vinVehicles: [
{
vin: "TEST_VIN",
vehicle: {
carId: "CARID",
},
},
],
});
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
useMainStore().order.vehicle.carId = "CARID";
useMainStore().saveRegistrationAddressLookup = jest.fn();
await wrapper.setData({
customerQuestions: {
@ -465,20 +487,8 @@ describe("address-lookup.vue", () => {
await wrapper.vm.forwardButtonAction();
// Assert
expect(wrapper.vm.dispatchStoreAction).toHaveBeenCalledWith(
"lookupVinByAddress",
{
licenseLastName: undefined,
licenseState: "OH",
licenseStreetAddress: "1234 Main St",
licenseZip: "43215",
},
false
);
expect(wrapper.vm.dispatchStoreAction).toHaveBeenCalledWith("validateZip", {
zip: "43215",
});
expect(useMainStore().saveRegistrationAddressLookup).toHaveBeenCalled();
expect(useMainStore().validateZip).toHaveBeenCalledWith({ zip: "43215" });
});
});
@ -505,7 +515,7 @@ describe("address-lookup.vue", () => {
],
});
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
useMainStore().order.vehicle.carId = "C0000";
await wrapper.setData({
customerQuestions: {
@ -543,7 +553,7 @@ describe("address-lookup.vue", () => {
isZipServiceable: false,
});
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
useMainStore().order.vehicle.carId = "CARID";
await wrapper.setData({
customerQuestions: {
@ -551,84 +561,17 @@ describe("address-lookup.vue", () => {
},
});
useMainStore().saveRegistrationAddressLookup = jest.fn();
// Act
await wrapper.vm.forwardButtonAction();
//FIX THIS
// Assert
expect(wrapper.vm.dispatchStoreAction).not.toHaveBeenCalledWith(
storeActions.UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION
);
});
test("if registration address, service zip are provided, and user clicks continue => both zips are saved and are different", async () => {
// Arrange
const mockRegistrationAddress = {
streetAddress: "1234 Main St",
city: "Columbus",
state: "OH",
zipCode: "43215",
};
const { wrapper } = setupMocks({});
wrapper.vm.navigateForwardWithSingleCarMatch = jest.fn();
store.commit(storeMutations.UPDATE_CAR_ID, "CARID");
wrapper.vm.dispatchStoreAction = jest.fn();
wrapper.vm.dispatchStoreAction.mockImplementation((actionName, value) => {
let data = {};
if (actionName == storeActions.VALIDATE_ZIP) {
if (value == "43215") {
data = {
isServiceable: false,
};
} else {
data = {
isServiceable: true,
};
}
} else if (actionName == storeActions.LOOKUP_VIN_BY_ADDRESS) {
data = {
isStatePermissible: true,
vinVehicles: [
{
vin: "TEST_VIN",
vehicle: {
carId: "CARID",
},
},
],
};
}
return Promise.resolve({ data });
});
await wrapper.setData({
customerQuestions: {
addressQuestions: mockRegistrationAddress,
},
});
await wrapper.vm.forwardButtonAction();
await wrapper.setData({
serviceZipCode: "12345",
});
// // Act
await wrapper.vm.forwardButtonAction();
// // Assert
expect(wrapper.vm.$store.getters.order.serviceLocation.zipCode).not.toEqual(
wrapper.vm.$store.getters.vehicle.registration.zipCode
);
expect(wrapper.vm.$store.getters.vehicle.registration.zipCode).toEqual("12345");
expect(wrapper.vm.$store.getters.order.serviceLocation.zipCode).toEqual("11111");
expect(useMainStore().saveRegistrationAddressLookup).not.toHaveBeenCalled();
});
});
});
*/
});
function setupMocks({
@ -641,7 +584,7 @@ function setupMocks({
carId = "C0000",
})
{
/*
useMainStore().validateZip = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
@ -651,7 +594,7 @@ function setupMocks({
})
});
useMainStore().LOOKUP_VIN_BY_ADDRESS = jest.fn().mockImplementation(() => {
useMainStore().lookupVinByAddress = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: lookupVinbyAddressResponse
? lookupVinbyAddressResponse
@ -668,7 +611,7 @@ function setupMocks({
},
})
})
*/
useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
@ -692,13 +635,11 @@ function setupMocks({
zipCode: "12345",
},
},
order: {
customer: {
emailAddress: "test@test.com",
},
serviceLocation: {
zipCode: "11111",
},
customer: {
emailAddress: "test@test.com",
},
serviceLocation: {
zipCode: "11111",
},
},
},

View file

@ -163,19 +163,7 @@ export default {
return this.mainStore.order.vehicle.carId !== null;
},
loadDefaultsFromStore() {
const data = this.mainStore.order.vehicle.registration;
this.customerQuestions = { ...this.customerQuestions,
...{
firstName: data.firstName,
lastName: data.lastName,
addressQuestions: {
streetAddress: data.address,
city: data.city,
state: data.state,
zipCode: data.zipCode
}
}
};
this.customerQuestions = this.mainStore.customerDataAddressLookup;
},
backButtonAction() {
// route to move backwards
@ -340,8 +328,7 @@ export default {
// display vehicle changed alert on that page.
if (
this.isCarIdDifferent &&
!this.isSelectedGlassAvailableForVehicle &&
matchingCars.length === 1
!this.isSelectedGlassAvailableForVehicle
) {
this.$router.navigate(
this.navigationScenarios.SELECTED_VIN_WITH_MISMATCHED_GLASS,

View file

@ -1,8 +1,8 @@
import vinPagesMixin from "@/mixins/vin-pages-mixin";
import { shallowMount } from "@vue/test-utils";
import { setupMocksForJsFiles, getMountOptions } from "@/helpers/unit-test-helper.js";
import { storeActions } from "@/constants/store-actions";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
import { useMainStore } from "@/store";
describe("vin-pages-mixin", () => {
afterEach(() => {
@ -12,6 +12,7 @@ describe("vin-pages-mixin", () => {
describe("navigateForwardWithSingleCarMatch", () => {
test("should navigateForward", async () => {
// Arrange
useMainStore().getPartsOrQuestions = () => { return { data: {partsOrQuestions: {}}} };
const { wrapper } = setupMocks({});
vehicleQuestionsMixin.methods.navigateForward = jest.fn();
@ -24,36 +25,15 @@ describe("vin-pages-mixin", () => {
});
});
function setupMocks({ partsOrQuestions = [] }) {
const baseMixin = setupMocksForJsFiles({
actionList: [
{
actionName: storeActions.GET_PARTS_OR_QUESTIONS,
data: {
partsOrQuestions: partsOrQuestions,
},
},
],
});
function setupMocks() {
const mocks = getMountOptions({
router: {
navigate: jest.fn(),
navigateWithSaving: jest.fn(),
navigateWithoutSaving: jest.fn(),
},
store: {
commit: jest.fn(),
getters: {
applicationUser: {
savedSessionId: 1,
},
},
},
});
const mockVinComponent = {
mixins: [vinPagesMixin, baseMixin.baseMixin],
mixins: [vinPagesMixin],
};
const wrapper = shallowMount(mockVinComponent, mocks);

View file

@ -42,6 +42,14 @@ const getDefaultState = () => {
capabilityQuestionAnswers: null,
},
customer: {
address: {
streetAddress: null,
city: null,
state: null,
zipCode: null,
},
firstName: null,
lastName: null,
emailAddress: null,
},
serviceLocation: {
@ -109,6 +117,35 @@ export const useMainStore = defineStore({
applicationUserObj: (state) => state.applicationUser,
pageData: (state) => (page) => {
return state.applicationUser.pageData[page];
},
customerDataAddressLookup: (state) => {
if (state.order.vehicle.registration.address)
{
const registration = state.order.vehicle.registration;
return {
addressQuestions: {
streetAddress: registration.address,
city: registration.city,
state: registration.state,
zipCode: registration.zipCode,
},
firstName: registration.firstName,
lastName: registration.lastName,
}
}
else {
const address = state.order.customer.address;
return {
addressQuestions: {
streetAddress: address.streetAddress,
city: address.city,
state: address.state,
zipCode: address.zipCode,
},
firstName: state.order.customer.firstName,
lastName: state.order.customer.lastName,
}
}
},
experimentOrder: (state) => {
return {

View file

@ -157,4 +157,66 @@ describe("Store", () => {
expect(store.order.damage.numberOfChips).toEqual(null);
});
it("should return registration data if available", () => {
//Arrange
const expected = {
addressQuestions: {
streetAddress: "test",
city: "city",
state: "state",
zipCode: "zip",
},
firstName: "1stName",
lastName: "Surname",
}
store.order.vehicle.registration = {
licensePlate: null,
address: "test",
city: "city",
state: "state",
zipCode: "zip",
firstName: "1stName",
lastName: "Surname",
};
//Act
const actual = store.customerDataAddressLookup;
//Assert
expect(actual).toEqual(expected);
});
it("should return customer data if registration data unavailable", () => {
//Arrange
const expected = {
addressQuestions: {
streetAddress: "test",
city: "city",
state: "state",
zipCode: "zip",
},
firstName: "1stName",
lastName: "Surname",
}
store.order.vehicle.registration.address = null;
store.order.customer = {
licensePlate: null,
address: "test",
city: "city",
state: "state",
zipCode: "zip",
firstName: "1stName",
lastName: "Surname",
};
//Act
const actual = store.customerDataAddressLookup;
//Assert
expect(actual).toEqual(expected);
});
});