From a69b79a4a8dbfa0daa639f5726c2b340a764568f Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Tue, 19 Nov 2024 11:54:06 -0600 Subject: [PATCH] fix `PairedListCollectionCreator` jest --- .../PairedListCollectionCreator.test.js | 115 ++++++++++-------- .../PairedListCollectionCreator.vue | 4 +- .../paired-collection-creator.data.js | 48 ++++---- 3 files changed, 91 insertions(+), 76 deletions(-) diff --git a/client/src/components/Collections/PairedListCollectionCreator.test.js b/client/src/components/Collections/PairedListCollectionCreator.test.js index a798ba2f8f17..d62270b04335 100644 --- a/client/src/components/Collections/PairedListCollectionCreator.test.js +++ b/client/src/components/Collections/PairedListCollectionCreator.test.js @@ -1,48 +1,69 @@ +import { createTestingPinia } from "@pinia/testing"; import DATA from "@tests/test-data/paired-collection-creator.data.js"; import { mount, shallowMount } from "@vue/test-utils"; import PairedListCollectionCreator from "components/Collections/PairedListCollectionCreator"; +import flushPromises from "flush-promises"; +import Vue from "vue"; + +import { useServerMock } from "@/api/client/__mocks__"; + +// Mock the localize directive +// (otherwise we get: [Vue warn]: Failed to resolve directive: localize) +Vue.directive("localize", { + bind(el, binding) { + el.textContent = binding.value; + }, +}); + +const { server, http } = useServerMock(); describe("PairedListCollectionCreator", () => { let wrapper; + const pinia = createTestingPinia(); + + beforeEach(() => { + server.use( + http.get("/api/configuration", ({ response }) => { + return response(200).json({ + chunk_upload_size: 100, + file_sources_configured: true, + }); + }) + ); + }); + + it("performs an autopair on startup if we have a selection", async () => { + // Kind of deprecated because we are never using `props.fromSelection: true` anywhere - it("autopairs the dataset", async () => { wrapper = shallowMount(PairedListCollectionCreator, { propsData: { + historyId: "history_id", initialElements: DATA._1, - creationFn: () => { - return; - }, - oncreate: () => { - return; - }, - oncancel: () => { - return; - }, - hideSourceItems: false, + fromSelection: true, }, + pinia, }); - await wrapper.vm.$nextTick(); + + await flushPromises(); // Autopair is called on startup - expect(wrapper.findAll("li.dataset unpaired").length == 0).toBeTruthy(); + const pairsCountDisplay = wrapper.find('[data-description="number of pairs"]'); + expect(pairsCountDisplay.text()).toContain(`${DATA._1.length / 2} pairs`); }); - it("selects the correct name for an auotpair", async () => { + it("selects the correct name for an autopair", async () => { wrapper = mount(PairedListCollectionCreator, { propsData: { + historyId: "history_id", initialElements: DATA._2, - creationFn: () => { - return; - }, - oncreate: () => { - return; - }, - oncancel: () => { - return; - }, - hideSourceItems: false, + }, + pinia, + stubs: { + FontAwesomeIcon: true, + BPopover: true, }, }); - await wrapper.vm.$nextTick(); + + await flushPromises(); //change filter to .1.fastq/.2.fastq await wrapper.find("div.forward-unpaired-filter > div.input-group-append > button").trigger("click"); await wrapper @@ -56,7 +77,7 @@ describe("PairedListCollectionCreator", () => { const reverseFilter = wrapper.find("div.reverse-unpaired-filter > input").element.value; expect(reverseFilter).toBe(".2.fastq"); // click Autopair - await wrapper.find("a.autopair-link").trigger("click"); + await wrapper.find(".autopair-link").trigger("click"); //assert pair-name longer name const pairname = wrapper.find("span.pair-name"); expect(pairname.text()).toBe("DP134_1_FS_PSII_FSB_42C_A10"); @@ -65,20 +86,17 @@ describe("PairedListCollectionCreator", () => { it("removes the period from autopair name", async () => { wrapper = mount(PairedListCollectionCreator, { propsData: { + historyId: "history_id", initialElements: DATA._3, - creationFn: () => { - return; - }, - oncreate: () => { - return; - }, - oncancel: () => { - return; - }, - hideSourceItems: false, + }, + pinia, + stubs: { + FontAwesomeIcon: true, + BPopover: true, }, }); - await wrapper.vm.$nextTick(); + + await flushPromises(); //change filter to .1.fastq/.2.fastq await wrapper.find("div.forward-unpaired-filter > div.input-group-append > button").trigger("click"); await wrapper @@ -92,7 +110,7 @@ describe("PairedListCollectionCreator", () => { const reverseFilter = wrapper.find("div.reverse-unpaired-filter > input").element.value; expect(reverseFilter).toBe(".2.fastq"); // click Autopair - await wrapper.find("a.autopair-link").trigger("click"); + await wrapper.find(".autopair-link").trigger("click"); //assert pair-name longer name const pairname = wrapper.find("span.pair-name"); expect(pairname.text()).toBe("UII_moo_1"); @@ -101,20 +119,17 @@ describe("PairedListCollectionCreator", () => { it("autopairs correctly when filters are typed in", async () => { wrapper = mount(PairedListCollectionCreator, { propsData: { + historyId: "history_id", initialElements: DATA._4, - creationFn: () => { - return; - }, - oncreate: () => { - return; - }, - oncancel: () => { - return; - }, - hideSourceItems: false, + }, + pinia, + stubs: { + FontAwesomeIcon: true, + BPopover: true, }, }); - await wrapper.vm.$nextTick(); + + await flushPromises(); //change filter to _R1/_R2 await wrapper.find("div.forward-unpaired-filter > input").setValue("_R1"); await wrapper.find("div.reverse-unpaired-filter > input").setValue("_R2"); @@ -125,7 +140,7 @@ describe("PairedListCollectionCreator", () => { const reverseFilter = wrapper.find("div.reverse-unpaired-filter > input").element.value; expect(reverseFilter).toBe("_R2"); // click Autopair - await wrapper.find("a.autopair-link").trigger("click"); + await wrapper.find(".autopair-link").trigger("click"); //assert all pairs matched expect(wrapper.findAll("li.dataset unpaired").length == 0).toBeTruthy(); }); diff --git a/client/src/components/Collections/PairedListCollectionCreator.vue b/client/src/components/Collections/PairedListCollectionCreator.vue index ae871c69c124..d6e0f385aecb 100644 --- a/client/src/components/Collections/PairedListCollectionCreator.vue +++ b/client/src/components/Collections/PairedListCollectionCreator.vue @@ -1279,8 +1279,8 @@ function _naiveStartingAndEndingLCS(s1: string, s2: string) {
-
- {{ numOfPairs }} {{ localize(" pairs") }} +
+ {{ numOfPairs }} {{ localize("pairs") }}