Skip to content

Commit 5f8b707

Browse files
committed
Fix table view showing wrong latest job
1 parent e5316e5 commit 5f8b707

File tree

2 files changed

+106
-12
lines changed

2 files changed

+106
-12
lines changed

src/views/Table.vue

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,13 @@ export default {
7373
},
7474
tasks () {
7575
const ret = []
76-
let latestJob
77-
let previousJob
7876
for (const workflow of this.workflows) {
7977
for (const cycle of workflow.children) {
8078
for (const task of cycle.children) {
81-
latestJob = null
82-
previousJob = null
83-
if (task.children.length) {
84-
latestJob = task.children.slice(-1)[0]
85-
if (task.children.length > 1) {
86-
previousJob = task.children.slice(-2)[0]
87-
}
88-
}
8979
ret.push({
9080
task,
91-
latestJob,
92-
previousJob
81+
latestJob: task.children[0],
82+
previousJob: task.children[1],
9383
})
9484
}
9585
}

tests/unit/views/table.vue.spec.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 { mount } from '@vue/test-utils'
19+
import { createStore } from 'vuex'
20+
import sinon from 'sinon'
21+
import storeOptions from '@/store/options'
22+
import Table from '@/views/Table.vue'
23+
import WorkflowService from '@/services/workflow.service'
24+
import User from '@/model/User.model'
25+
26+
chai.config.truncateThreshold = 0
27+
28+
const workflows = [
29+
{
30+
id: '~user/one',
31+
children: [
32+
{
33+
id: '~user/one//1',
34+
children: [
35+
{
36+
id: '~user/one//1/eventually_succeeded',
37+
children: [
38+
{
39+
id: '~user/one//1/eventually_succeeded/3',
40+
children: [],
41+
},
42+
{
43+
id: '~user/one//1/eventually_succeeded/2',
44+
children: [],
45+
},
46+
{
47+
id: '~user/one//1/eventually_succeeded/1',
48+
children: [],
49+
},
50+
],
51+
},
52+
{
53+
id: '~user/one//1/failed',
54+
children: [
55+
{
56+
id: '~user/one//1/failed/1',
57+
children: [],
58+
},
59+
],
60+
},
61+
]
62+
}
63+
]
64+
},
65+
]
66+
67+
describe('Table view', () => {
68+
let store, $workflowService
69+
beforeEach(() => {
70+
store = createStore(storeOptions)
71+
const user = new User('cylc', [], new Date(), true, 'localhost', 'owner')
72+
store.commit('user/SET_USER', user)
73+
$workflowService = sinon.createStubInstance(WorkflowService)
74+
})
75+
76+
it('computes tasks', async () => {
77+
const wrapper = mount(Table, {
78+
shallow: true,
79+
global: {
80+
plugins: [store],
81+
mocks: { $workflowService }
82+
},
83+
props: {
84+
workflowName: 'one',
85+
},
86+
data: () => ({
87+
// Override computed property
88+
workflows
89+
})
90+
})
91+
92+
expect(wrapper.vm.tasks).toMatchObject([
93+
{
94+
task: { id: '~user/one//1/eventually_succeeded' },
95+
latestJob: { id: '~user/one//1/eventually_succeeded/3' },
96+
previousJob: { id: '~user/one//1/eventually_succeeded/2' }
97+
},
98+
{
99+
task: { id: '~user/one//1/failed' },
100+
latestJob: { id: '~user/one//1/failed/1' },
101+
}
102+
])
103+
})
104+
})

0 commit comments

Comments
 (0)