more unit tests
This commit is contained in:
parent
4ee9a3fd06
commit
32c63e6b63
4 changed files with 179 additions and 4 deletions
|
|
@ -4,6 +4,7 @@ import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"
|
|||
import { storeActions } from "@/constants/store-actions";
|
||||
import { setupMocksForJsFiles, getMockOrderInfo } from "@/helpers/unit-test-helper.js";
|
||||
import { externalUrls } from "@/router/router-constants/externalUrl-values";
|
||||
import { queryStrings } from "@/constants/query-strings";
|
||||
|
||||
import store from "@/store";
|
||||
import router from "@/router";
|
||||
|
|
@ -15,6 +16,58 @@ jest.mock("@/router/dynamic-routing/component-loader.js", () => ({
|
|||
|
||||
describe("getPageToRouteExistingOrderTo", () => {
|
||||
|
||||
test("getPageToRouteExistingOrderTo, should return vehicle-year", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {}
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
lazyLoadComponent
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.mockReturnValueOnce(() => {
|
||||
return {
|
||||
default: {
|
||||
methods: {
|
||||
arePagePrerequisitesValid: jest.fn().mockReturnValueOnce(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe('vehicle-year');
|
||||
});
|
||||
|
||||
test("getPageToRouteExistingOrderTo, should return vehicle-model", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
|
|
@ -232,6 +285,21 @@ describe("getPageToRouteExistingOrderTo", () => {
|
|||
//Assert
|
||||
expect(result).toBe('estimate');
|
||||
});
|
||||
|
||||
test("getPageToRouteExistingOrderTo, existing order, should return heritage", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {
|
||||
[queryStrings.START_TYPE]: 'fmg'
|
||||
}
|
||||
}
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, true);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe("heritage");
|
||||
})
|
||||
});
|
||||
|
||||
describe("navigateToHeritageFunnel", () => {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export function isSavedSessionStillActive() {
|
|||
if (getConceptCookie() !== null) {
|
||||
const savedSessionTimeStamp = new Date(getConceptCookie().SavedQuoteTimeoutDate);
|
||||
const isSavedSessionTimedOut = (new Date(new Date().toUTCString()) > savedSessionTimeStamp);
|
||||
|
||||
console.log(savedSessionTimeStamp, isSavedSessionTimedOut);
|
||||
console.log("Saved Session Timed Out? --->", isSavedSessionTimedOut);
|
||||
|
||||
if (isSavedSessionTimedOut) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import * as cookieHelper from "@/helpers/heritage-integration/cookie-helper";
|
||||
import { isAnalyticsSessionStillActive, isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
|
||||
import { isAnalyticsSessionStillActive, isSavedSessionStillActive, getDateForSavedSessionTimeout} from "@/helpers/heritage-integration/session-helper";
|
||||
import { applicationConfig } from "@/constants/application-config";
|
||||
|
||||
describe("isAnalyticsSessionStillActive", () => {
|
||||
test("isAnalyticsSessionStillActive, should return true", () => {
|
||||
|
|
@ -52,7 +53,7 @@ describe("isSavedSessionStillActive", () => {
|
|||
test("isSavedSessionStillActive, should return false", () => {
|
||||
// Arrange
|
||||
const mockDate = new Date(new Date().toUTCString())
|
||||
mockDate.setDate(mockDate.getDate() + 65)
|
||||
mockDate.setDate(mockDate.getDate() - 1)
|
||||
|
||||
cookieHelper.getConceptCookie = jest.spyOn(cookieHelper, "getConceptCookie")
|
||||
.mockReturnValue({ SavedQuoteTimeoutDate: mockDate });
|
||||
|
|
@ -64,4 +65,18 @@ describe("isSavedSessionStillActive", () => {
|
|||
expect(result).toBe(false);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDateForSavedSessionTimeout", () => {
|
||||
test("getDateForSavedSessionTimeout, should equal application config setting", () =>{
|
||||
// Arrange
|
||||
const currentDate = new Date(new Date().toUTCString())
|
||||
currentDate.setDate(currentDate.getDate() + applicationConfig.SAVED_SESSION_TIMEOUT)
|
||||
|
||||
// Act
|
||||
const result = getDateForSavedSessionTimeout();
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(currentDate.toUTCString());
|
||||
});
|
||||
})
|
||||
|
|
@ -200,6 +200,38 @@ describe("Mutations", () => {
|
|||
expect(storeState.applicationUser.pageData['vehicle-year']).toEqual({});
|
||||
});
|
||||
|
||||
it("setLoadOrderInformation, should set order information in state", () => {
|
||||
// Arrange
|
||||
const storeState = state;
|
||||
|
||||
// Act
|
||||
mutations.setLoadOrderInformation(storeState, {
|
||||
referralNumber: 123,
|
||||
referralDate: new Date().toUTCString(),
|
||||
referralCorrelationId: "xxx-xxx-xxx",
|
||||
vehicle: {
|
||||
year: "2019",
|
||||
make: "Acura",
|
||||
model: "ILX",
|
||||
style: "4 DOOR SEDAN",
|
||||
carId: "C0000001",
|
||||
category: "CAR"
|
||||
},
|
||||
glassToReplace: ["Windshield"],
|
||||
isRepair: false,
|
||||
numberOfChips: 0,
|
||||
parts: [],
|
||||
parentAccountNumber: "123456789",
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(storeState.order.referralNumber).toEqual(123);
|
||||
expect(storeState.order.referralCorrelationId).toEqual("xxx-xxx-xxx");
|
||||
expect(storeState.order.vehicle.year).toEqual("2019");
|
||||
expect(storeState.order.vehicle.make).toEqual("Acura");
|
||||
expect(storeState.order.vehicle.model).toEqual("ILX");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("Actions", () => {
|
||||
|
|
@ -466,6 +498,66 @@ describe("Actions", () => {
|
|||
expect(response.data).toEqual({ imageUrl: "https://test.com" });
|
||||
});
|
||||
|
||||
it("saveOrder action, returns order information", async () => {
|
||||
// Arrange
|
||||
const context = state;
|
||||
|
||||
context.getters = {
|
||||
vehicle: {},
|
||||
damage: {},
|
||||
};
|
||||
context.state = {
|
||||
order: {}
|
||||
};
|
||||
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ data: { referralNumber: 123 } });
|
||||
});
|
||||
|
||||
// Act
|
||||
const response = await actions.saveOrder(context);
|
||||
|
||||
// Assert
|
||||
expect(response.data).toEqual({ referralNumber: 123 });
|
||||
});
|
||||
|
||||
|
||||
it("loadOrder action, returns order information, calls mutation", async () => {
|
||||
// Arrange
|
||||
const context = state;
|
||||
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ data: { referralNumber: 123 } });
|
||||
});
|
||||
|
||||
const commit = jest.fn();
|
||||
|
||||
context.commit = commit;
|
||||
|
||||
// Act
|
||||
const response = await actions.loadOrder(context, {referralNumber: "123", referralDate: new Date().toUTCString(), referralCorrelationId: "xxx-xxx-xxx"});
|
||||
|
||||
// Assert
|
||||
expect(response.data).toEqual({ referralNumber: 123 });
|
||||
expect(commit).toBeCalledWith(storeMutations.SET_LOAD_CONCEPT_SESSION_INFO, {"referralNumber": 123});
|
||||
});
|
||||
|
||||
it("setReferralInformation, should call commit three times", () => {
|
||||
// Arrange
|
||||
const context = state;
|
||||
const commit = jest.fn();
|
||||
|
||||
context.commit = commit;
|
||||
|
||||
// Act
|
||||
actions.setReferralInformation(context, {referralNumber: "123", referralDate: new Date().toUTCString(), referralCorrelationId: "xxx-xxx-xxx"});
|
||||
|
||||
// Assert
|
||||
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_NUMBER, "123");
|
||||
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_DATE, new Date().toUTCString());
|
||||
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, "xxx-xxx-xxx");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("Getters", () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue