/
app.spec.ts
411 lines (341 loc) · 12.2 KB
/
app.spec.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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import {
getCheckedProjectItems,
getDeselectAllButton,
getFocusButtonForProject,
getGroupByFolderCheckbox,
getImageDownloadButton,
getIncludeProjectsInPathButton,
getSearchDepthCheckbox,
getSearchDepthIncrementButton,
getSelectAffectedButton,
getSelectAllButton,
getSelectProjectsMessage,
getTextFilterInput,
getTextFilterReset,
getToggleAllButtonForFolder,
getUncheckedProjectItems,
getUnfocusProjectButton,
} from '../support/app.po';
import * as affectedJson from '../fixtures/affected.json';
import * as nxExamplesJson from '../fixtures/nx-examples.json';
describe('graph-client', () => {
before(() => {
cy.intercept('/assets/graphs/nx.json', { fixture: 'nx-examples.json' }).as(
'getGraph'
);
cy.visit('/');
// 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('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/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/graphs/nx-examples.json', {
fixture: 'nx-examples.json',
}).as('getGraph');
cy.get('[data-cy=project-select]').select('Nx Examples', { 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')
);
getCheckedProjectItems().should(
'have.length',
['cart', ...dependencies, ...dependents].length
);
});
});
describe('unfocus button', () => {
it('should uncheck all project items', () => {
getFocusButtonForProject('cart').click({ force: true });
getUnfocusProjectButton().click();
getCheckedProjectItems().should('have.length', 0);
});
});
describe('toggle all projects in folder button', () => {
it('should uncheck 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', 0);
});
it('should check all projects in folder if no projects checked yet', () => {
getToggleAllButtonForFolder('shared').click({ force: true });
getCheckedProjectItems().should('have.length', 5);
});
});
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 });
cy.url().should('contain', 'focus=cart');
});
it('should set group by folder', () => {
getGroupByFolderCheckbox().click();
cy.url().should('contain', 'groupByFolder=true');
});
it('should set search depth disabled', () => {
// it's on by default, clicking should disable it
getSearchDepthCheckbox().click();
cy.url().should('contain', 'searchDepth=0');
});
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.url().should('contain', 'searchDepth=2');
});
it('should set select to all', () => {
getSelectAllButton().click();
cy.url().should('contain', 'select=all');
});
});
});
describe('loading graph client with url params', () => {
beforeEach(() => {
cy.intercept('/assets/graphs/*', { fixture: 'nx-examples.json' }).as(
'getGraph'
);
});
it('should focus projects', () => {
cy.visit('/?focus=cart');
// wait for first graph to finish loading
cy.wait('@getGraph');
const dependencies = nxExamplesJson.dependencies.cart;
const dependents = Object.keys(nxExamplesJson.dependencies).filter((key) =>
nxExamplesJson.dependencies[key]
.map((dependencies) => dependencies.target)
.includes('cart')
);
getCheckedProjectItems().should(
'have.length',
['cart', ...dependencies, ...dependents].length
);
});
it('should focus projects with search depth', () => {
cy.visit('/?focus=cart&searchDepth=2');
// wait for first graph to finish loading
cy.wait('@getGraph');
getCheckedProjectItems().should('have.length', 10);
getSearchDepthCheckbox().should('exist');
});
it('should focus projects with search depth disabled', () => {
cy.visit('/?focus=cart&searchDepth=0');
// wait for first graph to finish loading
cy.wait('@getGraph');
getCheckedProjectItems().should('have.length', 12);
getSearchDepthCheckbox().should('exist');
});
it('should set group by folder', () => {
cy.visit('/?focus=nx-dev&searchDepth=1&groupByFolder=true');
// wait for first graph to finish loading
cy.wait('@getGraph');
getGroupByFolderCheckbox().should('be.checked');
});
it('should select all projects', () => {
cy.visit('/?select=all');
// wait for first graph to finish loading
cy.wait('@getGraph');
getCheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.length
);
});
});
describe('theme preferences', () => {
let systemTheme: string;
before(() => {
cy.visit('/');
systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light';
});
it('should initialize localstorage with default theme', () => {
expect(localStorage.getItem('nx-dep-graph-theme')).eq('system');
});
it('has system default theme', () => {
cy.log('system theme is:', systemTheme);
cy.get('html').should('have.class', systemTheme);
});
describe('dark theme is set as prefered', () => {
before(() => {
cy.get('[data-cy="theme-open-modal-button"]').click();
cy.get('[data-cy="dark-theme-button"]').click();
});
it('should set dark theme', () => {
cy.log('Localstorage is: ', localStorage.getItem('nx-dep-graph-theme'));
expect(localStorage.getItem('nx-dep-graph-theme')).eq('dark');
cy.get('html').should('have.class', 'dark');
});
});
describe('light theme is set as preferred', () => {
before(() => {
cy.get('[data-cy="theme-open-modal-button"]').click();
cy.get('[data-cy="light-theme-button"]').click();
});
it('should set light theme', () => {
cy.log('Localstorage is: ', localStorage.getItem('nx-dep-graph-theme'));
expect(localStorage.getItem('nx-dep-graph-theme')).eq('light');
cy.get('html').should('have.class', 'light');
});
});
});