tests updated
This commit is contained in:
parent
c46d527acb
commit
17fbf65129
2 changed files with 22 additions and 49 deletions
|
|
@ -32,6 +32,7 @@ describe("glass-part-question.vue", () => {
|
|||
//Act
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
console.log(wrapper.vm.featureListData["Green Tint"][0].Text)
|
||||
//Assert
|
||||
expect(Object.keys(wrapper.vm.featureListData).length).toBe(2);
|
||||
expect(wrapper.vm.featureListData["Green Tint"][0].Text).toBe(
|
||||
|
|
@ -101,36 +102,7 @@ describe("glass-part-question.vue", () => {
|
|||
expect(listCard.attributes("groupname")).toBe("Rear-Stationary");
|
||||
expect(listCard.attributes("validationrules")).toBe("Rear-Stationary-tint-required");
|
||||
});
|
||||
|
||||
test("ResetTintAndPartSelections, should reset data elements ", async () => {
|
||||
//Arrange
|
||||
|
||||
featureListData.pageData = {
|
||||
partsOrQuestions: [
|
||||
{
|
||||
glassName: "Stationary",
|
||||
glassLocation: "Rear",
|
||||
parts: [{ partNumber: "DB12209GTYN", color: "Green Tint" },
|
||||
{ partNumber: "DB12209GTYN2", color: "Green Tint" }
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
const { wrapper } = setupMocks(featureListData);
|
||||
|
||||
//Act
|
||||
await wrapper.vm.$nextTick();
|
||||
await wrapper.setData({ selectedTint: "Green Tint", selectedPartNumber: "DB12209GTYN" });
|
||||
|
||||
expect(wrapper.vm.selectedTint).toEqual("Green Tint");
|
||||
expect(wrapper.vm.selectedPartNumber).toEqual("DB12209GTYN");
|
||||
|
||||
await wrapper.vm.ResetTintAndPartSelections();
|
||||
|
||||
expect(wrapper.vm.selectedTint).toEqual("Green Tint");
|
||||
expect(wrapper.vm.selectedPartNumber).toEqual(null);
|
||||
});
|
||||
|
||||
|
||||
test("default is selected if only one option", async () => {
|
||||
// Arrange
|
||||
featureListData.pageData = {
|
||||
|
|
@ -156,7 +128,7 @@ describe("glass-part-question.vue", () => {
|
|||
expect(wrapper.vm.selectedPartNumber).toBe("DB12209GTYN");
|
||||
});
|
||||
|
||||
test("default is not selected if more than one option", async () => {
|
||||
test("first is selected if more than one option", async () => {
|
||||
// Arrange
|
||||
featureListData.pageData = {
|
||||
partsOrQuestions: [
|
||||
|
|
@ -178,8 +150,7 @@ describe("glass-part-question.vue", () => {
|
|||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.emitted()["update:modelValue"]).toBeFalsy();
|
||||
expect(wrapper.vm.selectedPartNumber).toBeFalsy();
|
||||
expect(wrapper.emitted()["update:modelValue"]).toBeTruthy();
|
||||
});
|
||||
|
||||
const partsForSelectedTintTestCases = [
|
||||
|
|
@ -266,7 +237,6 @@ describe("glass-part-question.vue", () => {
|
|||
|
||||
function setupMocks({ glassNameProp, glassLocationProp, colorAnswersProp, modelValueProp, pageData }) {
|
||||
|
||||
|
||||
const mountOptions = getMountOptions({
|
||||
route: {
|
||||
query: {
|
||||
|
|
@ -288,7 +258,7 @@ function setupMocks({ glassNameProp, glassLocationProp, colorAnswersProp, modelV
|
|||
//Mock store
|
||||
const partsOrQuestions = pageData ?? { partsOrQuestions: [{ glassName: "Stationary", glassLocation: "Rear", parts: [] }] };
|
||||
useMainStore().pageData = jest.fn();
|
||||
useMainStore().pageData.mockReturnValueOnce(partsOrQuestions);
|
||||
|
||||
useMainStore().pageData.mockReturnValue(partsOrQuestions);
|
||||
document.querySelector = jest.fn().mockReturnValue({checked: false});
|
||||
return { wrapper };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,22 +180,25 @@ export default {
|
|||
},
|
||||
|
||||
AutoSelect() {
|
||||
// Check if only a single part is present for the tint and set the v-model if it is.
|
||||
if (this.partsForSelectedTint?.length == 1) {
|
||||
this.selectedPartNumber = { value: this.partsForSelectedTint[0].partNumber };
|
||||
}
|
||||
else{
|
||||
// If selected part isn't in the current list or it's null, select the first part
|
||||
if(!this.selectedPartNumber || this.partsForSelectedTint.filter(x => x.partNumber == this.selectedPartNumber).length === 0)
|
||||
{
|
||||
if(this.partsForSelectedTint?.length > 0)
|
||||
{
|
||||
// Check if only a single part is present for the tint and set the v-model if it is.
|
||||
if (this.partsForSelectedTint?.length == 1) {
|
||||
this.selectedPartNumber = { value: this.partsForSelectedTint[0].partNumber };
|
||||
}
|
||||
}
|
||||
else{
|
||||
// If selected part isn't in the current list or it's null, select the first part
|
||||
if(!this.selectedPartNumber || this.partsForSelectedTint.filter(x => x.partNumber == this.selectedPartNumber).length === 0)
|
||||
{
|
||||
this.selectedPartNumber = { value: this.partsForSelectedTint[0].partNumber };
|
||||
}
|
||||
}
|
||||
|
||||
//select element with matching partNumber
|
||||
this.$nextTick(() => {
|
||||
document.querySelector('input[value=' + this.selectedPartNumber + ']').checked = true;
|
||||
});
|
||||
//select element with matching partNumber
|
||||
this.$nextTick(() => {
|
||||
document.querySelector('input[value=' + this.selectedPartNumber + ']').checked = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Loads the preselected values from the store.
|
||||
|
|
|
|||
Loading…
Reference in a new issue