commit
7f2fb70f0c
4 changed files with 165 additions and 9 deletions
15
src/mixins/experiment-mixin.js
Normal file
15
src/mixins/experiment-mixin.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import store from "@/store";
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
hasSettingEqualTo(settingName, settingValue) {
|
||||
return store.getters.experimentSettings[settingName] === settingValue;
|
||||
},
|
||||
hasSetting(settingName) {
|
||||
return store.getters.experimentSettings.hasOwnProperty(settingName);
|
||||
},
|
||||
getSettingValue(settingName) {
|
||||
return this.hasSetting(settingName) ? store.getters.experimentSettings[settingName] : null;
|
||||
}
|
||||
},
|
||||
}
|
||||
148
src/mixins/experiment-mixin.spec.js
Normal file
148
src/mixins/experiment-mixin.spec.js
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
import experimentMixin from "@/mixins/experiment-mixin";
|
||||
import { shallowMount } from "@vue/test-utils";
|
||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||
import store from "@/store";
|
||||
|
||||
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 mocks = getMountOptions({});
|
||||
|
||||
const testExperimentSettings = {
|
||||
"Setting1": "Value1",
|
||||
"Setting2": "Value2",
|
||||
"Setting3": "Value3",
|
||||
"Setting4": "Value1",
|
||||
"Setting5": "Value2",
|
||||
"Setting6": "Value3"
|
||||
};
|
||||
|
||||
store.getters = {
|
||||
experimentSettings: experimentSettings ?? testExperimentSettings
|
||||
};
|
||||
|
||||
const mockComponent = {
|
||||
template: "<div></div>",
|
||||
mixins: [experimentMixin]
|
||||
};
|
||||
|
||||
const wrapper = shallowMount(mockComponent, mocks);
|
||||
|
||||
return { wrapper };
|
||||
}
|
||||
|
|
@ -895,23 +895,14 @@ function setupMocks({ partsOrQuestions = [] }) {
|
|||
router: {
|
||||
navigate: jest.fn()
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
const mockVinComponent = {
|
||||
components: { loadingModal },
|
||||
template: '<loadingModal ref="loadingModal" />',
|
||||
// render() {
|
||||
// return '<div ref="loadingModal"></div>'
|
||||
// },
|
||||
mixins: [vinPagesMixin, baseMixin.baseMixin]
|
||||
};
|
||||
|
||||
// const mockVinComponent = Vue.component("mockcomponent", {
|
||||
// template: '<loadingModal ref="loadingModal" />',
|
||||
// mixins: [vinPagesMixin, baseMixin.baseMixin]
|
||||
// })
|
||||
|
||||
const wrapper = shallowMount(mockVinComponent, mocks);
|
||||
|
||||
wrapper.vm.$refs.loadingModal.showModal = jest.fn();
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ const getDefaultState = () => {
|
|||
saveQuoteId: null,
|
||||
crmCustomerId: null,
|
||||
lastPageVisited: null,
|
||||
experiments: []
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
@ -333,6 +334,7 @@ export const getters = {
|
|||
applicationUser: (state) => state.applicationUser,
|
||||
order: (state) => state.order,
|
||||
payment: (state) => state.order.payment,
|
||||
experimentSettings: (state) => state.applicationUser.experiments.map(x => x.settings).reduce((r, c) => Object.assign(r, c), {})
|
||||
}
|
||||
|
||||
// Export Actions
|
||||
|
|
|
|||
Loading…
Reference in a new issue