init unit tests
This commit is contained in:
parent
856060faa5
commit
2cb3c6c052
2 changed files with 122 additions and 9 deletions
|
|
@ -77,6 +77,7 @@ export async function getPageToRouteExistingOrderTo(toRoute = {}, existingHerita
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// If this is a non-CTA navigation, determine where to send the user based on page prerequisites.
|
||||
// This also works if a user has a 'fmg' start_type query string but no current order.
|
||||
// That shouldn't happen, but it's possible.
|
||||
|
|
@ -85,6 +86,7 @@ export async function getPageToRouteExistingOrderTo(toRoute = {}, existingHerita
|
|||
const vehicleStyleComponent = (await lazyLoadComponent('vehicle-style')()).default;
|
||||
const vehicleDamageComponent = (await lazyLoadComponent('vehicle-damage')()).default;
|
||||
|
||||
|
||||
if (!vehicleMakeComponent.methods.arePagePrerequisitesValid()) {
|
||||
return "vehicle-year";
|
||||
} else if (!vehicleModelComponent.methods.arePagePrerequisitesValid()) {
|
||||
|
|
@ -93,7 +95,7 @@ export async function getPageToRouteExistingOrderTo(toRoute = {}, existingHerita
|
|||
return "vehicle-model";
|
||||
} else if (!vehicleDamageComponent.methods.arePagePrerequisitesValid()) {
|
||||
return "vehicle-style";
|
||||
} else if (!store.getters.damage.isRepair || !store.getters.vehicle.carId) {
|
||||
} else if (store.getters.damage.isRepair != null && store.getters.vehicle.carId) {
|
||||
return 'vehicle-damage'
|
||||
} else {
|
||||
if (store.getters.vehicle.vin) {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,16 @@ import * as helper from "@/helpers/heritage-integration-helper";
|
|||
import { cookieNames } from "@/constants/cookie-names";
|
||||
import { setupMocksForJsFiles } from "@/helpers/unit-test-helper.js";
|
||||
import { storeActions } from "@/constants/store-actions";
|
||||
import { storeMutations } from "@/constants/store-mutations";
|
||||
import store from "@/store";
|
||||
import router from "@/router";
|
||||
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
|
||||
import baseMixin from "@/mixins/base-mixin";
|
||||
import { externalUrls } from "@/router/router-constants/externalUrl-values";
|
||||
import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js";
|
||||
|
||||
// Mock Lazy Load
|
||||
jest.mock("@/router/dynamic-routing/component-loader.js", () => ({
|
||||
lazyLoadComponent: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("loadOrderIfPresent", () => {
|
||||
afterEach(() => {
|
||||
|
|
@ -321,21 +325,128 @@ describe("cookies", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("getPageToRouteExistingOrderTo", () => {
|
||||
test("getPageToRouteExistingOrderTo, should return vehicle-model", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {}
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
lazyLoadComponent
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await helper.getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe('vehicle-model');
|
||||
});
|
||||
|
||||
test("getPageToRouteExistingOrderTo, should return vehicle-damage", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {}
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
lazyLoadComponent
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
store.getters.damage.isRepair = false;
|
||||
store.getters.vehicle.carId = 'C00000';
|
||||
|
||||
// Act
|
||||
const result = await helper.getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe('vehicle-damage');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// document.cookie is not just a string, needs to be added individually
|
||||
const cookies = {
|
||||
"orderconfirmation": 1565980,
|
||||
"optimizelyEndUserId": "oeu1610051865958r0.07937134272718804",
|
||||
[cookieNames.CONCEPT_SESSION_INFO]: `{"ReferralNumber":"1566818","ReferralDate":"2022-03-15T10:56:24.597","ReferralCorrelationId":"404d2b04-f86e-45c3-b373-127b6217b060","ShouldResetState":false,"DidHeritageFunnelUpdateLast":true}`,
|
||||
"UNIQUE_SESSION_ID": "33756020-b58e-4ec7-b8b8-3f1576719c40",
|
||||
"_ga": "GA1.1.1631274579.1622658999",
|
||||
"da_lid": "B10847599A73EA95861EBB99009A283E27|0|0|0 clientTag=null",
|
||||
"addshoppers.com": "2%7C1%3A0%7C10%3A1646681050%7C15%3Aaddshoppers.com%7C44%3AODM1OTczNWI0MmFjNGNmMmExNDY3OWRlNTQ1NmM5MGY%3D%7Cef2a50fafe40fc5abf641a14ee5541c70bef2950666f59d3a809fd9352c7b963"
|
||||
"anotherCookie": "{}",
|
||||
"someOtherCookie": "{}"
|
||||
};
|
||||
|
||||
function setupCookies({ conceptCookieValue = "", includeHeritageCookie = true }) {
|
||||
Object.keys(cookies).forEach(key => {
|
||||
const cookieValue = key == cookieNames.CONCEPT_SESSION_INFO ? conceptCookieValue : cookies[key];
|
||||
|
||||
|
||||
if (includeHeritageCookie || key != cookieNames.CONCEPT_SESSION_INFO)
|
||||
document.cookie = `${key}=${cookieValue}; path=/;`;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue