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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
import { mount } from '@vue/test-utils';
import EnvironmentsBlock from '~/jobs/components/job/environments_block.vue';
const TEST_CLUSTER_NAME = 'test_cluster';
const TEST_CLUSTER_PATH = 'path/to/test_cluster';
const TEST_KUBERNETES_NAMESPACE = 'this-is-a-kubernetes-namespace';
describe('Environments block', () => {
let wrapper;
const status = {
group: 'success',
icon: 'status_success',
label: 'passed',
text: 'passed',
tooltip: 'passed',
};
const environment = {
environment_path: '/environment',
name: 'environment',
};
const lastDeployment = { iid: 'deployment', deployable: { build_path: 'bar' } };
const createEnvironmentWithLastDeployment = () => ({
...environment,
last_deployment: { ...lastDeployment },
});
const createDeploymentWithCluster = () => ({ name: TEST_CLUSTER_NAME, path: TEST_CLUSTER_PATH });
const createDeploymentWithClusterAndKubernetesNamespace = () => ({
name: TEST_CLUSTER_NAME,
path: TEST_CLUSTER_PATH,
kubernetes_namespace: TEST_KUBERNETES_NAMESPACE,
});
const createComponent = (deploymentStatus = {}, deploymentCluster = {}) => {
wrapper = mount(EnvironmentsBlock, {
propsData: {
deploymentStatus,
deploymentCluster,
iconStatus: status,
},
});
};
const findText = () => wrapper.findComponent(EnvironmentsBlock).text();
const findJobDeploymentLink = () => wrapper.find('[data-testid="job-deployment-link"]');
const findEnvironmentLink = () => wrapper.find('[data-testid="job-environment-link"]');
const findClusterLink = () => wrapper.find('[data-testid="job-cluster-link"]');
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('with last deployment', () => {
it('renders info for most recent deployment', () => {
createComponent({
status: 'last',
environment,
});
expect(findText()).toBe('This job is deployed to environment.');
});
describe('when there is a cluster', () => {
it('renders info with cluster', () => {
createComponent(
{
status: 'last',
environment: createEnvironmentWithLastDeployment(),
},
createDeploymentWithCluster(),
);
expect(findText()).toBe(
`This job is deployed to environment using cluster ${TEST_CLUSTER_NAME}.`,
);
});
describe('when there is a kubernetes namespace', () => {
it('renders info with cluster', () => {
createComponent(
{
status: 'last',
environment: createEnvironmentWithLastDeployment(),
},
createDeploymentWithClusterAndKubernetesNamespace(),
);
expect(findText()).toBe(
`This job is deployed to environment using cluster ${TEST_CLUSTER_NAME} and namespace ${TEST_KUBERNETES_NAMESPACE}.`,
);
});
});
});
});
describe('with out of date deployment', () => {
describe('with last deployment', () => {
it('renders info for out date and most recent', () => {
createComponent({
status: 'out_of_date',
environment: createEnvironmentWithLastDeployment(),
});
expect(findText()).toBe(
'This job is an out-of-date deployment to environment. View the most recent deployment.',
);
expect(findJobDeploymentLink().attributes('href')).toBe('bar');
});
describe('when there is a cluster', () => {
it('renders info with cluster', () => {
createComponent(
{
status: 'out_of_date',
environment: createEnvironmentWithLastDeployment(),
},
createDeploymentWithCluster(),
);
expect(findText()).toBe(
`This job is an out-of-date deployment to environment using cluster ${TEST_CLUSTER_NAME}. View the most recent deployment.`,
);
});
describe('when there is a kubernetes namespace', () => {
it('renders info with cluster', () => {
createComponent(
{
status: 'out_of_date',
environment: createEnvironmentWithLastDeployment(),
},
createDeploymentWithClusterAndKubernetesNamespace(),
);
expect(findText()).toBe(
`This job is an out-of-date deployment to environment using cluster ${TEST_CLUSTER_NAME} and namespace ${TEST_KUBERNETES_NAMESPACE}. View the most recent deployment.`,
);
});
});
});
});
describe('without last deployment', () => {
it('renders info about out of date deployment', () => {
createComponent({
status: 'out_of_date',
environment,
});
expect(findText()).toBe('This job is an out-of-date deployment to environment.');
});
});
});
describe('with failed deployment', () => {
it('renders info about failed deployment', () => {
createComponent({
status: 'failed',
environment,
});
expect(findText()).toBe('The deployment of this job to environment did not succeed.');
});
});
describe('creating deployment', () => {
describe('with last deployment', () => {
it('renders info about creating deployment and overriding latest deployment', () => {
createComponent({
status: 'creating',
environment: createEnvironmentWithLastDeployment(),
});
expect(findText()).toBe(
'This job is creating a deployment to environment. This will overwrite the latest deployment.',
);
expect(findEnvironmentLink().attributes('href')).toBe(environment.environment_path);
expect(findJobDeploymentLink().attributes('href')).toBe('bar');
expect(findClusterLink().exists()).toBe(false);
});
});
describe('without last deployment', () => {
it('renders info about deployment being created', () => {
createComponent({
status: 'creating',
environment,
});
expect(findText()).toBe('This job is creating a deployment to environment.');
});
describe('when there is a cluster', () => {
it('inclues information about the cluster', () => {
createComponent(
{
status: 'creating',
environment,
},
createDeploymentWithCluster(),
);
expect(findText()).toBe(
`This job is creating a deployment to environment using cluster ${TEST_CLUSTER_NAME}.`,
);
});
});
});
describe('without environment', () => {
it('does not render environment link', () => {
createComponent({
status: 'creating',
environment: null,
});
expect(findEnvironmentLink().exists()).toBe(false);
});
});
});
describe('with a cluster', () => {
it('renders the cluster link', () => {
createComponent(
{
status: 'last',
environment: createEnvironmentWithLastDeployment(),
},
createDeploymentWithCluster(),
);
expect(findText()).toBe(
`This job is deployed to environment using cluster ${TEST_CLUSTER_NAME}.`,
);
expect(findClusterLink().attributes('href')).toBe(TEST_CLUSTER_PATH);
});
describe('when the cluster is missing the path', () => {
it('renders the name without a link', () => {
createComponent(
{
status: 'last',
environment: createEnvironmentWithLastDeployment(),
},
{ name: 'the-cluster' },
);
expect(findText()).toContain('using cluster the-cluster.');
expect(findClusterLink().exists()).toBe(false);
});
});
});
});
|