2
2
* @file Integration tests for Firewall creation flows involving templates.
3
3
*/
4
4
5
- import {
6
- accountFactory ,
7
- firewallFactory ,
8
- firewallTemplateFactory ,
9
- } from 'src/factories' ;
10
5
import { mockGetAccount } from 'support/intercepts/account' ;
11
6
import { mockAppendFeatureFlags } from 'support/intercepts/feature-flags' ;
12
7
import {
@@ -17,8 +12,13 @@ import {
17
12
} from 'support/intercepts/firewalls' ;
18
13
import { mockApiInternalUser } from 'support/intercepts/general' ;
19
14
import { ui } from 'support/ui' ;
20
- import { buildArray } from 'support/util/arrays' ;
21
- import { randomNumber } from 'support/util/random' ;
15
+ import { randomLabel } from 'support/util/random' ;
16
+
17
+ import {
18
+ accountFactory ,
19
+ firewallFactory ,
20
+ firewallTemplateFactory ,
21
+ } from 'src/factories' ;
22
22
23
23
const mockFirewallTemplateVpc = firewallTemplateFactory . build ( {
24
24
slug : 'vpc' ,
@@ -51,13 +51,13 @@ describe('Can create Firewalls using templates', () => {
51
51
/*
52
52
* - Confirms that users can create a Firewall using the VPC template.
53
53
* - Confirms that VPC template-specific details are shown prior to creating Firewall.
54
- * - Confirms that outgoing Firewall create request includes autogenerated label.
54
+ * - Confirms that outgoing Firewall create request includes chosen Firewall label.
55
55
* - Confirms that outgoing Firewall create request includes chosen rules.
56
56
* - Confirms that landing page automatically updates to display the new Firewall.
57
57
*/
58
58
it ( 'can create a Firewall using VPC template' , ( ) => {
59
59
const mockFirewall = firewallFactory . build ( {
60
- label : 'vpc-1' ,
60
+ label : randomLabel ( ) ,
61
61
rules : mockFirewallTemplateVpc . rules ,
62
62
entities : [ ] ,
63
63
} ) ;
@@ -83,6 +83,7 @@ describe('Can create Firewalls using templates', () => {
83
83
. should ( 'be.visible' )
84
84
. within ( ( ) => {
85
85
cy . findByText ( 'From a Template' ) . should ( 'be.visible' ) . click ( ) ;
86
+ cy . findByText ( 'Label' ) . should ( 'be.visible' ) . type ( mockFirewall . label ) ;
86
87
87
88
cy . findByLabelText ( 'Firewall Template' ) . click ( ) ;
88
89
ui . autocompletePopper . find ( ) . within ( ( ) => {
@@ -104,16 +105,16 @@ describe('Can create Firewalls using templates', () => {
104
105
} ) ;
105
106
106
107
cy . wait ( '@createFirewall' ) . then ( ( xhr ) => {
107
- // Confirm that label is automatically assigned, and that rules reflect the selected template.
108
- expect ( xhr . request . body [ 'label' ] ) . to . equal ( 'vpc-1' ) ;
108
+ // Confirm that rules reflect the selected template.
109
+ expect ( xhr . request . body [ 'label' ] ) . to . equal ( mockFirewall . label ) ;
109
110
expect ( xhr . request . body [ 'rules' ] ) . to . deep . equal (
110
111
mockFirewallTemplateVpc . rules
111
112
) ;
112
113
} ) ;
113
114
114
115
// Confirm that page automatically updates to show the new Firewall,
115
116
// and that the expected information is displayed alongside the Firewall.
116
- cy . findByText ( 'vpc-1' )
117
+ cy . findByText ( mockFirewall . label )
117
118
. should ( 'be.visible' )
118
119
. closest ( 'tr' )
119
120
. within ( ( ) => {
@@ -126,36 +127,24 @@ describe('Can create Firewalls using templates', () => {
126
127
/*
127
128
* - Confirms that users can create a Firewall using the Public template.
128
129
* - Confirms that Public template-specific details are shown prior to creating Firewall.
129
- * - Confirms that outgoing Firewall create request includes autogenerated label.
130
- * - Confirms that autogenerated Firewall label takes into account existing Firewalls.
130
+ * - Confirms that outgoing Firewall create request includes chosen Firewall label
131
131
* - Confirms that outgoing Firewall create request includes chosen rules.
132
132
* - Confirms that landing page automatically updates to display the new Firewall.
133
133
*/
134
134
it ( 'can create a Firewall using Public template' , ( ) => {
135
- const existingFirewallCount = randomNumber ( 1 , 10 ) ;
136
-
137
- const mockExistingFirewalls = buildArray ( existingFirewallCount , ( i ) => {
138
- return firewallFactory . build ( {
139
- label : `public-${ i + 1 } ` ,
140
- rules : mockFirewallTemplatePublic . rules ,
141
- entities : [ ] ,
142
- } ) ;
143
- } ) ;
144
-
145
- const mockNewFirewallLabel = `public-${ existingFirewallCount + 1 } ` ;
146
- const mockNewFirewall = firewallFactory . build ( {
147
- label : mockNewFirewallLabel ,
135
+ const mockFirewall = firewallFactory . build ( {
136
+ label : randomLabel ( ) ,
148
137
rules : mockFirewallTemplatePublic . rules ,
149
138
entities : [ ] ,
150
139
} ) ;
151
140
152
- mockGetFirewalls ( mockExistingFirewalls ) . as ( 'getFirewalls' ) ;
141
+ mockGetFirewalls ( [ ] ) . as ( 'getFirewalls' ) ;
153
142
mockGetFirewallTemplates ( [
154
143
mockFirewallTemplateVpc ,
155
144
mockFirewallTemplatePublic ,
156
145
] ) ;
157
146
mockGetFirewallTemplate ( mockFirewallTemplatePublic ) ;
158
- mockCreateFirewall ( mockNewFirewall ) . as ( 'createFirewall' ) ;
147
+ mockCreateFirewall ( mockFirewall ) . as ( 'createFirewall' ) ;
159
148
160
149
cy . visitWithLogin ( '/firewalls' ) ;
161
150
cy . wait ( '@getFirewalls' ) ;
@@ -171,6 +160,7 @@ describe('Can create Firewalls using templates', () => {
171
160
. should ( 'be.visible' )
172
161
. within ( ( ) => {
173
162
cy . findByText ( 'From a Template' ) . should ( 'be.visible' ) . click ( ) ;
163
+ cy . findByText ( 'Label' ) . should ( 'be.visible' ) . type ( mockFirewall . label ) ;
174
164
175
165
cy . findByLabelText ( 'Firewall Template' ) . click ( ) ;
176
166
ui . autocompletePopper . find ( ) . within ( ( ) => {
@@ -186,9 +176,7 @@ describe('Can create Firewalls using templates', () => {
186
176
) . should ( 'be.visible' ) ;
187
177
188
178
// Create the Firewall
189
- mockGetFirewalls ( [ ...mockExistingFirewalls , mockNewFirewall ] ) . as (
190
- 'getFirewalls'
191
- ) ;
179
+ mockGetFirewalls ( [ mockFirewall ] ) . as ( 'getFirewalls' ) ;
192
180
ui . buttonGroup
193
181
. findButtonByTitle ( 'Create Firewall' )
194
182
. should ( 'be.visible' )
@@ -197,17 +185,17 @@ describe('Can create Firewalls using templates', () => {
197
185
} ) ;
198
186
199
187
cy . wait ( '@createFirewall' ) . then ( ( xhr ) => {
200
- // Confirm that label is automatically assigned, taking into account existing firewall labels,
188
+ // Confirm that label reflects chosen label
201
189
// and that the Firewall rules reflect the selected template.
202
- expect ( xhr . request . body [ 'label' ] ) . to . equal ( mockNewFirewallLabel ) ;
190
+ expect ( xhr . request . body [ 'label' ] ) . to . equal ( mockFirewall . label ) ;
203
191
expect ( xhr . request . body [ 'rules' ] ) . to . deep . equal (
204
192
mockFirewallTemplatePublic . rules
205
193
) ;
206
194
} ) ;
207
195
208
196
// Confirm that page automatically updates to show the new Firewall,
209
197
// and that the expected information is displayed alongside the Firewall.
210
- cy . findByText ( mockNewFirewallLabel )
198
+ cy . findByText ( mockFirewall . label )
211
199
. should ( 'be.visible' )
212
200
. closest ( 'tr' )
213
201
. within ( ( ) => {
@@ -220,13 +208,13 @@ describe('Can create Firewalls using templates', () => {
220
208
/*
221
209
* - Confirms that users can create a Firewall using the internal template.
222
210
* - Confirms that internal choice is present when internal API header exists and API includes the template.
223
- * - Confirms that outgoing Firewall create request includes autogenerated label.
211
+ * - Confirms that outgoing Firewall create request includes selected Firewall label.
224
212
* - Confirms that outgoing Firewall create request includes chosen rules.
225
213
* - Confirms that landing page automatically updates to display the new Firewall.
226
214
*/
227
215
it ( 'can create a Firewall using internal-only template as internal user' , ( ) => {
228
216
const mockFirewall = firewallFactory . build ( {
229
- label : 'akamai-non-prod-1' ,
217
+ label : randomLabel ( ) ,
230
218
rules : mockFirewallTemplateInternalUser . rules ,
231
219
entities : [ ] ,
232
220
} ) ;
@@ -254,6 +242,7 @@ describe('Can create Firewalls using templates', () => {
254
242
. should ( 'be.visible' )
255
243
. within ( ( ) => {
256
244
cy . findByText ( 'From a Template' ) . should ( 'be.visible' ) . click ( ) ;
245
+ cy . findByText ( 'Label' ) . should ( 'be.visible' ) . type ( mockFirewall . label ) ;
257
246
258
247
cy . findByLabelText ( 'Firewall Template' ) . click ( ) ;
259
248
ui . autocompletePopper . find ( ) . within ( ( ) => {
@@ -275,15 +264,15 @@ describe('Can create Firewalls using templates', () => {
275
264
cy . wait ( '@createFirewall' ) . then ( ( xhr ) => {
276
265
// Confirm that page automatically updates to show the new Firewall,
277
266
// and that the expected information is displayed alongside the Firewall.
278
- expect ( xhr . request . body [ 'label' ] ) . to . equal ( 'akamai-non-prod-1' ) ;
267
+ expect ( xhr . request . body [ 'label' ] ) . to . equal ( mockFirewall . label ) ;
279
268
expect ( xhr . request . body [ 'rules' ] ) . to . deep . equal (
280
269
mockFirewallTemplateInternalUser . rules
281
270
) ;
282
271
} ) ;
283
272
284
273
// Confirm that page automatically updates to show the new Firewall,
285
274
// and that the expected information is displayed alongside the Firewall.
286
- cy . findByText ( 'akamai-non-prod-1' )
275
+ cy . findByText ( mockFirewall . label )
287
276
. should ( 'be.visible' )
288
277
. closest ( 'tr' )
289
278
. within ( ( ) => {
@@ -317,6 +306,7 @@ describe('Can create Firewalls using templates', () => {
317
306
. should ( 'be.visible' )
318
307
. within ( ( ) => {
319
308
cy . findByText ( 'From a Template' ) . should ( 'be.visible' ) . click ( ) ;
309
+ cy . findByText ( 'Label' ) . should ( 'be.visible' ) . type ( randomLabel ( ) ) ;
320
310
321
311
cy . findByLabelText ( 'Firewall Template' ) . click ( ) ;
322
312
ui . autocompletePopper . find ( ) . within ( ( ) => {
@@ -329,6 +319,44 @@ describe('Can create Firewalls using templates', () => {
329
319
} ) ;
330
320
} ) ;
331
321
322
+ /*
323
+ * - Confirms a validation error displays for firewall label if no label inputted
324
+ * - Confirms a validation error displays for template select if no template chosen
325
+ */
326
+ it ( 'displays an error when trying to create a Firewall from a template without a label' , ( ) => {
327
+ mockGetFirewalls ( [ ] ) . as ( 'getFirewalls' ) ;
328
+ mockGetFirewallTemplates ( [
329
+ mockFirewallTemplateVpc ,
330
+ mockFirewallTemplatePublic ,
331
+ ] ) ;
332
+ mockGetFirewallTemplate ( mockFirewallTemplatePublic ) ;
333
+
334
+ cy . visitWithLogin ( '/firewalls' ) ;
335
+ cy . wait ( '@getFirewalls' ) ;
336
+
337
+ ui . button
338
+ . findByTitle ( 'Create Firewall' )
339
+ . should ( 'be.visible' )
340
+ . should ( 'be.enabled' )
341
+ . click ( ) ;
342
+
343
+ ui . drawer
344
+ . findByTitle ( 'Create Firewall' )
345
+ . should ( 'be.visible' )
346
+ . within ( ( ) => {
347
+ cy . findByText ( 'From a Template' ) . should ( 'be.visible' ) . click ( ) ;
348
+
349
+ ui . buttonGroup
350
+ . findButtonByTitle ( 'Create Firewall' )
351
+ . should ( 'be.visible' )
352
+ . should ( 'be.enabled' )
353
+ . click ( ) ;
354
+ } ) ;
355
+
356
+ cy . findByText ( 'Label is required.' ) ;
357
+ cy . findByText ( 'Please select a template to create a firewall from.' ) ;
358
+ } ) ;
359
+
332
360
// TODO M3-9775 - Delete this test once `linodeInterfaces` feature flag is removed.
333
361
/*
334
362
* - Confirms that "Custom Firewall" and "From a Template" selections are absent when feature flag is disabled.
0 commit comments