Skip to content

Commit

Permalink
fix jest fails caused by DatasetDetails id is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Nov 7, 2023
1 parent 9a14a5f commit 15d7da0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions client/src/components/History/Content/ContentItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { mount } from "@vue/test-utils";
import { updateContentFields } from "components/History/model/queries";
import { PiniaVuePlugin } from "pinia";
import { getLocalVue } from "tests/jest/helpers";
import VueRouter from "vue-router";

import ContentItem from "./ContentItem";

jest.mock("components/History/model/queries");

const localVue = getLocalVue();
localVue.use(VueRouter);
localVue.use(PiniaVuePlugin);
const router = new VueRouter();

// mock queries
updateContentFields.mockImplementation(async () => {});
Expand Down Expand Up @@ -48,6 +51,7 @@ describe("ContentItem", () => {
},
},
pinia: createTestingPinia(),
router,
});
});

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/History/Content/ContentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<!-- collections are not expandable, so we only need the DatasetDetails component here -->
<b-collapse :visible="expandDataset">
<DatasetDetails
v-if="expandDataset"
v-if="expandDataset && item.id"
:id="item.id"
:writable="writable"
:show-highlight="(isHistoryItem && filterable) || addHighlightBtn"
Expand Down
6 changes: 6 additions & 0 deletions client/src/components/History/Content/GenericElement.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { mount } from "@vue/test-utils";
import { getLocalVue } from "tests/jest/helpers";
import VueRouter from "vue-router";

import GenericElement from "./GenericElement";

jest.mock("components/History/model/queries");

const localVue = getLocalVue();
localVue.use(VueRouter);
const router = new VueRouter();

describe("GenericElement", () => {
let wrapper;
Expand Down Expand Up @@ -54,6 +59,7 @@ describe("GenericElement", () => {
},
},
localVue,
router,
});
});

Expand Down
10 changes: 5 additions & 5 deletions client/src/components/History/HistoryView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async function createWrapper(localVue, currentUserId, history) {
localVue,
stubs: {
icon: { template: "<div></div>" },
ContentItem: true,
},
provide: {
store: {
Expand Down Expand Up @@ -119,14 +120,13 @@ describe("History center panel View", () => {
// parts of the layout that should be similar for all cases
expectCorrectLayout(wrapper);

// all history items, make sure all show up with hids and names
const historyItems = wrapper.findAll(".content-item");
// make sure all history items show up
const historyItems = wrapper.findAll("contentitem-stub");
expect(historyItems.length).toBe(10);
for (let i = 0; i < historyItems.length; i++) {
const hid = historyItems.length - i;
const itemHeader = historyItems.at(i).find("[data-description='content item header info']");
const headerText = `${hid}: Dataset ${hid}`;
expect(itemHeader.text()).toBe(headerText);
expect(historyItems.at(i).attributes("id")).toBe(`${hid}`);
expect(historyItems.at(i).attributes("name")).toBe(`Dataset ${hid}`);
}
});

Expand Down
14 changes: 11 additions & 3 deletions client/src/components/JobParameters/JobParameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe("JobParameters/JobParameters.vue", () => {
propsData,
stubs: {
DatasetProvider: DatasetProvider,
ContentItem: true,
},
pinia,
});
Expand All @@ -54,12 +55,18 @@ describe("JobParameters/JobParameters.vue", () => {
const checkTableParameter = (
element: Wrapper<any>,
expectedTitle: string,
expectedValue: string,
expectedValue: string | { hid: number; name: string },
link?: string
) => {
const tds = element.findAll("td");
expect(tds.at(0).text()).toBe(expectedTitle);
expect(tds.at(1).text()).toContain(expectedValue);
if (typeof expectedValue === "string") {
expect(tds.at(1).text()).toContain(expectedValue);
} else {
const contentItem = tds.at(1).find("contentitem-stub");
expect(contentItem.attributes("id")).toBe(`${expectedValue.hid}`);
expect(contentItem.attributes("name")).toBe(expectedValue.name);
}
if (link) {
const a_element = tds.at(1).find("a");
expect(a_element.attributes("href")).toBe(link);
Expand All @@ -74,7 +81,7 @@ describe("JobParameters/JobParameters.vue", () => {
expect(elements.length).toBe(3);

checkTableParameter(elements.at(0), "Add this value", "22", undefined);
checkTableParameter(elements.at(1), linkParam.text, `${raw.hid}: ${raw.name}`, undefined);
checkTableParameter(elements.at(1), linkParam.text, { hid: raw.hid, name: raw.name }, undefined);
checkTableParameter(elements.at(2), "Iterate?", "NO", undefined);
});

Expand All @@ -89,6 +96,7 @@ describe("JobParameters/JobParameters.vue", () => {
propsData,
stubs: {
DatasetProvider: DatasetProvider,
ContentItem: true,
},
pinia,
});
Expand Down

0 comments on commit 15d7da0

Please sign in to comment.