Skip to content

Commit 25e9af5

Browse files
committed
Fix store, tree, workflow, unit tests (pending GScan)
1 parent a0d4f10 commit 25e9af5

File tree

6 files changed

+123
-72
lines changed

6 files changed

+123
-72
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/components/cylc/tree/deltas.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import sinon from 'sinon'
2020
import TaskState from '@/model/TaskState.model'
2121
import WorkflowState from '@/model/WorkflowState.model'
2222
import * as CylcTree from '@/components/cylc/tree/index'
23-
import applyWorkflowDeltas from '@/components/cylc/workflow/deltas'
23+
import applyWorkflowDeltas from '@/components/cylc/common/deltas'
2424
import applyTreeDeltas from '@/components/cylc/tree/deltas'
2525
import { createCyclePointNode, createFamilyProxyNode, createWorkflowNode } from '@/components/cylc/tree/nodes'
2626

@@ -148,7 +148,7 @@ describe('Deltas', () => {
148148
// let's force the tree to throw an error when handling the first data burst, simulating a runtime exception
149149
const result = applyTreeDeltas(deltasAdded, workflow, lookup, {})
150150
expect(result.errors.length).to.equal(1)
151-
expect(result.errors[0][0]).to.contain('error applying deltas')
151+
expect(result.errors[0][0]).to.contain('error applying tree deltas')
152152
})
153153
describe('Initial data burst', () => {
154154
it('Should create the CylcTree structure using the initial data burst', () => {

tests/unit/components/cylc/tree/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
getCyclePointId
2121
} from '@/components/cylc/tree/nodes'
2222
import handleTreeDeltas from '@/components/cylc/tree/deltas'
23-
import handleWorkflowDeltas from '@/components/cylc/workflow/deltas'
23+
import handleWorkflowDeltas from '@/components/cylc/common/deltas'
2424
import { expect } from 'chai'
2525
import { sampleWorkflow1 } from './tree.data'
2626
import * as CylcTree from '@/components/cylc/tree/index'

tests/unit/components/cylc/workflow/deltas.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { expect } from 'chai'
1919
import sinon from 'sinon'
2020
import Vue from 'vue'
21-
import applyWorkflowDeltas from '@/components/cylc/workflow/deltas'
21+
import applyWorkflowDeltas from '@/components/cylc/common/deltas'
2222
import WorkflowState from '@/model/WorkflowState.model'
2323

2424
const sandbox = sinon.createSandbox()

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: 28 additions & 66 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,37 @@ 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)
114113
})
115114
})
116115
describe('Actions', () => {
@@ -119,14 +118,15 @@ describe('workflows', () => {
119118
deltas: {
120119
added: {
121120
workflow: {
122-
id: 'test',
121+
id: 'cylc|test',
123122
status: 'test'
124123
}
125124
}
126125
}
127126
}
128127
store.dispatch('workflows/applyWorkflowsDeltas', data)
129-
expect(store.state.workflows.workflows.test).to.not.equal(undefined)
128+
store.dispatch('workflows/applyGScanDeltas', data)
129+
expect(store.state.workflows.workflows['cylc|test']).to.not.equal(undefined)
130130
})
131131
it('should clear workflows', () => {
132132
const workflows = {
@@ -150,52 +150,14 @@ describe('workflows', () => {
150150
deltas: {
151151
added: {
152152
workflow: {
153-
id: 'test',
153+
id: 'cylc|test',
154154
status: 'test'
155155
}
156156
}
157157
}
158158
}
159-
store.dispatch('workflows/applyWorkflowDeltas', data)
160-
expect(store.state.workflows.lookup.test).to.not.equal(undefined)
161-
})
162-
it('should apply tree deltas', () => {
163-
const data = {
164-
deltas: {
165-
added: {
166-
workflow: {
167-
id: 'test',
168-
status: 'test'
169-
}
170-
}
171-
}
172-
}
173-
store.dispatch('workflows/applyWorkflowDeltas', data)
174-
store.dispatch('workflows/applyTreeDeltas', data)
175-
expect(store.state.workflows.workflow.tree.id).to.equal('test')
176-
})
177-
it('should clear lookup', () => {
178-
const lookup = {
179-
test: 1
180-
}
181-
store.commit('workflows/SET_LOOKUP', lookup)
182-
expect(store.state.workflows.lookup).to.deep.equal(lookup)
183-
store.dispatch('workflows/clearWorkflow')
184-
expect(store.state.workflows.lookup).to.not.deep.equal(lookup)
185-
})
186-
it('should clear workflow (tree)', () => {
187-
const workflow = {
188-
tree: {
189-
test: 1
190-
},
191-
lookup: {
192-
test: 1
193-
}
194-
}
195-
store.commit('workflows/SET_WORKFLOW', workflow)
196-
expect(store.state.workflows.workflow).to.deep.equal(workflow)
197-
store.dispatch('workflows/clearTree')
198-
expect(store.state.workflows.workflow).to.not.deep.equal(workflow)
159+
store.dispatch('workflows/applyGScanDeltas', data)
160+
expect(store.state.workflows.gscan.lookup['cylc|test']).to.not.equal(undefined)
199161
})
200162
})
201163
})

0 commit comments

Comments
 (0)