-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy pathcollapsingAndEntering.spec.ts
277 lines (243 loc) · 10.4 KB
/
collapsingAndEntering.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
import { test, type Page } from '@playwright/test'
import * as actions from './actions'
import { expect } from './customExpect'
import { mockCollapsedFunctionInfo } from './expressionUpdates'
import { CONTROL_KEY, DELETE_KEY } from './keyboard'
import * as locate from './locate'
import { edgesFromNode, edgesToNode } from './locate'
import { mockSuggestion } from './suggestionUpdates'
const MAIN_FILE_NODES = 12
const EDGE_PARTS = 2
const COLLAPSE_SHORTCUT = `${CONTROL_KEY}+G`
test('Entering nodes', async ({ page }) => {
await actions.goToGraph(page)
await mockCollapsedFunctionInfo(page, 'final', 'func1')
await expectInsideMain(page)
await expect(locate.navBreadcrumb(page)).toHaveText(['Mock Project'])
await locate.graphNodeByBinding(page, 'final').dblclick()
await mockCollapsedFunctionInfo(page, 'f2', 'func2')
await expectInsideFunc1(page)
await expect(locate.navBreadcrumb(page)).toHaveText(['Mock Project', 'func1'])
await locate.graphNodeByBinding(page, 'f2').dblclick()
await expectInsideFunc2(page)
await expect(locate.navBreadcrumb(page)).toHaveText(['Mock Project', 'func1', 'func2'])
})
test('Leaving entered nodes', async ({ page }) => {
await actions.goToGraph(page)
await enterToFunc2(page)
await actions.exitFunction(page)
await expectInsideFunc1(page)
await actions.exitFunction(page)
await expectInsideMain(page)
})
test('Using breadcrumbs to navigate', async ({ page }) => {
await actions.goToGraph(page)
await enterToFunc2(page)
await actions.exitFunction(page)
await expectInsideFunc1(page)
await actions.exitFunction(page)
await expectInsideMain(page)
// Breadcrumbs still have all the crumbs, but the last two are dimmed.
await expect(locate.navBreadcrumb(page)).toHaveText(['Mock Project', 'func1', 'func2'])
await expect(locate.navBreadcrumb(page).and(page.locator('.inactive'))).toHaveText([
'func1',
'func2',
])
await locate.navBreadcrumb(page).filter({ hasText: 'func2' }).click()
await expectInsideFunc2(page)
await locate.navBreadcrumb(page).filter({ hasText: 'Mock Project' }).click()
await expectInsideMain(page)
await locate.navBreadcrumb(page).filter({ hasText: 'func1' }).click()
await expectInsideFunc1(page)
})
test('Collapsing nodes', async ({ page }) => {
await actions.goToGraph(page)
const initialNodesCount = await locate.graphNode(page).count()
await mockCollapsedFunctionInfo(page, 'final', 'func1')
// Widgets may "steal" clicks, so we always click at icon.
await locate
.graphNodeByBinding(page, 'prod')
.locator('.grab-handle')
.click({ modifiers: ['Shift'] })
await locate
.graphNodeByBinding(page, 'sum')
.locator('.grab-handle')
.click({ modifiers: ['Shift'] })
await locate
.graphNodeByBinding(page, 'ten')
.locator('.grab-handle')
.click({ modifiers: ['Shift'] })
await page.getByLabel('Group Selected Components').click()
await expect(locate.graphNode(page)).toHaveCount(initialNodesCount - 2)
await mockCollapsedFunctionInfo(page, 'prod', 'collapsed')
await mockSuggestion(page, {
type: 'method',
module: 'local.Mock_Project',
name: 'collapsed',
isStatic: true,
arguments: [{ name: 'five', reprType: 'Any', isSuspended: false, hasDefault: false }],
selfType: 'local.Mock_Project',
returnType: 'Standard.Base.Any.Any',
annotations: [],
})
const collapsedNode = locate.graphNodeByBinding(page, 'prod')
await expect(collapsedNode.locator('.WidgetApplication.prefix > .WidgetPort')).toExist()
await expect(collapsedNode.locator('.WidgetApplication.prefix > .WidgetPort')).toHaveText(
'Main.collapsed',
)
await expect(collapsedNode.locator('.WidgetTopLevelArgument')).toHaveText('five')
await locate.graphNodeIcon(collapsedNode).dblclick()
await expect(locate.graphNode(page)).toHaveCount(5)
await expect(locate.inputNode(page)).toHaveCount(1)
await expect(locate.graphNodeByBinding(page, 'ten')).toExist()
await expect(locate.graphNodeByBinding(page, 'sum')).toExist()
await expect(locate.graphNodeByBinding(page, 'prod')).toExist()
await locate
.graphNodeByBinding(page, 'ten')
.locator('.grab-handle')
.click({ modifiers: ['Shift'] })
// Wait till node is selected.
await expect(locate.graphNodeByBinding(page, 'ten').and(page.locator('.selected'))).toHaveCount(1)
await page.keyboard.press(COLLAPSE_SHORTCUT)
await expect(locate.graphNode(page)).toHaveCount(5)
await expect(locate.inputNode(page)).toHaveCount(1)
const secondCollapsedNode = locate.graphNodeByBinding(page, 'ten')
await expect(secondCollapsedNode.locator('.WidgetToken')).toHaveText(['Main', '.', 'collapsed1'])
await mockCollapsedFunctionInfo(page, 'ten', 'collapsed1')
await secondCollapsedNode.dblclick()
await expect(locate.graphNode(page)).toHaveCount(2)
await expect(locate.graphNodeByBinding(page, 'ten')).toExist()
})
test('Input node', async ({ page }) => {
await actions.goToGraph(page)
await enterToFunc2(page)
const inputNode = locate.inputNode(page)
await expect(inputNode).toHaveCount(1)
// Input node with identifier should have the icon and an identifier.
await expect(inputNode.locator('.WidgetIcon')).toHaveCount(1)
await expect(inputNode.locator('.WidgetToken')).toContainText('a')
await inputNode.click()
await page.keyboard.press('Delete')
await expect(inputNode).toHaveCount(1)
await inputNode.locator('.More').click({})
await expect(inputNode.getByTestId('removeNode')).toHaveClass(/(?<=^| )disabled(?=$| )/)
})
test('Output node', async ({ page }) => {
await actions.goToGraph(page)
await enterToFunc2(page)
const outputNode = locate.outputNode(page)
await expect(outputNode).toHaveCount(1)
// Output node with identifier should have only icon and no displayed identifiers
await expect(outputNode.locator('.WidgetIcon')).toHaveCount(1)
await expect(outputNode.locator('.WidgetToken')).toHaveCount(0)
await outputNode.click()
await page.keyboard.press('Delete')
await expect(outputNode).toHaveCount(1)
await outputNode.locator('.More').click({})
await expect(outputNode.getByTestId('removeNode')).toHaveClass(/(?<=^| )disabled(?=$| )/)
})
test('Output node is not collapsed', async ({ page }) => {
await actions.goToGraph(page)
await enterToFunc2(page)
await locate.outputNode(page).click({ modifiers: ['Shift'] })
await locate
.graphNodeByBinding(page, 'r')
.locator('.grab-handle')
.click({ modifiers: ['Shift'] })
await page.getByLabel('Group Selected Components').click()
await expect(locate.graphNodeByBinding(page, 'r').locator('.WidgetToken')).toHaveText([
'Main',
'.',
'collapsed',
'a',
])
await expect(locate.inputNode(page)).toHaveCount(1)
})
test('Input node is not collapsed', async ({ page }) => {
await actions.goToGraph(page)
await enterToFunc2(page)
await locate
.graphNodeByBinding(page, 'r')
.locator('.grab-handle')
.click({ modifiers: ['Shift'] })
await locate.inputNode(page).click({ modifiers: ['Shift'] })
await page.getByLabel('Group Selected Components').click()
await expect(locate.graphNodeByBinding(page, 'r').locator('.WidgetToken')).toHaveText([
'Main',
'.',
'collapsed',
'a',
])
await expect(locate.outputNode(page)).toHaveCount(1)
})
test('Collapsed call shows argument placeholders', async ({ page }) => {
await actions.goToGraph(page)
await mockCollapsedFunctionInfo(page, 'final', 'func1', [0])
await mockSuggestion(page, {
type: 'method',
module: 'local.Mock_Project.Main',
name: 'func1',
arguments: [
{
name: 'arg1',
reprType: 'Standard.Base.Any.Any',
isSuspended: false,
hasDefault: false,
defaultValue: null as any,
tagValues: null as any,
},
],
selfType: 'local.Mock_Project.Main',
returnType: 'Standard.Base.Any.Any',
isStatic: true,
documentation: '',
annotations: [],
})
const collapsedCallComponent = locate.graphNodeByBinding(page, 'final')
await locate.graphNodeByBinding(page, 'prod').click()
await page.keyboard.press(DELETE_KEY)
await expect(await edgesToNode(page, collapsedCallComponent)).toHaveCount(0)
await expect(locate.selectedNodes(page)).toHaveCount(0)
await expect(collapsedCallComponent.locator('.WidgetArgumentName .name')).toHaveText('arg1')
})
async function expectInsideMain(page: Page) {
await actions.expectNodePositionsInitialized(page, -16)
await expect(locate.graphNode(page)).toHaveCount(MAIN_FILE_NODES)
await expect(locate.graphNodeByBinding(page, 'five')).toExist()
await expect(locate.graphNodeByBinding(page, 'ten')).toExist()
await expect(locate.graphNodeByBinding(page, 'sum')).toExist()
await expect(locate.graphNodeByBinding(page, 'prod')).toExist()
await expect(locate.graphNodeByBinding(page, 'final')).toExist()
await expect(locate.graphNodeByBinding(page, 'list')).toExist()
await expect(locate.graphNodeByBinding(page, 'data')).toExist()
await expect(locate.graphNodeByBinding(page, 'aggregated')).toExist()
await expect(locate.graphNodeByBinding(page, 'filtered')).toExist()
await expect(locate.graphNodeByBinding(page, 'autoscoped')).toExist()
}
async function expectInsideFunc1(page: Page) {
await actions.expectNodePositionsInitialized(page, -88)
await expect(locate.graphNode(page)).toHaveCount(4)
await expect(locate.inputNode(page)).toHaveCount(1)
await expect(locate.graphNodeByBinding(page, 'f2')).toExist()
await expect(locate.graphNodeByBinding(page, 'result')).toExist()
await expect(locate.outputNode(page)).toHaveCount(1)
await expect(await edgesFromNode(page, locate.inputNode(page))).toHaveCount(EDGE_PARTS)
await expect(await edgesToNode(page, locate.outputNode(page))).toHaveCount(EDGE_PARTS)
}
async function expectInsideFunc2(page: Page) {
await actions.expectNodePositionsInitialized(page, -88)
await expect(locate.graphNode(page)).toHaveCount(3)
await expect(locate.inputNode(page)).toHaveCount(1)
await expect(locate.graphNodeByBinding(page, 'r')).toExist()
await expect(locate.outputNode(page)).toHaveCount(1)
await expect(await edgesFromNode(page, locate.inputNode(page))).toHaveCount(EDGE_PARTS)
await expect(await edgesToNode(page, locate.outputNode(page))).toHaveCount(EDGE_PARTS)
}
async function enterToFunc2(page: Page) {
await mockCollapsedFunctionInfo(page, 'final', 'func1')
await locate.graphNodeByBinding(page, 'final').dblclick()
await expectInsideFunc1(page)
await mockCollapsedFunctionInfo(page, 'f2', 'func2')
await locate.graphNodeByBinding(page, 'f2').dblclick()
await expectInsideFunc2(page)
}