Skip to content

Commit ddfd028

Browse files
committed
Fix store, tree, workflow, unit tests (pending GScan)
1 parent 6349f33 commit ddfd028

File tree

3 files changed

+161
-25
lines changed

3 files changed

+161
-25
lines changed

tests/unit/components/cylc/gscan/gscan.vue.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ describe('GScan component', () => {
230230
}
231231
]
232232
tests.forEach(test => {
233-
store.commit('workflows/SET_WORKFLOWS', test.workflows)
234-
const wrapper = mountFunction()
233+
store.dispatch('workflows/SET_WORKFLOWS', test.workflows)
234+
const wrapper = mountFunction({})
235235
// We will have all TreeItem elements, workflow-name-part's, and workflow's.
236236
const workflowsElements = wrapper.findAllComponents(TreeItem)
237237
.filter((treeItem) => {

tests/unit/store/tree.spec.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
import { expect } from 'chai'
19+
import Vue from 'vue'
20+
import Vuex from 'vuex'
21+
import storeOptions from '@/store/options'
22+
23+
Vue.use(Vuex)
24+
25+
/**
26+
* Tests for the store/tree module.
27+
*/
28+
describe('tree', () => {
29+
const store = new Vuex.Store(storeOptions)
30+
if (!global.localStorage) {
31+
global.localStorage = {}
32+
}
33+
const resetState = () => {
34+
store.state.tree.lookup = {}
35+
store.state.tree.workflow = {
36+
tree: {},
37+
lookup: {}
38+
}
39+
}
40+
beforeEach(resetState)
41+
afterEach(resetState)
42+
describe('Actions', () => {
43+
it('should apply tree deltas', () => {
44+
const data = {
45+
deltas: {
46+
added: {
47+
workflow: {
48+
id: 'cylc|test',
49+
status: 'test'
50+
}
51+
}
52+
}
53+
}
54+
store.dispatch('tree/applyWorkflowDeltas', data)
55+
store.dispatch('tree/applyTreeDeltas', data)
56+
expect(store.state.tree.workflow.tree.id).to.equal('cylc|test')
57+
})
58+
it('should clear lookup', () => {
59+
const workflow = {
60+
tree: [
61+
{
62+
test: 1
63+
}
64+
],
65+
lookup: {
66+
test: 1
67+
}
68+
}
69+
store.commit('tree/SET_LOOKUP', workflow)
70+
expect(store.state.tree.lookup).to.deep.equal(workflow)
71+
store.dispatch('tree/clearWorkflow')
72+
expect(store.state.tree.lookup).to.not.deep.equal(workflow)
73+
})
74+
it('should clear workflow (tree)', () => {
75+
const workflow = {
76+
tree: {
77+
test: 1
78+
},
79+
lookup: {
80+
test: 1
81+
}
82+
}
83+
store.commit('tree/SET_WORKFLOW', workflow)
84+
expect(store.state.tree.workflow.tree.test).to.deep.equal(workflow.tree.test)
85+
store.dispatch('tree/clearTree')
86+
expect(store.state.tree.workflow.tree).to.not.deep.equal(workflow.tree)
87+
})
88+
})
89+
})

tests/unit/store/workflows.spec.js

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('workflows', () => {
3333
const resetState = () => {
3434
store.state.workflows.lookup = {}
3535
store.state.workflows.workflow = {
36-
tree: {},
36+
tree: [],
3737
lookup: {}
3838
}
3939
store.state.workflows.workflows = []
@@ -44,7 +44,7 @@ describe('workflows', () => {
4444
describe('State', () => {
4545
it('should start with empty lookup, empty workflow, no workflows, and no workflow name', () => {
4646
expect(Object.keys(store.state.workflows.lookup).length).to.deep.equal(0)
47-
expect(store.state.workflows.workflow).to.deep.equal({ tree: {}, lookup: {} })
47+
expect(store.state.workflows.workflow).to.deep.equal({ tree: [], lookup: {} })
4848
expect(store.state.workflows.workflows.length).to.equal(0)
4949
expect(store.state.workflows.workflowName).to.equal(null)
5050
})
@@ -79,38 +79,85 @@ describe('workflows', () => {
7979
store.commit('workflows/SET_WORKFLOW_NAME', workflowName)
8080
expect(store.state.workflows.workflowName).to.equal(workflowName)
8181
})
82-
it('should set workflow', () => {
82+
it('should set gscan', () => {
8383
const workflow = {
84-
tree: {
85-
test: 1
86-
},
84+
tree: [
85+
{
86+
test: 1
87+
}
88+
],
8789
lookup: {
8890
test: 1
8991
}
9092
}
91-
store.commit('workflows/SET_WORKFLOW', workflow)
92-
expect(store.state.workflows.workflow).to.deep.equal(workflow)
93-
})
94-
it('should set lookup', () => {
95-
const lookup = {
96-
test: 1
97-
}
98-
store.commit('workflows/SET_LOOKUP', lookup)
99-
expect(store.state.workflows.lookup).to.deep.equal(lookup)
93+
store.commit('workflows/SET_GSCAN', workflow)
94+
expect(store.state.workflows.gscan).to.deep.equal(workflow)
10095
})
101-
it('should clear workflow', () => {
96+
it('should clear gscan', () => {
10297
const workflow = {
103-
tree: {
104-
test: 1
105-
},
98+
tree: [
99+
{
100+
test: 1
101+
}
102+
],
106103
lookup: {
107104
test: 1
108105
}
109106
}
110-
store.commit('workflows/SET_WORKFLOW', workflow)
111-
expect(store.state.workflows.workflow).to.deep.equal(workflow)
112-
store.commit('workflows/CLEAR_WORKFLOW', workflow)
113-
expect(store.state.workflows.workflow).to.not.deep.equal(workflow)
107+
store.commit('workflows/SET_GSCAN', workflow)
108+
expect(store.state.workflows.gscan.tree.length).to.equal(1)
109+
expect(Object.keys(store.state.workflows.gscan.lookup).length).to.equal(1)
110+
store.commit('workflows/CLEAR_GSCAN')
111+
expect(store.state.workflows.gscan.tree.length).to.equal(0)
112+
expect(Object.keys(store.state.workflows.gscan.lookup).length).to.equal(0)
113+
})
114+
})
115+
describe('Actions', () => {
116+
it('should apply workflows deltas', () => {
117+
const data = {
118+
deltas: {
119+
added: {
120+
workflow: {
121+
id: 'cylc|test',
122+
status: 'test'
123+
}
124+
}
125+
}
126+
}
127+
store.dispatch('workflows/applyWorkflowsDeltas', data)
128+
store.dispatch('workflows/applyGScanDeltas', data)
129+
expect(store.state.workflows.workflows['cylc|test']).to.not.equal(undefined)
130+
})
131+
it('should clear workflows', () => {
132+
const workflows = {
133+
'cylc|cylc': {
134+
id: 'cylc|cylc',
135+
name: 'cylc'
136+
}
137+
}
138+
store.commit('workflows/SET_WORKFLOWS', workflows)
139+
expect(store.state.workflows.workflows).to.deep.equal(workflows)
140+
store.dispatch('workflows/clearWorkflows')
141+
expect(store.state.workflows.workflows).to.not.deep.equal(workflows)
142+
})
143+
it('should set workflow name', () => {
144+
const workflowName = 'cylc'
145+
store.dispatch('workflows/setWorkflowName', workflowName)
146+
expect(store.state.workflows.workflowName).to.equal(workflowName)
147+
})
148+
it('should apply workflow deltas', () => {
149+
const data = {
150+
deltas: {
151+
added: {
152+
workflow: {
153+
id: 'cylc|test',
154+
status: 'test'
155+
}
156+
}
157+
}
158+
}
159+
store.dispatch('workflows/applyGScanDeltas', data)
160+
expect(store.state.workflows.gscan.lookup['cylc|test']).to.not.equal(undefined)
114161
})
115162
})
116163
})

0 commit comments

Comments
 (0)