From 8b1a42547dd74d89c8f7b2fe44040fea2ac59d36 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Tue, 28 Mar 2023 14:09:31 -0400 Subject: [PATCH] Formatting. --- .../textbox-question/textbox-question.spec.js | 207 +++++++++--------- src/layouts/vin-lookup/vin-lookup.spec.js | 20 +- 2 files changed, 115 insertions(+), 112 deletions(-) diff --git a/src/common-components/textbox-question/textbox-question.spec.js b/src/common-components/textbox-question/textbox-question.spec.js index d9a3053a6..dc0124211 100644 --- a/src/common-components/textbox-question/textbox-question.spec.js +++ b/src/common-components/textbox-question/textbox-question.spec.js @@ -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(); diff --git a/src/layouts/vin-lookup/vin-lookup.spec.js b/src/layouts/vin-lookup/vin-lookup.spec.js index 162319ef5..f47fdfb36 100644 --- a/src/layouts/vin-lookup/vin-lookup.spec.js +++ b/src/layouts/vin-lookup/vin-lookup.spec.js @@ -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