forked from nrwl/nx
/
routing-tests.ts
166 lines (138 loc) · 4.6 KB
/
routing-tests.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
import * as nxExamplesJson from '../fixtures/nx-examples-project-graph.json';
import {
getCheckedProjectItems,
getGroupByFolderCheckbox,
getGroupByProjectCheckbox,
getSearchDepthCheckbox,
getSelectTargetDropdown,
} from './app.po';
function waitForProjectGraph(router: 'hash' | 'browser') {
if (router === 'browser') {
cy.wait('@getGraph');
}
}
function waitForTaskGraphs(router: 'hash' | 'browser') {
if (router === 'browser') {
cy.wait('@getTaskGraphs');
}
}
function resolveProjectsRoute(
router: 'hash' | 'browser',
route: string,
paramString: string
) {
if (router === 'hash') {
return `/#${route}?${paramString}`;
} else {
return `${route}?${paramString}`;
}
}
function resolveTasksRoute(
router: 'hash' | 'browser',
route: string,
paramString: string
) {
if (router === 'hash') {
return `/#${route}?${paramString}`;
} else {
return `${route}?${paramString}`;
}
}
export function testProjectsRoutes(
router: 'hash' | 'browser',
routes: string[]
) {
routes.forEach((route) => {
describe(`for route ${route}`, () => {
it('should focus projects', () => {
cy.visit(resolveProjectsRoute(router, `${route}/cart`, ''));
// wait for first graph to finish loading
waitForProjectGraph(router);
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 special characters', () => {
cy.visit(
resolveProjectsRoute(router, `${route}/%40scoped%2Fproject-a`, '')
);
// wait for first graph to finish loading
waitForProjectGraph(router);
const dependencies = nxExamplesJson.dependencies['@scoped/project-a'];
const dependents = Object.keys(nxExamplesJson.dependencies).filter(
(key) =>
nxExamplesJson.dependencies[key]
.map((dependencies) => dependencies.target)
.includes('@scoped/project-a')
);
getCheckedProjectItems().should(
'have.length',
['@scoped/project-a', ...dependencies, ...dependents].length
);
});
it('should focus projects with search depth', () => {
cy.visit(
resolveProjectsRoute(router, `${route}/cart`, `searchDepth=2`)
);
// wait for first graph to finish loading
waitForProjectGraph(router);
getCheckedProjectItems().should('have.length', 10);
getSearchDepthCheckbox().should('exist');
});
it('should focus projects with search depth disabled', () => {
cy.visit(
resolveProjectsRoute(router, `${route}/cart`, `searchDepth=0`)
);
// wait for first graph to finish loading
waitForProjectGraph(router);
getCheckedProjectItems().should('have.length', 12);
getSearchDepthCheckbox().should('exist');
});
it('should set group by folder', () => {
cy.visit(
resolveProjectsRoute(router, `${route}/cart`, `groupByFolder=true`)
);
// wait for first graph to finish loading
waitForProjectGraph(router);
getGroupByFolderCheckbox().should('be.checked');
});
it('should select all projects', () => {
cy.visit(resolveProjectsRoute(router, `${route}/all`, ``));
// wait for first graph to finish loading
waitForProjectGraph(router);
getCheckedProjectItems().should(
'have.length',
nxExamplesJson.projects.length
);
});
});
});
}
export function testTaskRoutes(router: 'hash' | 'browser', routes: string[]) {
routes.forEach((route) => {
describe(`for route ${route}`, () => {
it('should set group by project', () => {
cy.visit(resolveTasksRoute(router, route, `groupByProject=true`));
// wait for first graph to finish loading
waitForProjectGraph(router);
waitForTaskGraphs(router);
getGroupByProjectCheckbox().should('be.checked');
});
it('should set selected target', () => {
cy.visit(resolveTasksRoute(router, `${route}/e2e`, ''));
// wait for first graph to finish loading
waitForProjectGraph(router);
waitForTaskGraphs(router);
getSelectTargetDropdown().should('have.value', 'e2e');
});
});
});
}