CSR-666 Add methods to experiment-mixin
This commit is contained in:
parent
453d086a1d
commit
0fdda5b4a2
3 changed files with 159 additions and 3 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
hasSettingEqualTo(settingName, settingValue) {
|
hasSettingEqualTo(settingName, settingValue) {
|
||||||
|
return this.$store.getters.experimentSettings[settingName] === settingValue;
|
||||||
},
|
},
|
||||||
hasSetting(settingName) {
|
hasSetting(settingName) {
|
||||||
|
return this.$store.getters.experimentSettings.hasOwnProperty(settingName);
|
||||||
},
|
},
|
||||||
getSettingValue(settingName) {
|
getSettingValue(settingName) {
|
||||||
|
return this.hasSetting(settingName) ? this.$store.getters.experimentSettings[settingName] : null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,154 @@
|
||||||
|
import experimentMixin from "@/mixins/experiment-mixin";
|
||||||
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
|
import store from "@/store";
|
||||||
|
|
||||||
|
jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({
|
||||||
|
navigateToHeritageFunnel: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("experiment-mixin", () => {
|
||||||
|
describe("hasSettingEqualTo", () => {
|
||||||
|
test("setting exists and value matches => return true", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.hasSettingEqualTo("Setting2", "Value2");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("setting exists and value does not match => return false", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.hasSettingEqualTo("Setting2", "Value3");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("setting does not exist => return false", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.hasSettingEqualTo("SettingBoogly", "Woogly");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("there are no settings => return false", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({ experimentSettings: {} });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.hasSettingEqualTo("Setting2", "Value3");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("hasSetting", () => {
|
||||||
|
test("has setting => return true", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.hasSetting("Setting4");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("does not have setting => return false", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.hasSetting("BooglyWoogly");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("experimentSettings is empty => return false", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({ experimentSettings: {} });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.hasSetting("Setting4");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getSettingValue", () => {
|
||||||
|
test("has setting => return correct value", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.getSettingValue("Setting3");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual("Value3")
|
||||||
|
});
|
||||||
|
|
||||||
|
test("does not have setting => return null", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.getSettingValue("Hello");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("experimentSettings is empty => return null", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({ experimentSettings: {} });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.getSettingValue("Hello");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function setupMocks({ experimentSettings }) {
|
||||||
|
const defaultExperimentSettings = experimentSettings ?? {
|
||||||
|
"Setting1": "Value1",
|
||||||
|
"Setting2": "Value2",
|
||||||
|
"Setting3": "Value3",
|
||||||
|
"Setting4": "Value1",
|
||||||
|
"Setting5": "Value2",
|
||||||
|
"Setting6": "Value3"
|
||||||
|
}
|
||||||
|
|
||||||
|
const mocks = getMountOptions({
|
||||||
|
store: {
|
||||||
|
getters: {
|
||||||
|
experimentSettings: defaultExperimentSettings
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockComponent = {
|
||||||
|
template: "<div></div>",
|
||||||
|
mixins: [experimentMixin]
|
||||||
|
};
|
||||||
|
|
||||||
|
const wrapper = shallowMount(mockComponent, mocks);
|
||||||
|
|
||||||
|
return { wrapper };
|
||||||
|
}
|
||||||
|
|
@ -69,6 +69,7 @@ const getDefaultState = () => {
|
||||||
saveQuoteId: null,
|
saveQuoteId: null,
|
||||||
crmCustomerId: null,
|
crmCustomerId: null,
|
||||||
lastPageVisited: null,
|
lastPageVisited: null,
|
||||||
|
experiments: []
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -333,6 +334,7 @@ export const getters = {
|
||||||
applicationUser: (state) => state.applicationUser,
|
applicationUser: (state) => state.applicationUser,
|
||||||
order: (state) => state.order,
|
order: (state) => state.order,
|
||||||
payment: (state) => state.order.payment,
|
payment: (state) => state.order.payment,
|
||||||
|
experimentSettings: (state) => state.applicationUser.experiments.map(x => x.settings).reduce((r, c) => Object.assign(r, c), {})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export Actions
|
// Export Actions
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue