Skip to content

Commit

Permalink
App component tests: reintroduction of sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Aug 31, 2023
1 parent f76e91b commit 3778d0d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 109 deletions.
23 changes: 23 additions & 0 deletions app/static/tests/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {VueWrapper} from "@vue/test-utils";
import WodinPanels from "../src/app/components/WodinPanels.vue";

export const fileTimeout = 20;

export const expectCloseNumericArray = (actual: number[], expected: number[]) => {
Expand All @@ -6,3 +9,23 @@ export const expectCloseNumericArray = (actual: number[], expected: number[]) =>
expect(value).toBeCloseTo(expected[idx]);
});
};

const expectWodinTabs = (wrapper: VueWrapper<any>, expectedTabNames: string[], tabType: string) => {
const wodinPanels = wrapper.findComponent(WodinPanels);
const panel = wodinPanels.find(`.wodin-${tabType}`);
const tabs = panel.find(`#${tabType}-tabs`);
const links = tabs.findAll("ul li a");

expect(links.length).toBe(expectedTabNames.length);
expectedTabNames.forEach((expected: string, idx: number) => {
expect(links[idx]!.text()).toBe(expected);
});
};

export const expectRightWodinTabs = (wrapper: VueWrapper<any>, expectedTabNames: string[]) => {
expectWodinTabs(wrapper, expectedTabNames, "right");
};

export const expectLeftWodinTabs = (wrapper: VueWrapper<any>, expectedTabNames: string[]) => {
expectWodinTabs(wrapper, expectedTabNames, "left");
};
49 changes: 14 additions & 35 deletions app/static/tests/unit/components/basic/basicApp.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Mock the import of third party packages to prevent errors
import {expectLeftWodinTabs, expectRightWodinTabs} from "../../../testUtils";

jest.mock("plotly.js-basic-dist-min", () => ({}));
jest.mock("../../../../src/app/components/help/MarkdownItImport.ts", () => {
return function () {
Expand Down Expand Up @@ -93,20 +95,14 @@ describe("BasicApp", () => {
const wodinApp = wrapper.findComponent(WodinApp);

const wodinPanels = wodinApp.findComponent(WodinPanels);
const leftPanel = wodinPanels.find(".wodin-left");
const leftTabs = leftPanel.find("#left-tabs");
const leftTabLinks = leftTabs.findAll("ul li a");
expect(leftTabLinks.length).toBe(2);
expect(leftTabLinks.at(0)!.text()).toBe("Code");
expect(leftTabLinks.at(1)!.text()).toBe("Options");

expectLeftWodinTabs(wrapper, ["Code", "Options"]);
const leftTabs = wodinPanels.find(".wodin-left #left-tabs");
expect(leftTabs.find("div.mt-4 div.code-tab").exists()).toBe(true);

const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
expectRightWodinTabs(wrapper,["Run", "Sensitivity"]);
const rightTabs = wodinPanels.find(".wodin-right #right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(2);
expect(rightTabLinks.at(0)!.text()).toBe("Run");
expect(rightTabLinks.at(1)!.text()).toBe("Sensitivity");
expect(rightTabs.find("div.mt-4 div.run-tab").exists()).toBe(true);
});

Expand Down Expand Up @@ -146,14 +142,9 @@ describe("BasicApp", () => {
}
};
const wrapper = getWrapper(jest.fn(), helpConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(3);
expect(rightTabLinks.at(0)!.text()).toBe("Help");
expect(rightTabLinks.at(1)!.text()).toBe("Run");
expect(rightTabLinks.at(2)!.text()).toBe("Sensitivity");
expectRightWodinTabs(wrapper, ["Help", "Run", "Sensitivity"]);

const rightTabs = wrapper.findComponent(WodinPanels).find(".wodin-right #right-tabs");
expect(rightTabs.findComponent(HelpTab).exists()).toBe(true);
});

Expand All @@ -162,14 +153,10 @@ describe("BasicApp", () => {
multiSensitivity: true
};
const wrapper = getWrapper(jest.fn(), multiSensConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
expectRightWodinTabs(wrapper, ["Run", "Sensitivity", "Multi-sensitivity"]);

const rightTabs = wrapper.findComponent(WodinPanels).find(".wodin-right #right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(3);
expect(rightTabLinks.at(0)!.text()).toBe("Run");
expect(rightTabLinks.at(1)!.text()).toBe("Sensitivity");
expect(rightTabLinks.at(2)!.text()).toBe("Multi-sensitivity");
// Change to Options tab
await rightTabLinks.at(2)!.trigger("click");
expect(rightTabs.findComponent(MultiSensitivityTab).exists()).toBe(true);
Expand All @@ -184,14 +171,6 @@ describe("BasicApp", () => {
multiSensitivity: true
};
const wrapper = getWrapper(jest.fn(), bothConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(4);
expect(rightTabLinks.at(0)!.text()).toBe("Help");
expect(rightTabLinks.at(1)!.text()).toBe("Run");
expect(rightTabLinks.at(2)!.text()).toBe("Sensitivity");
expect(rightTabLinks.at(3)!.text()).toBe("Multi-sensitivity");
expectRightWodinTabs(wrapper, ["Help", "Run", "Sensitivity", "Multi-sensitivity"]);
});
});
54 changes: 15 additions & 39 deletions app/static/tests/unit/components/fit/fitApp.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Mock the import of third party packages to prevent errors
import {expectLeftWodinTabs, expectRightWodinTabs} from "../../../testUtils";

jest.mock("plotly.js-basic-dist-min", () => ({}));
jest.mock("plotly.js-basic-dist-min", () => ({}));
jest.mock("../../../../src/app/components/help/MarkdownItImport.ts", () => {
Expand Down Expand Up @@ -105,22 +107,13 @@ describe("FitApp", () => {
const wodinApp = wrapper.findComponent(WodinApp);

const wodinPanels = wodinApp.findComponent(WodinPanels);
const leftPanel = wodinPanels.find(".wodin-left");
const leftTabs = leftPanel.find("#left-tabs");
const leftTabLinks = leftTabs.findAll("ul li a");
expect(leftTabLinks.length).toBe(3);
expect(leftTabLinks.at(0)!.text()).toBe("Data");
expect(leftTabLinks.at(1)!.text()).toBe("Code");
expect(leftTabLinks.at(2)!.text()).toBe("Options");
expectLeftWodinTabs(wrapper,["Data", "Code", "Options"]);

const leftTabs = wodinPanels.find(".wodin-left #left-tabs");
expect(leftTabs.findComponent(DataTab).exists()).toBe(true);

const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(3);
expect(rightTabLinks.at(0)!.text()).toBe("Run");
expect(rightTabLinks.at(1)!.text()).toBe("Fit");
expect(rightTabLinks.at(2)!.text()).toBe("Sensitivity");
expectRightWodinTabs(wrapper, ["Run", "Fit", "Sensitivity"]);
const rightTabs = wodinPanels.find(".wodin-right #right-tabs");
expect(rightTabs.findComponent(RunTab).exists()).toBe(true);
});

Expand Down Expand Up @@ -183,13 +176,9 @@ describe("FitApp", () => {
const wrapper = getWrapper(jest.fn(), helpConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(4);
expect(rightTabLinks.at(0)!.text()).toBe("Help");
expect(rightTabLinks.at(1)!.text()).toBe("Run");
expect(rightTabLinks.at(2)!.text()).toBe("Fit");
expect(rightTabLinks.at(3)!.text()).toBe("Sensitivity");

expectRightWodinTabs(wrapper,["Help", "Run", "Fit", "Sensitivity"]);
const rightTabs = wodinPanels.find(".wodin-right #right-tabs");
expect(rightTabs.findComponent(HelpTab).exists()).toBe(true);
});

Expand All @@ -199,15 +188,11 @@ describe("FitApp", () => {
};
const wrapper = getWrapper(jest.fn(), multiSensConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(4);
expect(rightTabLinks.at(0)!.text()).toBe("Run");
expect(rightTabLinks.at(1)!.text()).toBe("Fit");
expect(rightTabLinks.at(2)!.text()).toBe("Sensitivity");
expect(rightTabLinks.at(3)!.text()).toBe("Multi-sensitivity");

expectRightWodinTabs(wrapper, ["Run", "Fit", "Sensitivity", "Multi-sensitivity"]);
// Change to Options tab
const rightTabs = wodinPanels.find(".wodin-right #right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
await rightTabLinks.at(3)!.trigger("click");
expect(rightTabs.findComponent(MultiSensitivityTab).exists()).toBe(true);
});
Expand All @@ -221,15 +206,6 @@ describe("FitApp", () => {
multiSensitivity: true
};
const wrapper = getWrapper(jest.fn(), bothConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(5);
expect(rightTabLinks.at(0)!.text()).toBe("Help");
expect(rightTabLinks.at(1)!.text()).toBe("Run");
expect(rightTabLinks.at(2)!.text()).toBe("Fit");
expect(rightTabLinks.at(3)!.text()).toBe("Sensitivity");
expect(rightTabLinks.at(4)!.text()).toBe("Multi-sensitivity");
expectRightWodinTabs(wrapper, ["Help", "Run", "Fit", "Sensitivity", "Multi-sensitivity"]);
});
});
51 changes: 16 additions & 35 deletions app/static/tests/unit/components/stochastic/stochasticApp.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Mock the import of third party packages to prevent errors
import {expectLeftWodinTabs, expectRightWodinTabs} from "../../../testUtils";

jest.mock("../../../../src/app/components/help/MarkdownItImport.ts", () => {
return function () {
return {
Expand Down Expand Up @@ -87,20 +89,14 @@ describe("StochasticApp", () => {
const wodinApp = wrapper.findComponent(WodinApp);

const wodinPanels = wodinApp.findComponent(WodinPanels);
const leftPanel = wodinPanels.find(".wodin-left");
const leftTabs = leftPanel.find("#left-tabs");
const leftTabLinks = leftTabs.findAll("ul li a");
expect(leftTabLinks.length).toBe(2);
expect(leftTabLinks.at(0)!.text()).toBe("Code");
expect(leftTabLinks.at(1)!.text()).toBe("Options");

expectLeftWodinTabs(wrapper,["Code", "Options"]);

const leftTabs = wodinPanels.find(".wodin-left #left-tabs");
expect(leftTabs.findComponent(CodeTab).exists()).toBe(true);

const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(2);
expect(rightTabLinks.at(0)!.text()).toBe("Run");
expect(rightTabLinks.at(1)!.text()).toBe("Sensitivity");
expectRightWodinTabs(wrapper, ["Run", "Sensitivity"]);
const rightTabs = wodinPanels.find(".wodin-right #right-tabs");
expect(rightTabs.findComponent(RunTab).exists()).toBe(true);
});

Expand Down Expand Up @@ -140,13 +136,9 @@ describe("StochasticApp", () => {
};
const wrapper = getWrapper(helpConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(3);
expect(rightTabLinks.at(0)!.text()).toBe("Help");
expect(rightTabLinks.at(1)!.text()).toBe("Run");
expect(rightTabLinks.at(2)!.text()).toBe("Sensitivity");
expectRightWodinTabs(wrapper, ["Help", "Run", "Sensitivity"]);

const rightTabs = wodinPanels.find(".wodin-right #right-tabs");
expect(rightTabs.findComponent(HelpTab).exists()).toBe(true);
});

Expand All @@ -156,14 +148,11 @@ describe("StochasticApp", () => {
};
const wrapper = getWrapper(multiSensConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(3);
expect(rightTabLinks.at(0)!.text()).toBe("Run");
expect(rightTabLinks.at(1)!.text()).toBe("Sensitivity");
expect(rightTabLinks.at(2)!.text()).toBe("Multi-sensitivity");

expectRightWodinTabs(wrapper, ["Run", "Sensitivity", "Multi-sensitivity"]);
// Change to Options tab
const rightTabs = wodinPanels.find(".wodin-right #right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
await rightTabLinks.at(2)!.trigger("click");
expect(rightTabs.findComponent(MultiSensitivityTab).exists()).toBe(true);
});
Expand All @@ -177,14 +166,6 @@ describe("StochasticApp", () => {
multiSensitivity: true
};
const wrapper = getWrapper(bothConfig);
const wodinPanels = wrapper.findComponent(WodinPanels);
const rightPanel = wodinPanels.find(".wodin-right");
const rightTabs = rightPanel.find("#right-tabs");
const rightTabLinks = rightTabs.findAll("ul li a");
expect(rightTabLinks.length).toBe(4);
expect(rightTabLinks.at(0)!.text()).toBe("Help");
expect(rightTabLinks.at(1)!.text()).toBe("Run");
expect(rightTabLinks.at(2)!.text()).toBe("Sensitivity");
expect(rightTabLinks.at(3)!.text()).toBe("Multi-sensitivity");
expectRightWodinTabs(wrapper,["Help", "Run", "Sensitivity", "Multi-sensitivity"]);
});
});

0 comments on commit 3778d0d

Please sign in to comment.