From d6617827930844efce61d781fe7bb9f26d929102 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:26:01 +0100 Subject: [PATCH] Refactor JobDestinationParams test - And drop redundant test that tries to access the internals of the component --- .../JobDestinationParams.test.ts | 65 +++++++++---------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/client/src/components/JobDestinationParams/JobDestinationParams.test.ts b/client/src/components/JobDestinationParams/JobDestinationParams.test.ts index c3ee6e9eebbf..5486f481f91d 100644 --- a/client/src/components/JobDestinationParams/JobDestinationParams.test.ts +++ b/client/src/components/JobDestinationParams/JobDestinationParams.test.ts @@ -1,4 +1,4 @@ -import { shallowMount, Wrapper } from "@vue/test-utils"; +import { shallowMount } from "@vue/test-utils"; import flushPromises from "flush-promises"; import { createPinia } from "pinia"; import { getLocalVue } from "tests/jest/helpers"; @@ -18,47 +18,40 @@ const localVue = getLocalVue(); const jobDestinationResponse = jobDestinationResponseData as Record; -describe("JobDestinationParams/JobDestinationParams.vue", () => { - const responseKeys = Object.keys(jobDestinationResponse); - expect(responseKeys.length > 0).toBeTruthy(); +async function mountJobDestinationParams() { + mockFetcher.path("/api/jobs/{job_id}/destination_params").method("get").mock({ data: jobDestinationResponse }); - let wrapper: Wrapper; - - beforeEach(async () => { - const propsData = { + const pinia = createPinia(); + const wrapper = shallowMount(JobDestinationParams as object, { + propsData: { jobId: JOB_ID, - }; - - mockFetcher.path("/api/jobs/{job_id}/destination_params").method("get").mock({ data: jobDestinationResponse }); - - const pinia = createPinia(); - wrapper = shallowMount(JobDestinationParams as object, { - propsData, - localVue, - pinia, - }); - - const userStore = useUserStore(); - userStore.currentUser = { - email: "admin@email", - id: "1", - tags_used: [], - isAnonymous: false, - total_disk_usage: 1048576, - is_admin: true, - }; - - await flushPromises(); + }, + localVue, + pinia, }); - it("destination parameters should exist", async () => { - expect(Object.keys(wrapper.vm.jobDestinationParams).length).toBe(responseKeys.length); - expect(wrapper.vm.jobId).toBe(JOB_ID); - expect(wrapper.vm.jobDestinationParams["docker_net"]).toBe("bridge"); - expect(wrapper.vm.jobDestinationParams["docker_set_user"]).toBeNull(); - }); + const userStore = useUserStore(); + userStore.currentUser = { + email: "admin@email", + id: "1", + tags_used: [], + isAnonymous: false, + total_disk_usage: 1048576, + is_admin: true, + }; + + await flushPromises(); + + return wrapper; +} + +describe("JobDestinationParams/JobDestinationParams.vue", () => { + const responseKeys = Object.keys(jobDestinationResponse); + expect(responseKeys.length > 0).toBeTruthy(); it("should render destination parameters", async () => { + const wrapper = await mountJobDestinationParams(); + const paramsTable = wrapper.find("#destination_parameters"); expect(paramsTable.exists()).toBe(true); const params = paramsTable.findAll("tbody > tr");