-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1db8c55
commit b9df2c3
Showing
6 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/static/tests/unit/components/graphConfig/graphConfigs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import Vuex from "vuex"; | ||
import {BasicState} from "../../../../src/app/store/basic/state"; | ||
import {mockBasicState} from "../../../mocks"; | ||
import {GraphsAction} from "../../../../src/app/store/graphs/actions"; | ||
import {shallowMount} from "@vue/test-utils"; | ||
import GraphConfigs from "../../../../src/app/components/graphConfig/GraphConfigs.vue"; | ||
import GraphConfig from "../../../../src/app/components/graphConfig/GraphConfig.vue"; | ||
import HiddenVariables from "../../../../src/app/components/graphConfig/HiddenVariables.vue"; | ||
import {nextTick} from "vue"; | ||
|
||
describe("GraphConfigs", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const mockNewGraph = jest.fn(); | ||
const namespaced = true; | ||
const getWrapper = () => { | ||
const store = new Vuex.Store<BasicState>({ | ||
state: mockBasicState({ | ||
configured: true | ||
}), | ||
modules: { | ||
graphs: { | ||
namespaced, | ||
state: { | ||
config: [ | ||
{ selectedVariables: ["S"], unselectedVariables: ["I", "R"] }, | ||
{ selectedVariables: ["I"], unselectedVariables: ["S", "R"] } | ||
] | ||
}, | ||
actions: { | ||
[GraphsAction.NewGraph]: mockNewGraph | ||
} | ||
} | ||
} | ||
}); | ||
return shallowMount(GraphConfigs, { | ||
global: { | ||
plugins: [store] | ||
} | ||
}); | ||
}; | ||
|
||
it("renders as expected", () => { | ||
const wrapper = getWrapper(); | ||
expect(wrapper.find("#graph-configs-instruction").text()).toContain("Drag variables to 'Hidden variables' to remove"); | ||
const graphConfigComps = wrapper.findAllComponents(GraphConfig); | ||
expect(graphConfigComps.length).toBe(2); | ||
expect(graphConfigComps.at(0)!.props("graphIndex")).toBe(0); | ||
expect(graphConfigComps.at(0)!.props("dragging")).toBe(false) | ||
expect(graphConfigComps.at(1)!.props("graphIndex")).toBe(1); | ||
expect(graphConfigComps.at(1)!.props("dragging")).toBe(false); | ||
expect(wrapper.find("button").text()).toBe("Add Graph"); | ||
expect(wrapper.findComponent(HiddenVariables).props("dragging")).toBe(false); | ||
}); | ||
|
||
it("sets dragging on emit from GraphConfig", async () => { | ||
const wrapper = getWrapper(); | ||
const graphConfig = wrapper.findAllComponents(GraphConfig).at(0)!; | ||
graphConfig.vm.$emit("setDragging", true); | ||
await nextTick(); | ||
expect(graphConfig.props("dragging")).toBe(true); | ||
expect(wrapper.findComponent(HiddenVariables).props("dragging")).toBe(true); | ||
}); | ||
|
||
it("sets dragging on emit from HiddenVariables", async () => { | ||
const wrapper = getWrapper(); | ||
const hiddenVars = wrapper.findComponent(HiddenVariables); | ||
hiddenVars.vm.$emit("setDragging", true); | ||
await nextTick(); | ||
expect(hiddenVars.props("dragging")).toBe(true); | ||
expect(wrapper.findAllComponents(GraphConfig).at(0)!.props("dragging")).toBe(true); | ||
}); | ||
|
||
it("Add Graph click invokes action", async () => { | ||
const wrapper = getWrapper(); | ||
expect(mockNewGraph).toHaveBeenCalledTimes(0); | ||
await wrapper.find("button").trigger("click"); | ||
expect(mockNewGraph).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}); |
79 changes: 79 additions & 0 deletions
79
app/static/tests/unit/components/graphConfig/hiddenVariables.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import Vuex from "vuex"; | ||
import {BasicState} from "../../../../src/app/store/basic/state"; | ||
import {GraphsAction} from "../../../../src/app/store/graphs/actions"; | ||
import {shallowMount} from "@vue/test-utils"; | ||
import HiddenVariables from "../../../../src/app/components/graphConfig/HiddenVariables.vue"; | ||
import {GraphsGetter} from "../../../../src/app/store/graphs/getters"; | ||
|
||
describe("HiddenVariables", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const mockUpdateSelectedVariables = jest.fn(); | ||
|
||
const getWrapper = () => { | ||
const store = new Vuex.Store<BasicState>({ | ||
state: {} as any, | ||
modules: { | ||
graphs: { | ||
namespaced: true, | ||
state: { | ||
config: [ | ||
{ | ||
selectedVariables: ["S"] | ||
} | ||
] | ||
}, | ||
actions: { | ||
[GraphsAction.UpdateSelectedVariables]: mockUpdateSelectedVariables | ||
}, | ||
getters: { | ||
[GraphsGetter.hiddenVariables]: ["I", "R"] | ||
} as any | ||
}, | ||
model: { | ||
namespaced: true, | ||
state: { | ||
paletteModel: { | ||
S: "#ff0000", | ||
I: "#00ff00", | ||
R: "#0000ff" | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
return shallowMount(HiddenVariables, { | ||
props: { | ||
dragging: false | ||
}, | ||
global: { | ||
plugins: [store] | ||
} | ||
}); | ||
}; | ||
|
||
|
||
it("renders as expected", () => { | ||
const wrapper = getWrapper(); | ||
}); | ||
|
||
/* | ||
it("starting drag sets values in event and emits setDragging"); | ||
it("ending drag emits setDragging"); | ||
it("onDrop removes variable from source"); | ||
it("shows drop zone when dragging", () => { | ||
const wrapper = getWrapper({dragging: true}); | ||
expect(wrapper.find(".drop-zone").classes()).toStrictEqual(["drop-zone", "drop-zone-active"]); | ||
}); | ||
it("shows instruction if no hidden variables", () =>{ | ||
const wrapper = getWrapper({}, []); | ||
expect(wrapper.find(".drop-zone-instruction").text()).toBe("Drag variables here to select them for this graph."); | ||
});*/ | ||
}); |