129 lines
No EOL
3.3 KiB
JavaScript
129 lines
No EOL
3.3 KiB
JavaScript
import analyticsMixin from "@/mixins/analytics-mixin";
|
|
import { setupMocksForJsFiles, setupCookies } from "@/helpers/unit-test-helper.js";
|
|
import { storeActions } from "@/constants/store-actions";
|
|
|
|
describe("analyticsMixin.js", () => {
|
|
test("logPageView: calls dispatch with type and payload", () => {
|
|
const type = "";
|
|
const payload = {};
|
|
|
|
const mockData = {
|
|
actionList: [{
|
|
actionName: storeActions.LOG_PAGE_VIEW
|
|
}],
|
|
}
|
|
const mocks = setupMocksForJsFiles(mockData);
|
|
|
|
const testCookieValue = {
|
|
sid: '10000000-0000-0000-0000-000000000001'
|
|
}
|
|
|
|
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
|
|
|
|
analyticsMixin.methods.logPageView(type, payload);
|
|
|
|
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
|
});
|
|
|
|
test("logCustomEvent: calls dispatch with type and payload", () => {
|
|
const type = "";
|
|
const payload = {};
|
|
|
|
const mockData = {
|
|
actionList: [{
|
|
actionName: storeActions.LOG_CUSTOM_EVENT
|
|
}],
|
|
}
|
|
const mocks = setupMocksForJsFiles(mockData);
|
|
|
|
analyticsMixin.methods.logCustomEvent(type, payload);
|
|
|
|
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
|
});
|
|
|
|
test("pushEventToGA, should call logEvent too", () => {
|
|
// Arrange
|
|
const mockData = {
|
|
actionList: [{
|
|
actionName: storeActions.LOG_CUSTOM_EVENT
|
|
}],
|
|
}
|
|
const mocks = setupMocksForJsFiles(mockData);
|
|
|
|
// Act
|
|
analyticsMixin.methods.pushEventToGA('category', 'action', 'label', true);
|
|
|
|
// Assert
|
|
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
|
|
|
});
|
|
|
|
test("Experiments, should push to dataLayer with default Google Custom Dimension Index", () => {
|
|
// Arrange
|
|
window.dataLayer = [];
|
|
|
|
const mockExperimentData =
|
|
[
|
|
{
|
|
settings: {},
|
|
variationName: 'test',
|
|
universeName: 'testUniverse'
|
|
}
|
|
]
|
|
|
|
|
|
// Act
|
|
analyticsMixin.methods.pushExperimentsToDataLayer(mockExperimentData);
|
|
|
|
// Assert
|
|
expect(window.dataLayer).toEqual([{
|
|
experimentId_99: undefined,
|
|
variationId_99: undefined,
|
|
experimentName_99: 'testUniverse',
|
|
variationName_99: 'test',
|
|
customDimension_99: 'undefined_undefined_testUniverse_test'
|
|
}]);
|
|
|
|
});
|
|
|
|
test("Experiments, should push to dataLayer with custom Google Custom Dimension Index", () => {
|
|
// Arrange
|
|
window.dataLayer = [];
|
|
|
|
const mockExperimentData =
|
|
[
|
|
{
|
|
settings: { "Google Custom Dimension Index": "5" },
|
|
variationName: 'test',
|
|
universeName: 'testUniverse'
|
|
}
|
|
]
|
|
|
|
|
|
// Act
|
|
analyticsMixin.methods.pushExperimentsToDataLayer(mockExperimentData);
|
|
|
|
// Assert
|
|
expect(window.dataLayer).toEqual([{
|
|
experimentId_5: undefined,
|
|
variationId_5: undefined,
|
|
experimentName_5: 'testUniverse',
|
|
variationName_5: 'test',
|
|
customDimension_5: 'undefined_undefined_testUniverse_test'
|
|
}]);
|
|
|
|
});
|
|
|
|
test("Obj is not null after action prepended", () => {
|
|
//Arrange
|
|
const obj = {baseMethodName:"testMethodName", data:"testData"};
|
|
const method = {name:"testMethodName", data:"testData" }
|
|
const action = "testAction";
|
|
|
|
//Act
|
|
analyticsMixin.methods.prependActionToMethod(obj, method, action);
|
|
|
|
//Assert
|
|
expect(obj!=null);
|
|
});
|
|
}); |