Update existing unit test suite
This commit is contained in:
parent
c2996187bb
commit
42d60f4e22
3 changed files with 74 additions and 17 deletions
|
|
@ -100,7 +100,8 @@ export const cookies = {
|
||||||
someOtherCookie: "{}",
|
someOtherCookie: "{}",
|
||||||
dxdev: "did=21b9b94a-ec23-42c1-aaac-e2ae4e4dbffe",
|
dxdev: "did=21b9b94a-ec23-42c1-aaac-e2ae4e4dbffe",
|
||||||
sid: "cba0c3d1-3c1b-4305-bb56-31aa50f58e27",
|
sid: "cba0c3d1-3c1b-4305-bb56-31aa50f58e27",
|
||||||
skey: "12345",
|
[cookieNames.FUNNEL_SESSION_KEY]: "12345",
|
||||||
|
[cookieNames.FUNNEL_USER_ID]: "11aec5e8-92ba-4dc9-a8b6-179a916d8d7a",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Removes test cookies for testing cookie-helper and order-helper
|
// Removes test cookies for testing cookie-helper and order-helper
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ export default {
|
||||||
parentAccountNumber: store.getters.order.payment.parentAccountNumber,
|
parentAccountNumber: store.getters.order.payment.parentAccountNumber,
|
||||||
};
|
};
|
||||||
|
|
||||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
await baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
async logCustomEvent(category, action, label, value) {
|
async logCustomEvent(category, action, label, value) {
|
||||||
|
|
@ -71,10 +71,14 @@ export default {
|
||||||
parentAccountNumber: store.getters.order.payment.parentAccountNumber,
|
parentAccountNumber: store.getters.order.payment.parentAccountNumber,
|
||||||
};
|
};
|
||||||
|
|
||||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_CUSTOM_EVENT, payload, false);
|
await baseMixin.methods.dispatchStoreAction(
|
||||||
|
storeActions.LOG_CUSTOM_EVENT,
|
||||||
|
payload,
|
||||||
|
false
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
pushEventToGA(category, action, label, pushToLogApp = false, valueToLogType = null) {
|
async pushEventToGA(category, action, label, pushToLogApp = false, valueToLogType = null) {
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
const labelToLog = getValueToLog(label, valueToLogType);
|
const labelToLog = getValueToLog(label, valueToLogType);
|
||||||
|
|
||||||
|
|
@ -90,11 +94,11 @@ export default {
|
||||||
pushToDataLayerIfDefined(eventToBePushed);
|
pushToDataLayerIfDefined(eventToBePushed);
|
||||||
|
|
||||||
if (pushToLogApp) {
|
if (pushToLogApp) {
|
||||||
this.logCustomEvent(category, action, labelToLog, undefined);
|
await this.logCustomEvent(category, action, labelToLog, undefined);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
pushPageViewToGA() {
|
async pushPageViewToGA() {
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
const pageViewEvent = {
|
const pageViewEvent = {
|
||||||
event: GaEvents.PAGE_VIEW_EVENT,
|
event: GaEvents.PAGE_VIEW_EVENT,
|
||||||
|
|
@ -104,7 +108,7 @@ export default {
|
||||||
|
|
||||||
pushToDataLayerIfDefined(pageViewEvent);
|
pushToDataLayerIfDefined(pageViewEvent);
|
||||||
|
|
||||||
this.logPageView(analyticsPageEvents.ENTRY);
|
await this.logPageView(analyticsPageEvents.ENTRY);
|
||||||
},
|
},
|
||||||
|
|
||||||
pushExperimentsToDataLayer() {
|
pushExperimentsToDataLayer() {
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,20 @@ import {
|
||||||
} from "@/constants/analytics";
|
} from "@/constants/analytics";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
|
|
||||||
|
// Mock only the regenerate functions; window.crypto is not available in testing.
|
||||||
|
jest.mock("@/helpers/heritage-integration/cookie-helper", () => {
|
||||||
|
const originalModule = jest.requireActual("@/helpers/heritage-integration/cookie-helper");
|
||||||
|
|
||||||
|
return {
|
||||||
|
__esModule: true,
|
||||||
|
...originalModule,
|
||||||
|
regenerateDeviceId: jest.fn(),
|
||||||
|
regenerateUserId: jest.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
describe("analyticsMixin.js", () => {
|
describe("analyticsMixin.js", () => {
|
||||||
test("logPageView: calls dispatch with type and payload", () => {
|
test("logPageView: calls dispatch with type and payload", async () => {
|
||||||
const type = "";
|
const type = "";
|
||||||
const payload = {};
|
const payload = {};
|
||||||
|
|
||||||
|
|
@ -21,6 +33,9 @@ describe("analyticsMixin.js", () => {
|
||||||
{
|
{
|
||||||
actionName: storeActions.LOG_PAGE_VIEW,
|
actionName: storeActions.LOG_PAGE_VIEW,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
actionName: storeActions.INITIALIZE_SESSION,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const mocks = setupMocksForJsFiles(mockData);
|
const mocks = setupMocksForJsFiles(mockData);
|
||||||
|
|
@ -31,27 +46,35 @@ describe("analyticsMixin.js", () => {
|
||||||
|
|
||||||
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
|
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
|
||||||
|
|
||||||
analyticsMixin.methods.logPageView(type, payload);
|
await analyticsMixin.methods.logPageView(type, payload);
|
||||||
|
|
||||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("logCustomEvent: calls dispatch with type and payload", () => {
|
test("logCustomEvent: calls dispatch with type and payload", async () => {
|
||||||
const mockData = {
|
const mockData = {
|
||||||
actionList: [
|
actionList: [
|
||||||
{
|
{
|
||||||
actionName: storeActions.LOG_CUSTOM_EVENT,
|
actionName: storeActions.LOG_CUSTOM_EVENT,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
actionName: storeActions.INITIALIZE_SESSION,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const mocks = setupMocksForJsFiles(mockData);
|
const mocks = setupMocksForJsFiles(mockData);
|
||||||
|
|
||||||
analyticsMixin.methods.logCustomEvent("someCat", "someAction", "someLabel", "someVal");
|
await analyticsMixin.methods.logCustomEvent(
|
||||||
|
"someCat",
|
||||||
|
"someAction",
|
||||||
|
"someLabel",
|
||||||
|
"someVal"
|
||||||
|
);
|
||||||
|
|
||||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("pushEventToGA, should call dataLayer push and logCustomEvent too", () => {
|
test("pushEventToGA, should call dataLayer push and logCustomEvent too", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
window.dataLayer = [];
|
window.dataLayer = [];
|
||||||
const mockData = {
|
const mockData = {
|
||||||
|
|
@ -59,6 +82,9 @@ describe("analyticsMixin.js", () => {
|
||||||
{
|
{
|
||||||
actionName: storeActions.LOG_CUSTOM_EVENT,
|
actionName: storeActions.LOG_CUSTOM_EVENT,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
actionName: storeActions.INITIALIZE_SESSION,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const mocks = setupMocksForJsFiles(mockData);
|
const mocks = setupMocksForJsFiles(mockData);
|
||||||
|
|
@ -73,14 +99,14 @@ describe("analyticsMixin.js", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
analyticsMixin.methods.pushEventToGA("category", "action", "label", true);
|
await analyticsMixin.methods.pushEventToGA("category", "action", "label", true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(mockDataLayer).toEqual(expect.arrayContaining(window.dataLayer));
|
expect(mockDataLayer).toEqual(expect.arrayContaining(window.dataLayer));
|
||||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("pushEventToGA, should call dataLayer push and ValueToLogTypes.LAST_5 only logs last 5 of label", () => {
|
test("pushEventToGA, should call dataLayer push and ValueToLogTypes.LAST_5 only logs last 5 of label", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
window.dataLayer = [];
|
window.dataLayer = [];
|
||||||
var expectedDataLayer = [];
|
var expectedDataLayer = [];
|
||||||
|
|
@ -93,8 +119,21 @@ describe("analyticsMixin.js", () => {
|
||||||
path: "/fmg/?fmgPage=",
|
path: "/fmg/?fmgPage=",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mockData = {
|
||||||
|
actionList: [
|
||||||
|
{
|
||||||
|
actionName: storeActions.LOG_CUSTOM_EVENT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
actionName: storeActions.INITIALIZE_SESSION,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const mocks = setupMocksForJsFiles(mockData);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
analyticsMixin.methods.pushEventToGA(
|
await analyticsMixin.methods.pushEventToGA(
|
||||||
"category",
|
"category",
|
||||||
"action",
|
"action",
|
||||||
"1111122222333333",
|
"1111122222333333",
|
||||||
|
|
@ -106,7 +145,7 @@ describe("analyticsMixin.js", () => {
|
||||||
expect(expectedDataLayer).toEqual(expect.arrayContaining(window.dataLayer));
|
expect(expectedDataLayer).toEqual(expect.arrayContaining(window.dataLayer));
|
||||||
});
|
});
|
||||||
|
|
||||||
test("pushEventToGA, should call dataLayer push and ValueToLogTypes.LAST_5 logs only the last 3 characters for a 3 character string", () => {
|
test("pushEventToGA, should call dataLayer push and ValueToLogTypes.LAST_5 logs only the last 3 characters for a 3 character string", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
window.dataLayer = [];
|
window.dataLayer = [];
|
||||||
var expectedDataLayer = [];
|
var expectedDataLayer = [];
|
||||||
|
|
@ -119,8 +158,21 @@ describe("analyticsMixin.js", () => {
|
||||||
path: "/fmg/?fmgPage=",
|
path: "/fmg/?fmgPage=",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mockData = {
|
||||||
|
actionList: [
|
||||||
|
{
|
||||||
|
actionName: storeActions.LOG_CUSTOM_EVENT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
actionName: storeActions.INITIALIZE_SESSION,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const mocks = setupMocksForJsFiles(mockData);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
analyticsMixin.methods.pushEventToGA(
|
await analyticsMixin.methods.pushEventToGA(
|
||||||
"category",
|
"category",
|
||||||
"action",
|
"action",
|
||||||
"111",
|
"111",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue