/
groups_test.jsx
165 lines (148 loc) · 4.74 KB
/
groups_test.jsx
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* eslint-disable jest/prefer-to-have-length */
import React from 'react';
import cloneDeep from 'lodash/cloneDeep';
import { mount } from 'enzyme';
import { JobGroupComponent } from '../../../../ui/job-view/pushes/JobGroup';
import FilterModel from '../../../../ui/models/filter';
import mappedGroupFixture from '../../mock/mappedGroup';
import mappedGroupDupsFixture from '../../mock/mappedGroupDups';
describe('JobGroup component', () => {
let countGroup;
let dupGroup;
const repoName = 'mozilla-inbound';
const filterModel = new FilterModel();
const pushGroupState = 'collapsed';
beforeEach(() => {
countGroup = cloneDeep(mappedGroupFixture);
dupGroup = cloneDeep(mappedGroupDupsFixture);
});
/*
Tests Jobs view
*/
it('collapsed should show a job and count of 2', () => {
const jobGroup = mount(
<JobGroupComponent
repoName={repoName}
group={countGroup}
filterPlatformCb={() => {}}
filterModel={filterModel}
pushGroupState={pushGroupState}
platform={<span>windows</span>}
duplicateJobsVisible={false}
groupCountsExpanded={false}
/>,
);
expect(
jobGroup
.find('.job-group-count')
.first()
.text(),
).toEqual('2');
});
test('should show a job and count of 2 when expanded, then re-collapsed', () => {
const jobGroup = mount(
<JobGroupComponent
repoName={repoName}
group={countGroup}
filterPlatformCb={() => {}}
filterModel={filterModel}
pushGroupState={pushGroupState}
platform={<span>windows</span>}
duplicateJobsVisible={false}
groupCountsExpanded={false}
/>,
);
jobGroup.setState({ expanded: true });
jobGroup.setState({ expanded: false });
expect(
jobGroup
.find('.job-group-count')
.first()
.text(),
).toEqual('2');
});
test('should show jobs, not counts when expanded', () => {
const jobGroup = mount(
<JobGroupComponent
repoName={repoName}
group={countGroup}
filterPlatformCb={() => {}}
filterModel={filterModel}
pushGroupState={pushGroupState}
platform={<span>windows</span>}
duplicateJobsVisible={false}
groupCountsExpanded={false}
/>,
);
jobGroup.setState({ expanded: true });
expect(jobGroup.find('.job-group-count').length).toEqual(0);
expect(jobGroup.find('.job-btn').length).toEqual(3);
});
test('should show jobs, not counts when globally expanded', () => {
const groupCountsExpanded = true;
const jobGroup = mount(
<JobGroupComponent
repoName={repoName}
group={countGroup}
filterPlatformCb={() => {}}
filterModel={filterModel}
pushGroupState={pushGroupState}
platform={<span>windows</span>}
duplicateJobsVisible={false}
groupCountsExpanded={groupCountsExpanded}
/>,
);
expect(jobGroup.find('.job-btn').length).toEqual(3);
expect(jobGroup.find('.job-group-count').length).toEqual(0);
});
test('should hide duplicates by default', () => {
const jobGroup = mount(
<JobGroupComponent
repoName={repoName}
group={dupGroup}
filterPlatformCb={() => {}}
filterModel={filterModel}
pushGroupState={pushGroupState}
platform={<span>windows</span>}
duplicateJobsVisible={false}
groupCountsExpanded={false}
/>,
);
expect(jobGroup.find('.job-group-count').length).toEqual(1);
expect(jobGroup.find('.job-btn').length).toEqual(1);
});
test('should show 2 duplicates when set to show duplicates', () => {
const duplicateJobsVisible = true;
const jobGroup = mount(
<JobGroupComponent
repoName={repoName}
group={dupGroup}
filterPlatformCb={() => {}}
filterModel={filterModel}
pushGroupState={pushGroupState}
platform={<span>windows</span>}
duplicateJobsVisible={duplicateJobsVisible}
groupCountsExpanded={false}
/>,
);
expect(jobGroup.find('.job-group-count').length).toEqual(1);
expect(jobGroup.find('.job-btn').length).toEqual(2);
});
test('should show 2 duplicates when globally set to show duplicates', () => {
const duplicateJobsVisible = true;
const jobGroup = mount(
<JobGroupComponent
repoName={repoName}
group={dupGroup}
filterPlatformCb={() => {}}
filterModel={filterModel}
pushGroupState={pushGroupState}
platform={<span>windows</span>}
duplicateJobsVisible={duplicateJobsVisible}
groupCountsExpanded={false}
/>,
);
expect(jobGroup.find('.job-group-count').length).toEqual(1);
expect(jobGroup.find('.job-btn').length).toEqual(2);
});
});