Merge remote-tracking branch 'origin/feature/CSR-1088' into feature/CSR-1012
This commit is contained in:
commit
ac18533a90
4 changed files with 267 additions and 0 deletions
|
|
@ -0,0 +1,98 @@
|
|||
import { mount, shallowMount } from "@vue/test-utils";
|
||||
import mobileLocationModalQuestions from "./mobile-location-modal-questions";
|
||||
import crypto from "crypto";
|
||||
global.crypto = crypto;
|
||||
|
||||
// const linkWidgetName = "linkWidgetName";
|
||||
// const modalWidgetName = "modalWidgetName";
|
||||
// const mobileFeeDisclaimerWidgetName = "MobileFeeDisclaimerWidget";
|
||||
// const workspaceRequirementsWidgetName = "WorkspaceRequirementsWidget";
|
||||
|
||||
// const mockLinkCmsContent = {
|
||||
// BodyText: "Sample link body text here.",
|
||||
// };
|
||||
|
||||
// const mockModalCmsContent = {
|
||||
// FooterText: "Sample modal footer text here.",
|
||||
// };
|
||||
|
||||
// const mockMobileFeeCmsContent = {
|
||||
// Text: "This is the price {custom:mobileFee}",
|
||||
// };
|
||||
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
getCmsContent: jest.fn((widgetName, cmsFieldName) => {
|
||||
if (widgetName === linkWidgetName) {
|
||||
return mockLinkCmsContent[cmsFieldName];
|
||||
}
|
||||
|
||||
if (widgetName === modalWidgetName) {
|
||||
return mockModalCmsContent[cmsFieldName];
|
||||
}
|
||||
|
||||
if (widgetName === mobileFeeDisclaimerWidgetName) {
|
||||
return mockMobileFeeCmsContent[cmsFieldName];
|
||||
}
|
||||
|
||||
return null;
|
||||
}),
|
||||
|
||||
getZipCodeData: jest.fn((zip) => {
|
||||
if (zip === "43235") {
|
||||
return {
|
||||
containsMilitaryBase: false,
|
||||
isServiceable: true,
|
||||
isValid: true,
|
||||
state: "OH",
|
||||
zipCodeCtu: "01820",
|
||||
};
|
||||
}
|
||||
|
||||
if (zip === "61606") {
|
||||
return {
|
||||
containsMilitaryBase: false,
|
||||
isServiceable: true,
|
||||
isValid: true,
|
||||
state: "IL",
|
||||
zipCodeCtu: "01526",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
containsMilitaryBase: false,
|
||||
isServiceable: false,
|
||||
isValid: false,
|
||||
state: null,
|
||||
zipCodeCtu: null,
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
describe("mobile-location-modal-questions.vue", () => {
|
||||
it("Initial state on load with no existing location info", async () => {
|
||||
let mobileLocationQuestions = {
|
||||
addressQuestions: {
|
||||
streetAddress: "",
|
||||
apartmentNumberOrBusinessName: "",
|
||||
city: "",
|
||||
state: "",
|
||||
zipCode: "",
|
||||
},
|
||||
isVehicleProtected: null,
|
||||
};
|
||||
|
||||
// Arrange
|
||||
const wrapper = shallowMount(mobileLocationModalQuestions, {
|
||||
mixins: [mockMixin],
|
||||
props: {
|
||||
modelValue: mobileLocationQuestions,
|
||||
},
|
||||
attachTo: document.body,
|
||||
});
|
||||
|
||||
// Assert
|
||||
//expect(wrapper.html()).toEqual(expect.stringContaining(mockLinkCmsContent["BodyText"]));
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
import { shallowMount } from "@vue/test-utils";
|
||||
import vehicleProtectedQuestion from "./vehicle-protected-question";
|
||||
|
||||
jest.mock("@/digital-components/textbox-question/textbox-question", () => ({
|
||||
getCmsContent: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
getCmsContent: jest.fn((widgetName, cmsFieldName) => {
|
||||
if (cmsFieldName === "Answers") {
|
||||
return [
|
||||
{
|
||||
AnswerImageUrl: "",
|
||||
Name: "YesAnswer",
|
||||
SubText: "",
|
||||
SubWidgetName: "",
|
||||
Text: "Yes",
|
||||
},
|
||||
{
|
||||
AnswerImageUrl: "",
|
||||
Name: "NoAnswer",
|
||||
SubText: "",
|
||||
SubWidgetName: "",
|
||||
Text: "No",
|
||||
},
|
||||
];
|
||||
}
|
||||
return "QuestionText";
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
describe("service-zip-question.vue", () => {
|
||||
it("Should get the modelValue", async () => {
|
||||
// Arrange
|
||||
const answer = "YesAnswer";
|
||||
const wrapper = shallowMount(vehicleProtectedQuestion, {
|
||||
mixins: [mockMixin],
|
||||
props: {
|
||||
modelValue: answer,
|
||||
},
|
||||
attachTo: document.body,
|
||||
});
|
||||
|
||||
// Act
|
||||
const modelValueAnswer = wrapper.vm.selectedValue;
|
||||
|
||||
// Assert
|
||||
expect(modelValueAnswer).toEqual(answer);
|
||||
});
|
||||
|
||||
it("Should emit to set value", async () => {
|
||||
// Arrange
|
||||
const yesAnswer = "YesAnswer";
|
||||
const noAnswer = "NoAnswer";
|
||||
const wrapper = shallowMount(vehicleProtectedQuestion, {
|
||||
mixins: [mockMixin],
|
||||
props: {
|
||||
modelValue: yesAnswer,
|
||||
},
|
||||
attachTo: document.body,
|
||||
});
|
||||
|
||||
// Act
|
||||
wrapper.vm.selectedValue = noAnswer;
|
||||
|
||||
// Assert
|
||||
expect(wrapper.emitted("update:modelValue")).toEqual([[noAnswer]]);
|
||||
});
|
||||
});
|
||||
|
|
@ -77,6 +77,103 @@ describe("buttonMain.vue", () => {
|
|||
const loader = wrapper.find("loader-stub");
|
||||
expect(loader.attributes("class")).toContain("right");
|
||||
});
|
||||
|
||||
it("Should set 'isLoaderDisplayed' to false when calling 'removeLoader'", async () => {
|
||||
// Arrange
|
||||
const wrapper = shallowMount(
|
||||
buttonMain,
|
||||
setupMocks({
|
||||
props: {
|
||||
loaderPosition: "right",
|
||||
loaderEnabled: true,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
wrapper.setData({
|
||||
isLoaderDisplayed: true,
|
||||
});
|
||||
|
||||
// Act
|
||||
wrapper.vm.removeLoader();
|
||||
await nextTick();
|
||||
|
||||
// Assert
|
||||
const loader = wrapper.find("loader-stub");
|
||||
expect(wrapper.vm.isLoaderDisplayed).toBe(false);
|
||||
});
|
||||
|
||||
it("Should set 'isLoaderDisplayed' to false when calling 'resetButtonStyle'", async () => {
|
||||
// Arrange
|
||||
const wrapper = shallowMount(
|
||||
buttonMain,
|
||||
setupMocks({
|
||||
props: {
|
||||
loaderPosition: "right",
|
||||
loaderEnabled: true,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
wrapper.setData({
|
||||
isLoaderDisplayed: true,
|
||||
});
|
||||
|
||||
// Act
|
||||
wrapper.vm.resetButtonStyle();
|
||||
await nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.isLoaderDisplayed).toBe(false);
|
||||
});
|
||||
|
||||
it("Should emit 'click-event' event when clicking if the button is enabled", async () => {
|
||||
// Arrange
|
||||
const wrapper = shallowMount(
|
||||
buttonMain,
|
||||
setupMocks({
|
||||
props: {
|
||||
loaderPosition: "right",
|
||||
loaderEnabled: true,
|
||||
isDisabled: false,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
const buttonElement = wrapper.find("button");
|
||||
|
||||
// Act
|
||||
buttonElement.trigger("click");
|
||||
|
||||
await nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.emitted("click-event")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Should not emit 'click-event' event when clicking if the button is disabled", async () => {
|
||||
// Arrange
|
||||
const wrapper = shallowMount(
|
||||
buttonMain,
|
||||
setupMocks({
|
||||
props: {
|
||||
loaderPosition: "right",
|
||||
loaderEnabled: true,
|
||||
isDisabled: true,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
const buttonElement = wrapper.find("button");
|
||||
|
||||
// Act
|
||||
buttonElement.trigger("click");
|
||||
|
||||
await nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.emitted("click-event")).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
function setupMocks(mountOptionsMockData = {}) {
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ export default {
|
|||
true
|
||||
);
|
||||
if (!this.isDisabled) {
|
||||
console.log("I'm here");
|
||||
this.isLoaderDisplayed = true;
|
||||
this.$emit("click-event");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue