Formatting.
This commit is contained in:
parent
f24214fbca
commit
8b1a42547d
2 changed files with 115 additions and 112 deletions
|
|
@ -232,13 +232,16 @@ describe("textboxQuestion.vue", () => {
|
|||
// Arrange
|
||||
const inputId = "test";
|
||||
const responseValue = "testResponse";
|
||||
|
||||
const imageHandler = jest.fn().mockImplementation(() => new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: [responseValue],
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
const imageHandler = jest.fn().mockImplementation(
|
||||
() =>
|
||||
new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: [responseValue],
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
directives: {
|
||||
|
|
@ -247,93 +250,7 @@ describe("textboxQuestion.vue", () => {
|
|||
},
|
||||
propsData: {
|
||||
modelValue: "",
|
||||
'onUpdate:modelValue': (v) => wrapper.setProps({modelValue: v}),
|
||||
includeImageQuestion: true,
|
||||
inputId: inputId,
|
||||
imageQuestionSubmitHandler: imageHandler
|
||||
},
|
||||
mixins: [mockMixin],
|
||||
attachTo: document.body,
|
||||
});
|
||||
|
||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||
wrapper.vm.isImageValid = jest.fn().mockImplementation(() => true);
|
||||
|
||||
// Act
|
||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||
|
||||
await imageUploadField.trigger("change");
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
|
||||
expect(wrapper.vm.imageQuestionSubmitHandler).toHaveBeenCalled();
|
||||
expect(wrapper.vm.handleChange).toHaveBeenCalled();
|
||||
expect(wrapper.emitted()).toHaveProperty("update:modelValue");
|
||||
});
|
||||
|
||||
it("Should not call handler and emit image-lookup-error when image is invalid.", async () => {
|
||||
// Arrange
|
||||
const inputId = "test";
|
||||
const responseValue = "testResponse";
|
||||
|
||||
const imageHandler = jest.fn().mockImplementation(() => new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: [responseValue],
|
||||
});
|
||||
}));
|
||||
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
directives: {
|
||||
maska: maska,
|
||||
},
|
||||
},
|
||||
propsData: {
|
||||
modelValue: "",
|
||||
'onUpdate:modelValue': (v) => wrapper.setProps({modelValue: v}),
|
||||
includeImageQuestion: true,
|
||||
inputId: inputId,
|
||||
imageQuestionSubmitHandler: imageHandler
|
||||
},
|
||||
mixins: [mockMixin],
|
||||
attachTo: document.body,
|
||||
});
|
||||
|
||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||
wrapper.vm.isImageValid = jest.fn().mockImplementation(() => false);
|
||||
|
||||
// Act
|
||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||
|
||||
await imageUploadField.trigger("change");
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.imageQuestionSubmitHandler).not.toHaveBeenCalled();
|
||||
expect(wrapper.vm.handleChange).not.toHaveBeenCalled();
|
||||
expect(wrapper.emitted()).toHaveProperty("imageValidityError");
|
||||
});
|
||||
|
||||
it("Should emit image-lookup-error when image lookup responds with an error.", async () => {
|
||||
// Arrange
|
||||
const inputId = "test";
|
||||
|
||||
const imageHandler = jest.fn().mockImplementation(() => new Promise((resolve, reject) => {
|
||||
reject({});
|
||||
}));
|
||||
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
directives: {
|
||||
maska: maska,
|
||||
},
|
||||
},
|
||||
propsData: {
|
||||
modelValue: "",
|
||||
'onUpdate:modelValue': (v) => wrapper.setProps({modelValue: v}),
|
||||
"onUpdate:modelValue": (v) => wrapper.setProps({ modelValue: v }),
|
||||
includeImageQuestion: true,
|
||||
inputId: inputId,
|
||||
imageQuestionSubmitHandler: imageHandler,
|
||||
|
|
@ -341,17 +258,109 @@ describe("textboxQuestion.vue", () => {
|
|||
mixins: [mockMixin],
|
||||
attachTo: document.body,
|
||||
});
|
||||
|
||||
|
||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||
wrapper.vm.isImageValid = jest.fn().mockImplementation(() => true);
|
||||
|
||||
|
||||
// Act
|
||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||
|
||||
|
||||
await imageUploadField.trigger("change");
|
||||
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
|
||||
// Assert
|
||||
|
||||
expect(wrapper.vm.imageQuestionSubmitHandler).toHaveBeenCalled();
|
||||
expect(wrapper.vm.handleChange).toHaveBeenCalled();
|
||||
expect(wrapper.emitted()).toHaveProperty("update:modelValue");
|
||||
});
|
||||
|
||||
it("Should not call handler and emit image-lookup-error when image is invalid.", async () => {
|
||||
// Arrange
|
||||
const inputId = "test";
|
||||
const responseValue = "testResponse";
|
||||
|
||||
const imageHandler = jest.fn().mockImplementation(
|
||||
() =>
|
||||
new Promise((resolve, reject) => {
|
||||
resolve({
|
||||
data: [responseValue],
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
directives: {
|
||||
maska: maska,
|
||||
},
|
||||
},
|
||||
propsData: {
|
||||
modelValue: "",
|
||||
"onUpdate:modelValue": (v) => wrapper.setProps({ modelValue: v }),
|
||||
includeImageQuestion: true,
|
||||
inputId: inputId,
|
||||
imageQuestionSubmitHandler: imageHandler,
|
||||
},
|
||||
mixins: [mockMixin],
|
||||
attachTo: document.body,
|
||||
});
|
||||
|
||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||
wrapper.vm.isImageValid = jest.fn().mockImplementation(() => false);
|
||||
|
||||
// Act
|
||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||
|
||||
await imageUploadField.trigger("change");
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.imageQuestionSubmitHandler).not.toHaveBeenCalled();
|
||||
expect(wrapper.vm.handleChange).not.toHaveBeenCalled();
|
||||
expect(wrapper.emitted()).toHaveProperty("imageValidityError");
|
||||
});
|
||||
|
||||
it("Should emit image-lookup-error when image lookup responds with an error.", async () => {
|
||||
// Arrange
|
||||
const inputId = "test";
|
||||
|
||||
const imageHandler = jest.fn().mockImplementation(
|
||||
() =>
|
||||
new Promise((resolve, reject) => {
|
||||
reject({});
|
||||
})
|
||||
);
|
||||
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
directives: {
|
||||
maska: maska,
|
||||
},
|
||||
},
|
||||
propsData: {
|
||||
modelValue: "",
|
||||
"onUpdate:modelValue": (v) => wrapper.setProps({ modelValue: v }),
|
||||
includeImageQuestion: true,
|
||||
inputId: inputId,
|
||||
imageQuestionSubmitHandler: imageHandler,
|
||||
},
|
||||
mixins: [mockMixin],
|
||||
attachTo: document.body,
|
||||
});
|
||||
|
||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||
wrapper.vm.isImageValid = jest.fn().mockImplementation(() => true);
|
||||
|
||||
// Act
|
||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||
|
||||
await imageUploadField.trigger("change");
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.imageQuestionSubmitHandler).toHaveBeenCalled();
|
||||
expect(wrapper.vm.handleChange).not.toHaveBeenCalled();
|
||||
|
|
|
|||
|
|
@ -262,9 +262,7 @@ describe("vin-lookup.vue", () => {
|
|||
// Arrange
|
||||
const responseValue = "testResponse";
|
||||
const lookup = jest.fn().mockImplementation(() => {
|
||||
return new Promise(
|
||||
(resolve, reject) => resolve([ responseValue ])
|
||||
);
|
||||
return new Promise((resolve, reject) => resolve([responseValue]));
|
||||
});
|
||||
|
||||
const image = {};
|
||||
|
|
@ -276,7 +274,7 @@ describe("vin-lookup.vue", () => {
|
|||
};
|
||||
|
||||
const { wrapper } = setupMocks({
|
||||
mixins: [storeMixin]
|
||||
mixins: [storeMixin],
|
||||
});
|
||||
|
||||
// Act
|
||||
|
|
@ -284,15 +282,13 @@ describe("vin-lookup.vue", () => {
|
|||
|
||||
// Assert
|
||||
expect(lookup).toHaveBeenCalled();
|
||||
expect(response).toEqual(responseValue)
|
||||
expect(response).toEqual(responseValue);
|
||||
});
|
||||
|
||||
test("GetVinFromImage rejects if no vins are returned.", async () => {
|
||||
// Arrange
|
||||
const lookup = jest.fn().mockImplementation(() => {
|
||||
return new Promise(
|
||||
(resolve, reject) => resolve([])
|
||||
);
|
||||
return new Promise((resolve, reject) => resolve([]));
|
||||
});
|
||||
|
||||
const image = {};
|
||||
|
|
@ -304,7 +300,7 @@ describe("vin-lookup.vue", () => {
|
|||
};
|
||||
|
||||
const { wrapper } = setupMocks({
|
||||
mixins: [storeMixin]
|
||||
mixins: [storeMixin],
|
||||
});
|
||||
|
||||
// Act
|
||||
|
|
@ -316,9 +312,7 @@ describe("vin-lookup.vue", () => {
|
|||
|
||||
test("GetVinFromImage rejects if an error occurs.", async () => {
|
||||
const lookup = jest.fn().mockImplementation(() => {
|
||||
return new Promise(
|
||||
(resolve, reject) => reject()
|
||||
);
|
||||
return new Promise((resolve, reject) => reject());
|
||||
});
|
||||
|
||||
const image = {};
|
||||
|
|
@ -330,7 +324,7 @@ describe("vin-lookup.vue", () => {
|
|||
};
|
||||
|
||||
const { wrapper } = setupMocks({
|
||||
mixins: [storeMixin]
|
||||
mixins: [storeMixin],
|
||||
});
|
||||
|
||||
// Act
|
||||
|
|
|
|||
Loading…
Reference in a new issue