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
|
// Arrange
|
||||||
const inputId = "test";
|
const inputId = "test";
|
||||||
const responseValue = "testResponse";
|
const responseValue = "testResponse";
|
||||||
|
|
||||||
const imageHandler = jest.fn().mockImplementation(() => new Promise((resolve, reject) => {
|
const imageHandler = jest.fn().mockImplementation(
|
||||||
resolve({
|
() =>
|
||||||
data: [responseValue],
|
new Promise((resolve, reject) => {
|
||||||
});
|
resolve({
|
||||||
}));
|
data: [responseValue],
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const wrapper = shallowMount(textboxQuestion, {
|
const wrapper = shallowMount(textboxQuestion, {
|
||||||
global: {
|
global: {
|
||||||
directives: {
|
directives: {
|
||||||
|
|
@ -247,93 +250,7 @@ describe("textboxQuestion.vue", () => {
|
||||||
},
|
},
|
||||||
propsData: {
|
propsData: {
|
||||||
modelValue: "",
|
modelValue: "",
|
||||||
'onUpdate:modelValue': (v) => wrapper.setProps({modelValue: v}),
|
"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}),
|
|
||||||
includeImageQuestion: true,
|
includeImageQuestion: true,
|
||||||
inputId: inputId,
|
inputId: inputId,
|
||||||
imageQuestionSubmitHandler: imageHandler,
|
imageQuestionSubmitHandler: imageHandler,
|
||||||
|
|
@ -341,17 +258,109 @@ describe("textboxQuestion.vue", () => {
|
||||||
mixins: [mockMixin],
|
mixins: [mockMixin],
|
||||||
attachTo: document.body,
|
attachTo: document.body,
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||||
wrapper.vm.isImageValid = jest.fn().mockImplementation(() => true);
|
wrapper.vm.isImageValid = jest.fn().mockImplementation(() => true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||||
|
|
||||||
await imageUploadField.trigger("change");
|
await imageUploadField.trigger("change");
|
||||||
|
|
||||||
await wrapper.vm.$nextTick();
|
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
|
// Assert
|
||||||
expect(wrapper.vm.imageQuestionSubmitHandler).toHaveBeenCalled();
|
expect(wrapper.vm.imageQuestionSubmitHandler).toHaveBeenCalled();
|
||||||
expect(wrapper.vm.handleChange).not.toHaveBeenCalled();
|
expect(wrapper.vm.handleChange).not.toHaveBeenCalled();
|
||||||
|
|
|
||||||
|
|
@ -262,9 +262,7 @@ describe("vin-lookup.vue", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const responseValue = "testResponse";
|
const responseValue = "testResponse";
|
||||||
const lookup = jest.fn().mockImplementation(() => {
|
const lookup = jest.fn().mockImplementation(() => {
|
||||||
return new Promise(
|
return new Promise((resolve, reject) => resolve([responseValue]));
|
||||||
(resolve, reject) => resolve([ responseValue ])
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const image = {};
|
const image = {};
|
||||||
|
|
@ -276,7 +274,7 @@ describe("vin-lookup.vue", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const { wrapper } = setupMocks({
|
const { wrapper } = setupMocks({
|
||||||
mixins: [storeMixin]
|
mixins: [storeMixin],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -284,15 +282,13 @@ describe("vin-lookup.vue", () => {
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(lookup).toHaveBeenCalled();
|
expect(lookup).toHaveBeenCalled();
|
||||||
expect(response).toEqual(responseValue)
|
expect(response).toEqual(responseValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GetVinFromImage rejects if no vins are returned.", async () => {
|
test("GetVinFromImage rejects if no vins are returned.", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const lookup = jest.fn().mockImplementation(() => {
|
const lookup = jest.fn().mockImplementation(() => {
|
||||||
return new Promise(
|
return new Promise((resolve, reject) => resolve([]));
|
||||||
(resolve, reject) => resolve([])
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const image = {};
|
const image = {};
|
||||||
|
|
@ -304,7 +300,7 @@ describe("vin-lookup.vue", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const { wrapper } = setupMocks({
|
const { wrapper } = setupMocks({
|
||||||
mixins: [storeMixin]
|
mixins: [storeMixin],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -316,9 +312,7 @@ describe("vin-lookup.vue", () => {
|
||||||
|
|
||||||
test("GetVinFromImage rejects if an error occurs.", async () => {
|
test("GetVinFromImage rejects if an error occurs.", async () => {
|
||||||
const lookup = jest.fn().mockImplementation(() => {
|
const lookup = jest.fn().mockImplementation(() => {
|
||||||
return new Promise(
|
return new Promise((resolve, reject) => reject());
|
||||||
(resolve, reject) => reject()
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const image = {};
|
const image = {};
|
||||||
|
|
@ -330,7 +324,7 @@ describe("vin-lookup.vue", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const { wrapper } = setupMocks({
|
const { wrapper } = setupMocks({
|
||||||
mixins: [storeMixin]
|
mixins: [storeMixin],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue