CASH-79: add unit test files
This commit is contained in:
parent
72526efcf2
commit
b3457512fa
2 changed files with 91 additions and 0 deletions
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { mount, shallowMount } from "@vue/test-utils";
|
||||||
|
import saveProgressModalQuestion from "./save-progress-modal-question";
|
||||||
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
|
|
||||||
|
jest.mock("@/digital-components/modal/modal", () => ({
|
||||||
|
methods: {
|
||||||
|
openModal: jest.fn(),
|
||||||
|
resetButtonStyle: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("save-progress-modal-question ", () => {
|
||||||
|
describe("when openModal is run ", () => {
|
||||||
|
test("the modal should open ", () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = setupMocks({
|
||||||
|
props: {
|
||||||
|
modelValue: "",
|
||||||
|
modalWidgetName: "testModal",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
wrapper.vm.openModal();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.modal).not.toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function setupMocks({ options, props }) {
|
||||||
|
const mountOptions = getMountOptions({
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockBaseMixin = {
|
||||||
|
methods: {
|
||||||
|
getCmsContent: jest.fn(),
|
||||||
|
dispatchStoreAction: jest.fn(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (props) mountOptions.propsData = props;
|
||||||
|
|
||||||
|
mountOptions.global.mixins = [mockBaseMixin];
|
||||||
|
|
||||||
|
const wrapper = mount(saveProgressModalQuestion, mountOptions);
|
||||||
|
|
||||||
|
return { wrapper };
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
import saveProgressQuestion from "./save-progress-question";
|
||||||
|
|
||||||
|
describe("save-progress-question.vue", () => {
|
||||||
|
it("Should get the modelValue", async () => {
|
||||||
|
// Arrange
|
||||||
|
const text = "test";
|
||||||
|
const wrapper = shallowMount(saveProgressQuestion, {
|
||||||
|
props: {
|
||||||
|
modelValue: text,
|
||||||
|
},
|
||||||
|
attachTo: document.body,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const modelValueText = wrapper.vm.value;
|
||||||
|
wrapper.vm.value = "test also";
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(modelValueText).toEqual("test");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should emit to set value", async () => {
|
||||||
|
// Arrange
|
||||||
|
const text = "test";
|
||||||
|
const wrapper = shallowMount(saveProgressQuestion, {
|
||||||
|
props: {
|
||||||
|
modelValue: text,
|
||||||
|
},
|
||||||
|
attachTo: document.body,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const modelValueText = wrapper.vm.value;
|
||||||
|
wrapper.vm.value = "test also";
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.emitted("update:modelValue")).toEqual([["test also"]]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue