/
dev-project-graph.cy.ts
390 lines (341 loc) · 12.8 KB
/
dev-project-graph.cy.ts
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import {
getCheckedProjectItems,
getDeselectAllButton,
getFocusButtonForProject,
getGroupByFolderCheckbox,
getImageDownloadButton,
getIncludeProjectsInPathButton,
getSearchDepthCheckbox,
getSearchDepthDecrementButton,
getSearchDepthIncrementButton,
getSelectAffectedButton,
getSelectAllButton,
getSelectProjectsMessage,
getTextFilterInput,
getTextFilterReset,
getToggleAllButtonForFolder,
getUncheckedProjectItems,
getUnfocusProjectButton,
} from '../support/app.po';
import * as affectedJson from '../fixtures/affected.json';
import { testProjectsRoutes } from '../support/routing-tests';
import * as nxExamplesJson from '../fixtures/nx-examples-project-graph.json';
describe('dev mode - project graph', () => {
before(() => {
cy.intercept('/assets/project-graphs/e2e.json', {
fixture: 'nx-examples-project-graph.json',
}).as('getGraph');
cy.visit('/e2e/projects');
// wait for initial graph to finish loading
cy.wait('@getGraph');
});
afterEach(() => {
// clean up by hiding all projects and clearing text input
getDeselectAllButton().click();
getTextFilterInput().clear();
getCheckedProjectItems().should('have.length', 0);
});
describe('select projects message', () => {
it('should display on load', () => {
getSelectProjectsMessage().should('be.visible');
});
it('should hide when a project is selected', () => {
cy.contains('cart').scrollIntoView().should('be.visible');
cy.get('[data-project="cart"]').should('be.visible');
cy.get('[data-project="cart"]').click({ force: true });
getSelectProjectsMessage().should('not.exist');
});
});
describe('text filter', () => {
it('should hide clear button initially', () => {
getTextFilterReset().should('not.exist');
});
it('should show clear button after typing', () => {
getTextFilterInput().type('cart');
getTextFilterReset().should('exist');
});
it('should clear selection on reset', () => {
getTextFilterInput().type('cart');
getCheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.filter((project) =>
project.name.includes('cart')
).length
);
getTextFilterReset().click();
getCheckedProjectItems().should('have.length', 0);
});
it('should hide clear button after clicking', () => {
getTextFilterInput().type('cart');
getTextFilterReset().click().should('not.exist');
});
it('should filter projects by text when pressing enter', () => {
getTextFilterInput().type('cart{enter}');
getCheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.filter((project) =>
project.name.includes('cart')
).length
);
});
it('should filter projects by text after debounce', () => {
getTextFilterInput().type('cart');
getCheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.filter((project) =>
project.name.includes('cart')
).length
);
});
it('should include projects in path when option is checked', () => {
getTextFilterInput().type('cart');
getIncludeProjectsInPathButton().click();
getCheckedProjectItems().should(
'have.length.gt',
nxExamplesJson.projects.filter((project) =>
project.name.includes('cart')
).length
);
});
});
describe('proximity', () => {
it('should change when increment/decrement button is clicked', () => {
cy.get('[data-cy="depth-value"]').should('contain', '1');
getSearchDepthIncrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '2');
getSearchDepthDecrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '1');
});
it("should reactivate proximity if it's disabled and a button is clicked", () => {
getSearchDepthIncrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '2');
getSearchDepthCheckbox()
.should('be.checked')
.click()
.should('not.be.checked')
.click();
getSearchDepthIncrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '3');
getSearchDepthCheckbox()
.should('be.checked')
.click()
.should('not.be.checked')
.click();
getSearchDepthDecrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '2');
getSearchDepthCheckbox()
.should('be.checked')
.click()
.should('not.be.checked')
.click();
// return to 1 for following tests
getSearchDepthDecrementButton().click();
});
it('should not go below 1', () => {
getSearchDepthIncrementButton().click();
getSearchDepthIncrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '3');
getSearchDepthDecrementButton().click();
getSearchDepthDecrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '1');
getSearchDepthDecrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '1');
});
});
describe('select all button', () => {
it('should check all project items', () => {
getSelectAllButton().scrollIntoView().click({ force: true });
getCheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.length
);
});
});
describe('deselect all button', () => {
it('should uncheck all project items', () => {
getDeselectAllButton().click();
getUncheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.length
);
getSelectProjectsMessage().should('be.visible');
});
});
describe('show affected button', () => {
it('should be hidden initially', () => {
getSelectAffectedButton().should('not.exist');
});
it('should check all affected project items', () => {
cy.intercept('/assets/project-graphs/affected.json', {
fixture: 'affected.json',
}).as('getAffectedGraph');
cy.get('[data-cy=project-select]').select('affected', { force: true });
cy.wait('@getAffectedGraph');
getSelectAffectedButton().click();
getCheckedProjectItems().should(
'have.length',
affectedJson.affected.length
);
// switch back to Nx Examples graph before proceeding
cy.intercept('/assets/project-graphs/e2e.json', {
fixture: 'nx-examples-project-graph.json',
}).as('getGraph');
cy.get('[data-cy=project-select]').select('e2e', { force: true });
cy.wait('@getGraph');
});
});
describe('selecting projects', () => {
it('should select a project by clicking on the project name', () => {
cy.get('[data-project="cart"]').should('have.data', 'active', false);
cy.get('[data-project="cart"]').click({
force: true,
});
cy.get('[data-project="cart"][data-active="true"]').should('exist');
});
it('should deselect a project by clicking on the project name again', () => {
cy.get('[data-project="cart"]').click({
force: true,
});
cy.get('[data-project="cart"][data-active="true"]')
.should('exist')
.click({
force: true,
});
cy.get('[data-project="cart"][data-active="false"]').should('exist');
});
it('should select a project by clicking on the selected icon', () => {
cy.get('[data-project="cart"][data-active="false"]').click({
force: true,
});
cy.get('[data-project="cart"][data-active="true"]')
.should('exist')
.parent()
.siblings()
.first()
.should('exist')
.click({
force: true,
});
cy.get('[data-project="cart"][data-active="false"]').should('exist');
});
});
describe('focusing projects in sidebar', () => {
it('should select appropriate projects', () => {
cy.contains('cart').scrollIntoView().should('be.visible');
getFocusButtonForProject('cart').click({ force: true });
const dependencies = nxExamplesJson.dependencies.cart;
const dependents = Object.keys(nxExamplesJson.dependencies).filter(
(key) =>
nxExamplesJson.dependencies[key]
.map((dependencies) => dependencies.target)
.includes('cart')
);
getUnfocusProjectButton().should('exist');
getCheckedProjectItems().should(
'have.length',
['cart', ...dependencies, ...dependents].length
);
});
it('should url encode projects with special chars', () => {
getFocusButtonForProject('@scoped/project-a').click({ force: true });
cy.url().should('include', '%40scoped%2Fproject-a');
});
});
describe('unfocus button', () => {
it('should uncheck all project items', () => {
getFocusButtonForProject('cart').click({ force: true });
getUnfocusProjectButton().click();
getUnfocusProjectButton().should('not.exist');
getCheckedProjectItems().should('have.length', 0);
});
});
describe('toggle all projects in folder button', () => {
it('should check all projects in folder if at least one project checked', () => {
cy.contains('shared-product-state').scrollIntoView().should('be.visible');
cy.get('[data-project="shared-product-state"]').should('be.visible');
cy.get('[data-project="shared-product-state"]').click({ force: true });
getToggleAllButtonForFolder('shared/product').click({ force: true });
getCheckedProjectItems().should('have.length', 4);
});
it('should check all projects in folder if no projects checked yet', () => {
getToggleAllButtonForFolder('shared').click({ force: true });
getCheckedProjectItems().should('have.length', 5);
});
it('should uncheck all projects in folder if all projects checked yet', () => {
getToggleAllButtonForFolder('shared').click({ force: true });
getCheckedProjectItems().should('have.length', 5);
getToggleAllButtonForFolder('shared').click({ force: true });
getCheckedProjectItems().should('have.length', 0);
});
});
describe('image download button', () => {
it('should be hidden initally', () => {
getImageDownloadButton().should('have.class', 'opacity-0');
});
it('should be shown when a project is selected', () => {
cy.get('[data-project="cart"]').click({ force: true });
getImageDownloadButton().should('not.have.class', 'opacity-0');
});
it('should be hidden when no more projects are selected', () => {
cy.get('[data-project="cart"]').click({ force: true });
getDeselectAllButton().click();
getImageDownloadButton().should('have.class', 'opacity-0');
});
});
describe('setting url params', () => {
it('should set focused project', () => {
cy.contains('cart').scrollIntoView().should('be.visible');
getFocusButtonForProject('cart').click({ force: true });
getUnfocusProjectButton().should('exist');
cy.url().should('contain', '/projects/cart');
cy.reload();
getUnfocusProjectButton().should('exist');
});
it('should set group by folder', () => {
getGroupByFolderCheckbox().click();
getGroupByFolderCheckbox().should('be.checked');
cy.url().should('contain', 'groupByFolder=true');
cy.reload();
getGroupByFolderCheckbox().should('be.checked');
});
it('should set search depth disabled', () => {
// it's on by default, clicking should disable it
getSearchDepthCheckbox().click();
getSearchDepthCheckbox().should('not.be.checked');
cy.url().should('contain', 'searchDepth=0');
cy.reload();
getSearchDepthCheckbox().should('not.be.checked');
// re-enable to clean-up for following tests
getSearchDepthCheckbox().click();
});
it('should set search depth if greater than 1', () => {
// it's on by default and set to 1, clicking should change it to 2
getSearchDepthIncrementButton().click();
cy.get('[data-cy="depth-value"]').should('contain', '2');
cy.url().should('contain', 'searchDepth=2');
cy.reload();
cy.get('[data-cy="depth-value"]').should('contain', '2');
});
it('should set select to all', () => {
getSelectAllButton().click();
getCheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.length
);
cy.url().should('contain', '/projects/all');
cy.reload();
getCheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.length
);
});
});
});
describe('loading graph client with url params', () => {
beforeEach(() => {
cy.intercept('/assets/project-graphs/*', {
fixture: 'nx-examples-project-graph.json',
}).as('getGraph');
});
testProjectsRoutes('browser', ['/e2e/projects']);
});