Skip to content

Commit

Permalink
fix PairedListCollectionCreator jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Nov 21, 2024
1 parent 88552f8 commit 4319aca
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 76 deletions.
115 changes: 65 additions & 50 deletions client/src/components/Collections/PairedListCollectionCreator.test.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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");
Expand All @@ -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
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,8 +1279,8 @@ function _naiveStartingAndEndingLCS(s1: string, s2: string) {
<div>
<div class="pairing-split-child">
<div class="column-header">
<div class="column-title paired-column-title">
<span class="title"> {{ numOfPairs }} {{ localize(" pairs") }}</span>
<div class="column-title paired-column-title" data-description="number of pairs">
<span class="title"> {{ numOfPairs }} {{ localize("pairs") }}</span>
</div>
<BButton
v-if="generatedPairs.length > 0"
Expand Down
48 changes: 24 additions & 24 deletions client/tests/test-data/paired-collection-creator.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@ import STATES from "mvc/dataset/states";
// ============================================================================
// plain 3 step job chain
var datasets1 = [
{ name: "SET1-01_1.fastq", state: STATES.OK },
{ name: "SET1-01_2.fastq", state: STATES.OK },
{ name: "SET1-02_1.fastq", state: STATES.OK },
{ name: "SET1-02_2.fastq", state: STATES.OK },
{ name: "SET1-03_1.fastq", state: STATES.OK },
{ name: "SET1-03_2.fastq", state: STATES.OK },
{ name: "SET1-04_1.fastq", state: STATES.OK },
{ name: "SET1-04_2.fastq", state: STATES.OK },
{ name: "SET1-05_1.fastq", state: STATES.OK },
{ name: "SET1-05_2.fastq", state: STATES.OK },
{ name: "SET1-06_1.fastq", state: STATES.OK },
{ name: "SET1-06_2.fastq", state: STATES.OK },
{ name: "SET1-07_1.fastq", state: STATES.OK },
{ name: "SET1-07_2.fastq", state: STATES.OK },
{ name: "SET1-01_1.fastq", state: STATES.OK, id: "011" },
{ name: "SET1-01_2.fastq", state: STATES.OK, id: "012" },
{ name: "SET1-02_1.fastq", state: STATES.OK, id: "021" },
{ name: "SET1-02_2.fastq", state: STATES.OK, id: "022" },
{ name: "SET1-03_1.fastq", state: STATES.OK, id: "031" },
{ name: "SET1-03_2.fastq", state: STATES.OK, id: "032" },
{ name: "SET1-04_1.fastq", state: STATES.OK, id: "041" },
{ name: "SET1-04_2.fastq", state: STATES.OK, id: "042" },
{ name: "SET1-05_1.fastq", state: STATES.OK, id: "051" },
{ name: "SET1-05_2.fastq", state: STATES.OK, id: "052" },
{ name: "SET1-06_1.fastq", state: STATES.OK, id: "061" },
{ name: "SET1-06_2.fastq", state: STATES.OK, id: "062" },
{ name: "SET1-07_1.fastq", state: STATES.OK, id: "071" },
{ name: "SET1-07_2.fastq", state: STATES.OK, id: "072" },
];

var datasets2 = [
{ name: "DP134_1_FS_PSII_FSB_42C_A10.1.fastq", state: STATES.OK },
{ name: "DP134_1_FS_PSII_FSB_42C_A10.2.fastq", state: STATES.OK },
{ name: "DP134_1_FS_PSII_FSB_42C_A10.1.fastq", state: STATES.OK, id: "101" },
{ name: "DP134_1_FS_PSII_FSB_42C_A10.2.fastq", state: STATES.OK, id: "102" },
];

var datasets3 = [
{ name: "UII_moo_1.1.fastq", state: STATES.OK },
{ name: "UII_moo_1.2.fastq", state: STATES.OK },
{ name: "UII_moo_1.1.fastq", state: STATES.OK, id: "11" },
{ name: "UII_moo_1.2.fastq", state: STATES.OK, id: "12" },
];

var datasets4 = [
{ name: "SET1-01_R1.fastq", state: STATES.OK },
{ name: "SET1-01_R2.fastq", state: STATES.OK },
{ name: "SET1-02_R1.fastq", state: STATES.OK },
{ name: "SET1-02_R2.fastq", state: STATES.OK },
{ name: "SET1-03_R1.fastq", state: STATES.OK },
{ name: "SET1-03_R2.fastq", state: STATES.OK },
{ name: "SET1-01_R1.fastq", state: STATES.OK, id: "111" },
{ name: "SET1-01_R2.fastq", state: STATES.OK, id: "112" },
{ name: "SET1-02_R1.fastq", state: STATES.OK, id: "211" },
{ name: "SET1-02_R2.fastq", state: STATES.OK, id: "212" },
{ name: "SET1-03_R1.fastq", state: STATES.OK, id: "311" },
{ name: "SET1-03_R2.fastq", state: STATES.OK, id: "312" },
];

var datasets1CreateRequestJSON = {
Expand Down

0 comments on commit 4319aca

Please sign in to comment.