Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Aug 1, 2024
1 parent 5209f68 commit d9e3b99
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/static/src/app/components/run/RunTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</run-plot>
</template>
<div v-if="sumOfSquares">
<span>Sum of squares: {{ sumOfSquares }}</span>
<span id="squares">Sum of squares: {{ sumOfSquares }}</span>
</div>
<error-info :error="error"></error-info>
<div>
Expand Down
2 changes: 0 additions & 2 deletions app/static/src/app/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ export function allFitDataToPlotly(
const palette = paletteData(Object.keys(linkedVariables));

return Object.keys(linkedVariables).map((name: string) => {
// Display column data if it is not linked OR if its linked variable is selected - render the series, but as
// transparent so that all graph x axes match
let color = palette[name];
const variable = linkedVariables[name];
if (variable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ describe("GraphConfig", () => {
const dropPanel = wrapper.find(".graph-config-panel");
await dropPanel.trigger("drop", { dataTransfer });
expect(mockUpdateSelectedVariables.mock.calls.length).toBe(2);
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({ graphIndex: 1, selectedVariables: ["J"] });
expect(mockUpdateSelectedVariables.mock.calls[1][1]).toStrictEqual({
expect(mockUpdateSelectedVariables.mock.calls[0][1]).toStrictEqual({
graphIndex: 0,
selectedVariables: ["S", "R", "I"]
});
expect(mockUpdateSelectedVariables.mock.calls[1][1]).toStrictEqual({ graphIndex: 1, selectedVariables: ["J"] });
});

it("onDrop does not attempt to remove variable if source was hidden variables", async () => {
Expand Down
45 changes: 44 additions & 1 deletion app/static/tests/unit/components/run/runTab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import Vuex from "vuex";
import { shallowMount } from "@vue/test-utils";
import { nextTick } from "vue";
import { BasicState } from "../../../../src/app/store/basic/state";
import { mockBasicState, mockGraphsState, mockModelState, mockRunState, mockStochasticState } from "../../../mocks";
import {
mockBasicState,
mockFitState,
mockGraphsState, mockModelFitState,
mockModelState,
mockRunState,
mockStochasticState
} from "../../../mocks";
import { ModelState } from "../../../../src/app/store/model/state";
import { RunState } from "../../../../src/app/store/run/state";
import RunTab from "../../../../src/app/components/run/RunTab.vue";
Expand All @@ -26,6 +33,7 @@ import { AppType } from "../../../../src/app/store/appState/state";
import { RunMutation } from "../../../../src/app/store/run/mutations";
import { RunAction } from "../../../../src/app/store/run/actions";
import { getters as graphGetters } from "../../../../src/app/store/graphs/getters";
import {FitState} from "../../../../src/app/store/fit/state";

describe("RunTab", () => {
const defaultModelState = {
Expand Down Expand Up @@ -144,6 +152,35 @@ describe("RunTab", () => {
});
};

const getFitWrapper = () => {
const store = new Vuex.Store<FitState>({
state: mockFitState(),
modules: {
graphs: {
namespaced: true,
state: mockGraphsState({
config: [
{ id: "123", selectedVariables: ["S"], unselectedVariables: [] },
{ id: "456", selectedVariables: [], unselectedVariables: [] }
]
} as any),
getters: graphGetters
},
modelFit: {
namespaced: true,
state: mockModelFitState({
sumOfSquares: 21.2
})
}
}
});
return shallowMount(RunTab, {
global: {
plugins: [store]
}
});
};

it("renders as expected when can run model", () => {
const runState = { ...defaultRunState, userDownloadFileName: "test.xlsx" };
const wrapper = getWrapper(defaultModelState, runState);
Expand Down Expand Up @@ -184,6 +221,12 @@ describe("RunTab", () => {
expect(wrapper.findComponent(RunStochasticPlot).exists()).toBe(false);
});

it("renders sumOfSquares for Fit app", () => {
const wrapper = getFitWrapper();
expect(wrapper.findAll("#squares").length).toBe(1);
expect(wrapper.find("#squares").text()).toBe("Sum of squares: 21.2");
});

it("propagates x axis changes to all run plots", async () => {
const wrapper = getWrapper();
const plots = wrapper.findAllComponents(RunPlot);
Expand Down
27 changes: 23 additions & 4 deletions app/static/tests/unit/plot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("allFitDataToPlotly", () => {
};

it("creates unlinked data", () => {
const res = allFitDataToPlotly(allFitData, palette, 0, 4);
const res = allFitDataToPlotly(allFitData, palette, 0, 4, ["B"]);
expect(res).toStrictEqual([
{
marker: { color: "#1c0a00" }, // first data colour
Expand All @@ -136,12 +136,12 @@ describe("allFitDataToPlotly", () => {
});

it("returns empty set if data missing", () => {
const res = allFitDataToPlotly(null, palette, 0, 4);
const res = allFitDataToPlotly(null, palette, 0, 4, ["B"]);
expect(res).toStrictEqual([]);
});

it("filters data by time", () => {
const res = allFitDataToPlotly(allFitData, palette, 1, 3);
const res = allFitDataToPlotly(allFitData, palette, 1, 3, ["B"]);
expect(res).toStrictEqual([
{
marker: { color: "#1c0a00" },
Expand All @@ -168,7 +168,8 @@ describe("allFitDataToPlotly", () => {
linkedVariables: { a: null, b: "B" },
timeVariable: "t"
};
const res = allFitDataToPlotly(allFitDataLinked, palette, 0, 4);
const selectedVariables = ["A", "B"];
const res = allFitDataToPlotly(allFitDataLinked, palette, 0, 4, selectedVariables);
expect(res).toStrictEqual([
{
marker: { color: "#1c0a00" }, // first data colour
Expand All @@ -188,6 +189,24 @@ describe("allFitDataToPlotly", () => {
}
]);
});

it("adds transparent data for unselected variable", () => {
const allFitDataLinked = {
data,
linkedVariables: { a: null, b: "B" },
timeVariable: "t"
};
const selectedVariables = ["A"];
const res = allFitDataToPlotly(allFitDataLinked, palette, 0, 4, selectedVariables);
expect(res[1]).toStrictEqual({
marker: { color: "transparent" }, // Model colour
mode: "markers",
name: "b",
type: "scatter",
x: [0, 1, 2, 3, 4],
y: [2, 4, 6, 8, 10]
});
});
});

describe("fitDataToPlotly", () => {
Expand Down

0 comments on commit d9e3b99

Please sign in to comment.