Add tests for textbox-question
This commit is contained in:
parent
d111d0a7bc
commit
e06be65e34
2 changed files with 140 additions and 0 deletions
|
|
@ -197,4 +197,143 @@ describe("textboxQuestion.vue", () => {
|
|||
// Assert
|
||||
expect(wrapper.vm.handleChange).toHaveBeenCalled;
|
||||
});
|
||||
|
||||
it("Should call this.handleChange when image is submitted with valid value.", async () => {
|
||||
// Arrange
|
||||
const inputId = 'test';
|
||||
const responseValue = 'testResponse';
|
||||
|
||||
const storeMixin = {
|
||||
methods: {
|
||||
dispatchStoreAction: jest.fn().mockImplementation(() => {
|
||||
return new Promise(
|
||||
(resolve, reject) => resolve(
|
||||
{
|
||||
data: [ responseValue ]
|
||||
}
|
||||
)
|
||||
);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
directives: {
|
||||
maska: maska,
|
||||
},
|
||||
},
|
||||
propsData: {
|
||||
modelValue: "",
|
||||
includeCameraIcon: true,
|
||||
inputId: inputId,
|
||||
},
|
||||
mixins: [mockMixin, storeMixin],
|
||||
attachTo: document.body
|
||||
});
|
||||
|
||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||
|
||||
// Act
|
||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||
|
||||
await imageUploadField.trigger('change');
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
|
||||
expect(wrapper.vm.handleChange).toHaveBeenCalled();
|
||||
expect(wrapper.emitted()).toHaveProperty("update:modelValue");
|
||||
});
|
||||
|
||||
it("Should emit image-lookup-error when image is submitted with invalid value", async () => {
|
||||
// Arrange
|
||||
const inputId = 'test';
|
||||
|
||||
const storeMixin = {
|
||||
methods: {
|
||||
dispatchStoreAction: jest.fn().mockImplementation(() => {
|
||||
return new Promise(
|
||||
(resolve, reject) => resolve(
|
||||
{
|
||||
data: []
|
||||
}
|
||||
)
|
||||
);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
directives: {
|
||||
maska: maska,
|
||||
},
|
||||
},
|
||||
propsData: {
|
||||
modelValue: "",
|
||||
includeCameraIcon: true,
|
||||
inputId: inputId,
|
||||
},
|
||||
mixins: [mockMixin, storeMixin],
|
||||
attachTo: document.body
|
||||
});
|
||||
|
||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||
|
||||
// Act
|
||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||
|
||||
await imageUploadField.trigger('change');
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.handleChange).not.toHaveBeenCalled();
|
||||
expect(wrapper.emitted()).toHaveProperty("imageLookupError");
|
||||
});
|
||||
|
||||
it("Should emit image-lookup-error when image endpoint responds with an error", async () => {
|
||||
// Arrange
|
||||
const inputId = 'test';
|
||||
|
||||
const storeMixin = {
|
||||
methods: {
|
||||
dispatchStoreAction: jest.fn().mockImplementation(() => {
|
||||
return new Promise(
|
||||
(resolve, reject) => reject()
|
||||
);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
directives: {
|
||||
maska: maska,
|
||||
},
|
||||
},
|
||||
propsData: {
|
||||
modelValue: "",
|
||||
includeCameraIcon: true,
|
||||
inputId: inputId,
|
||||
},
|
||||
mixins: [mockMixin, storeMixin],
|
||||
attachTo: document.body
|
||||
});
|
||||
|
||||
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
|
||||
|
||||
// Act
|
||||
const imageUploadField = wrapper.find('[data-test="image-upload"]');
|
||||
|
||||
await imageUploadField.trigger('change');
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.handleChange).not.toHaveBeenCalled();
|
||||
expect(wrapper.emitted()).toHaveProperty("imageLookupError");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
id="vin-input"
|
||||
accept="image/"
|
||||
aria-label="Camera icon/button"
|
||||
data-test="image-upload"
|
||||
@change="submitImage" />
|
||||
</label>
|
||||
<loader
|
||||
|
|
|
|||
Loading…
Reference in a new issue