Add remaining tests

This commit is contained in:
Chloe Herd 2023-03-15 09:38:58 -04:00
parent 3543c1cb04
commit 78160d4cff
3 changed files with 32 additions and 36 deletions

View file

@ -200,21 +200,19 @@ describe("textboxQuestion.vue", () => {
it("Should call this.handleChange when image is submitted with valid value.", async () => { it("Should call this.handleChange when image is submitted with valid value.", async () => {
// Arrange // Arrange
const inputId = 'test'; const inputId = "test";
const responseValue = 'testResponse'; const responseValue = "testResponse";
const storeMixin = { const storeMixin = {
methods: { methods: {
dispatchStoreAction: jest.fn().mockImplementation(() => { dispatchStoreAction: jest.fn().mockImplementation(() => {
return new Promise( return new Promise((resolve, reject) =>
(resolve, reject) => resolve( resolve({
{ data: [responseValue],
data: [ responseValue ] })
}
)
); );
}) }),
} },
}; };
const wrapper = shallowMount(textboxQuestion, { const wrapper = shallowMount(textboxQuestion, {
@ -229,7 +227,7 @@ describe("textboxQuestion.vue", () => {
inputId: inputId, inputId: inputId,
}, },
mixins: [mockMixin, storeMixin], mixins: [mockMixin, storeMixin],
attachTo: document.body attachTo: document.body,
}); });
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {}); wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
@ -237,7 +235,7 @@ describe("textboxQuestion.vue", () => {
// 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();
@ -249,20 +247,18 @@ describe("textboxQuestion.vue", () => {
it("Should emit image-lookup-error when image is submitted with invalid value", async () => { it("Should emit image-lookup-error when image is submitted with invalid value", async () => {
// Arrange // Arrange
const inputId = 'test'; const inputId = "test";
const storeMixin = { const storeMixin = {
methods: { methods: {
dispatchStoreAction: jest.fn().mockImplementation(() => { dispatchStoreAction: jest.fn().mockImplementation(() => {
return new Promise( return new Promise((resolve, reject) =>
(resolve, reject) => resolve( resolve({
{ data: [],
data: [] })
}
)
); );
}) }),
} },
}; };
const wrapper = shallowMount(textboxQuestion, { const wrapper = shallowMount(textboxQuestion, {
@ -277,7 +273,7 @@ describe("textboxQuestion.vue", () => {
inputId: inputId, inputId: inputId,
}, },
mixins: [mockMixin, storeMixin], mixins: [mockMixin, storeMixin],
attachTo: document.body attachTo: document.body,
}); });
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {}); wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
@ -285,7 +281,7 @@ describe("textboxQuestion.vue", () => {
// 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();
@ -296,16 +292,14 @@ describe("textboxQuestion.vue", () => {
it("Should emit image-lookup-error when image endpoint responds with an error", async () => { it("Should emit image-lookup-error when image endpoint responds with an error", async () => {
// Arrange // Arrange
const inputId = 'test'; const inputId = "test";
const storeMixin = { const storeMixin = {
methods: { methods: {
dispatchStoreAction: jest.fn().mockImplementation(() => { dispatchStoreAction: jest.fn().mockImplementation(() => {
return new Promise( return new Promise((resolve, reject) => reject());
(resolve, reject) => reject() }),
); },
})
}
}; };
const wrapper = shallowMount(textboxQuestion, { const wrapper = shallowMount(textboxQuestion, {
@ -320,7 +314,7 @@ describe("textboxQuestion.vue", () => {
inputId: inputId, inputId: inputId,
}, },
mixins: [mockMixin, storeMixin], mixins: [mockMixin, storeMixin],
attachTo: document.body attachTo: document.body,
}); });
wrapper.vm.handleChange = jest.fn().mockImplementation(() => {}); wrapper.vm.handleChange = jest.fn().mockImplementation(() => {});
@ -328,7 +322,7 @@ describe("textboxQuestion.vue", () => {
// 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();

View file

@ -249,7 +249,7 @@ describe("vin-lookup.vue", () => {
// Act // Act
const vinLookup = wrapper.findComponent('[data-test="vin-lookup-component"]'); const vinLookup = wrapper.findComponent('[data-test="vin-lookup-component"]');
vinLookup.trigger('imageLookupError'); vinLookup.trigger("imageLookupError");
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
// Assert // Assert

View file

@ -409,14 +409,14 @@ describe("Actions", () => {
const dummyImage = {}; const dummyImage = {};
globalMethods.callHttpClient.mockImplementation(() => { globalMethods.callHttpClient.mockImplementation(() => {
return Promise.resolve({ data: [ "1C6JJTAG3NL134044" ] }); return Promise.resolve({ data: ["1C6JJTAG3NL134044"] });
}); });
// Act // Act
const response = await actions.lookupVinByImage(context, dummyImage); const response = await actions.lookupVinByImage(context, dummyImage);
// Assert // Assert
expect(response.data).toEqual([ "1C6JJTAG3NL134044" ]); expect(response.data).toEqual(["1C6JJTAG3NL134044"]);
}); });
it("lookupVinByImage action, should reject if error in calling API", async () => { it("lookupVinByImage action, should reject if error in calling API", async () => {
@ -431,7 +431,9 @@ describe("Actions", () => {
// Act // Act
// Assert // Assert
await expect(actions.lookupVinByImage(context, dummyImage)).rejects.toEqual("An error occurred"); await expect(actions.lookupVinByImage(context, dummyImage)).rejects.toEqual(
"An error occurred"
);
}); });
it("getVehicleMakes action, should return makes list", async () => { it("getVehicleMakes action, should return makes list", async () => {