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
|
// Assert
|
||||||
expect(wrapper.vm.handleChange).toHaveBeenCalled;
|
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"
|
id="vin-input"
|
||||||
accept="image/"
|
accept="image/"
|
||||||
aria-label="Camera icon/button"
|
aria-label="Camera icon/button"
|
||||||
|
data-test="image-upload"
|
||||||
@change="submitImage" />
|
@change="submitImage" />
|
||||||
</label>
|
</label>
|
||||||
<loader
|
<loader
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue