1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
import { shallowMount, mount } from '@vue/test-utils';
import RunnerStats from '~/ci/runner/components/stat/runner_stats.vue';
import RunnerSingleStat from '~/ci/runner/components/stat/runner_single_stat.vue';
import {
I18N_STATUS_ONLINE,
I18N_STATUS_OFFLINE,
I18N_STATUS_STALE,
INSTANCE_TYPE,
STATUS_ONLINE,
STATUS_OFFLINE,
STATUS_STALE,
} from '~/ci/runner/constants';
describe('RunnerStats', () => {
let wrapper;
const findSingleStats = () => wrapper.findAllComponents(RunnerSingleStat);
const RunnerCountStub = {
props: ['variables'],
render() {
// return a count for each status
const mockCounts = {
undefined: 6, // no status returns "all"
[STATUS_ONLINE]: 3,
[STATUS_OFFLINE]: 2,
[STATUS_STALE]: 1,
};
return this.$scopedSlots.default({
count: mockCounts[this.variables.status],
});
},
};
const createComponent = ({ props = {}, mountFn = shallowMount, ...options } = {}) => {
wrapper = mountFn(RunnerStats, {
propsData: {
scope: INSTANCE_TYPE,
variables: {},
...props,
},
stubs: {
RunnerCount: RunnerCountStub,
},
...options,
});
};
afterEach(() => {
wrapper.destroy();
});
it('Displays all the stats', () => {
createComponent({
mountFn: mount,
});
const text = wrapper.text();
expect(text).toContain(`${I18N_STATUS_ONLINE} 3`);
expect(text).toContain(`${I18N_STATUS_OFFLINE} 2`);
expect(text).toContain(`${I18N_STATUS_STALE} 1`);
});
it('Skips query for other stats', () => {
createComponent({
props: {
variables: { status: STATUS_ONLINE },
},
});
expect(findSingleStats().at(0).props('skip')).toBe(false);
expect(findSingleStats().at(1).props('skip')).toBe(true);
expect(findSingleStats().at(2).props('skip')).toBe(true);
});
it('Displays all counts for filtered searches', () => {
const mockVariables = { paused: true };
createComponent({ props: { variables: mockVariables } });
findSingleStats().wrappers.forEach((stat) => {
expect(stat.props('variables')).toMatchObject(mockVariables);
});
});
it('Does not display counts when total is 0', () => {
createComponent({
mountFn: mount,
stubs: {
RunnerCount: {
render() {
return this.$scopedSlots.default({
count: 0,
});
},
},
},
});
expect(wrapper.html()).toBe('');
});
});
|