@neo4j-cypher/react-codemirror 2.0.0-next.1 → 2.0.0-next.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +4 -1
  3. package/dist/{types/CypherEditor.d.ts → CypherEditor.d.ts} +69 -8
  4. package/dist/CypherEditor.js +300 -0
  5. package/dist/CypherEditor.js.map +1 -0
  6. package/dist/CypherEditor.test.js +151 -0
  7. package/dist/CypherEditor.test.js.map +1 -0
  8. package/dist/constants.d.ts +1 -0
  9. package/dist/constants.js +2 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/e2e_tests/autoCompletion.spec.js +267 -0
  12. package/dist/e2e_tests/autoCompletion.spec.js.map +1 -0
  13. package/dist/e2e_tests/configuration.spec.js +83 -0
  14. package/dist/e2e_tests/configuration.spec.js.map +1 -0
  15. package/dist/e2e_tests/debounce.spec.js +65 -0
  16. package/dist/e2e_tests/debounce.spec.js.map +1 -0
  17. package/dist/e2e_tests/e2eUtils.js +60 -0
  18. package/dist/e2e_tests/e2eUtils.js.map +1 -0
  19. package/dist/e2e_tests/extraKeybindings.spec.js +43 -0
  20. package/dist/e2e_tests/extraKeybindings.spec.js.map +1 -0
  21. package/dist/e2e_tests/historyNavigation.spec.js +227 -0
  22. package/dist/e2e_tests/historyNavigation.spec.js.map +1 -0
  23. package/dist/e2e_tests/performanceTest.spec.d.ts +6 -0
  24. package/dist/e2e_tests/performanceTest.spec.js +96 -0
  25. package/dist/e2e_tests/performanceTest.spec.js.map +1 -0
  26. package/dist/e2e_tests/sanityChecks.spec.js +53 -0
  27. package/dist/e2e_tests/sanityChecks.spec.js.map +1 -0
  28. package/dist/e2e_tests/signatureHelp.spec.js +179 -0
  29. package/dist/e2e_tests/signatureHelp.spec.js.map +1 -0
  30. package/dist/e2e_tests/snippets.spec.js +62 -0
  31. package/dist/e2e_tests/snippets.spec.js.map +1 -0
  32. package/dist/e2e_tests/syntaxHighlighting.spec.d.ts +1 -0
  33. package/dist/e2e_tests/syntaxHighlighting.spec.js +90 -0
  34. package/dist/e2e_tests/syntaxHighlighting.spec.js.map +1 -0
  35. package/dist/e2e_tests/syntaxValidation.spec.d.ts +1 -0
  36. package/dist/e2e_tests/syntaxValidation.spec.js +79 -0
  37. package/dist/e2e_tests/syntaxValidation.spec.js.map +1 -0
  38. package/dist/historyNavigation.d.ts +7 -0
  39. package/dist/historyNavigation.js +163 -0
  40. package/dist/historyNavigation.js.map +1 -0
  41. package/dist/{types/icons.d.ts → icons.d.ts} +1 -1
  42. package/dist/icons.js +62 -0
  43. package/dist/icons.js.map +1 -0
  44. package/dist/index.d.ts +4 -0
  45. package/dist/index.js +5 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/lang-cypher/autocomplete.d.ts +6 -0
  48. package/dist/lang-cypher/autocomplete.js +124 -0
  49. package/dist/lang-cypher/autocomplete.js.map +1 -0
  50. package/dist/{types/lang-cypher → lang-cypher}/constants.d.ts +9 -0
  51. package/dist/lang-cypher/constants.js +65 -0
  52. package/dist/lang-cypher/constants.js.map +1 -0
  53. package/dist/lang-cypher/contants.test.d.ts +1 -0
  54. package/dist/lang-cypher/contants.test.js +103 -0
  55. package/dist/lang-cypher/contants.test.js.map +1 -0
  56. package/dist/lang-cypher/createCypherTheme.js +179 -0
  57. package/dist/lang-cypher/createCypherTheme.js.map +1 -0
  58. package/dist/lang-cypher/langCypher.d.ts +14 -0
  59. package/dist/lang-cypher/langCypher.js +30 -0
  60. package/dist/lang-cypher/langCypher.js.map +1 -0
  61. package/dist/lang-cypher/lintWorker.d.ts +8 -0
  62. package/dist/lang-cypher/lintWorker.js +4 -0
  63. package/dist/lang-cypher/lintWorker.js.map +1 -0
  64. package/dist/lang-cypher/parser-adapter.d.ts +19 -0
  65. package/dist/lang-cypher/parser-adapter.js +113 -0
  66. package/dist/lang-cypher/parser-adapter.js.map +1 -0
  67. package/dist/lang-cypher/signatureHelp.d.ts +4 -0
  68. package/dist/lang-cypher/signatureHelp.js +94 -0
  69. package/dist/lang-cypher/signatureHelp.js.map +1 -0
  70. package/dist/lang-cypher/syntaxValidation.d.ts +5 -0
  71. package/dist/lang-cypher/syntaxValidation.js +69 -0
  72. package/dist/lang-cypher/syntaxValidation.js.map +1 -0
  73. package/dist/lang-cypher/themeIcons.js +22 -0
  74. package/dist/lang-cypher/themeIcons.js.map +1 -0
  75. package/dist/lang-cypher/utils.d.ts +2 -0
  76. package/dist/lang-cypher/utils.js +10 -0
  77. package/dist/lang-cypher/utils.js.map +1 -0
  78. package/dist/ndlTokensCopy.js +380 -0
  79. package/dist/ndlTokensCopy.js.map +1 -0
  80. package/dist/ndlTokensCopy.test.d.ts +1 -0
  81. package/dist/ndlTokensCopy.test.js +12 -0
  82. package/dist/ndlTokensCopy.test.js.map +1 -0
  83. package/dist/neo4jSetup.js +120 -0
  84. package/dist/neo4jSetup.js.map +1 -0
  85. package/dist/{types/themes.d.ts → themes.d.ts} +1 -1
  86. package/dist/themes.js +114 -0
  87. package/dist/themes.js.map +1 -0
  88. package/dist/tsconfig.tsbuildinfo +1 -0
  89. package/package.json +30 -31
  90. package/src/CypherEditor.test.tsx +200 -0
  91. package/src/CypherEditor.tsx +292 -41
  92. package/src/constants.ts +1 -0
  93. package/src/e2e_tests/autoCompletion.spec.tsx +472 -0
  94. package/src/e2e_tests/configuration.spec.tsx +111 -0
  95. package/src/e2e_tests/debounce.spec.tsx +101 -0
  96. package/src/e2e_tests/{e2e-utils.ts → e2eUtils.ts} +11 -1
  97. package/src/e2e_tests/{extra-keybindings.spec.tsx → extraKeybindings.spec.tsx} +1 -3
  98. package/src/e2e_tests/historyNavigation.spec.tsx +315 -0
  99. package/src/e2e_tests/performanceTest.spec.tsx +158 -0
  100. package/src/e2e_tests/{sanity-checks.spec.tsx → sanityChecks.spec.tsx} +7 -22
  101. package/src/e2e_tests/signatureHelp.spec.tsx +380 -0
  102. package/src/e2e_tests/snippets.spec.tsx +92 -0
  103. package/src/e2e_tests/{syntax-highlighting.spec.tsx → syntaxHighlighting.spec.tsx} +1 -3
  104. package/src/e2e_tests/{syntax-validation.spec.tsx → syntaxValidation.spec.tsx} +6 -7
  105. package/src/{repl-mode.ts → historyNavigation.ts} +7 -30
  106. package/src/icons.ts +3 -0
  107. package/src/index.ts +5 -2
  108. package/src/lang-cypher/autocomplete.ts +107 -15
  109. package/src/lang-cypher/constants.ts +23 -0
  110. package/src/lang-cypher/contants.test.ts +6 -2
  111. package/src/lang-cypher/{create-cypher-theme.ts → createCypherTheme.ts} +41 -2
  112. package/src/lang-cypher/langCypher.ts +53 -0
  113. package/src/lang-cypher/lintWorker.ts +14 -0
  114. package/src/lang-cypher/parser-adapter.ts +145 -0
  115. package/src/lang-cypher/signatureHelp.ts +133 -0
  116. package/src/lang-cypher/syntaxValidation.ts +96 -0
  117. package/src/lang-cypher/utils.ts +9 -0
  118. package/src/{ndl-tokens-copy.test.ts → ndlTokensCopy.test.ts} +2 -1
  119. package/src/{neo4j-setup.tsx → neo4jSetup.tsx} +51 -1
  120. package/src/themes.ts +4 -2
  121. package/src/viteEnv.d.ts +1 -0
  122. package/dist/cjs/index.cjs +0 -1443
  123. package/dist/cjs/index.cjs.map +0 -7
  124. package/dist/esm/index.mjs +0 -1466
  125. package/dist/esm/index.mjs.map +0 -7
  126. package/dist/types/e2e_tests/mock-data.d.ts +0 -3779
  127. package/dist/types/index.d.ts +0 -4
  128. package/dist/types/lang-cypher/ParserAdapter.d.ts +0 -14
  129. package/dist/types/lang-cypher/autocomplete.d.ts +0 -3
  130. package/dist/types/lang-cypher/lang-cypher.d.ts +0 -7
  131. package/dist/types/lang-cypher/syntax-validation.d.ts +0 -3
  132. package/dist/types/repl-mode.d.ts +0 -8
  133. package/dist/types/tsconfig.tsbuildinfo +0 -1
  134. package/src/e2e_tests/auto-completion.spec.tsx +0 -232
  135. package/src/e2e_tests/history-navigation.spec.tsx +0 -144
  136. package/src/e2e_tests/mock-data.ts +0 -4310
  137. package/src/e2e_tests/performance-test.spec.tsx +0 -71
  138. package/src/lang-cypher/ParserAdapter.ts +0 -92
  139. package/src/lang-cypher/lang-cypher.ts +0 -32
  140. package/src/lang-cypher/syntax-validation.ts +0 -24
  141. /package/dist/{types/e2e_tests/auto-completion.spec.d.ts → CypherEditor.test.d.ts} +0 -0
  142. /package/dist/{types/e2e_tests/extra-keybindings.spec.d.ts → e2e_tests/autoCompletion.spec.d.ts} +0 -0
  143. /package/dist/{types/e2e_tests/history-navigation.spec.d.ts → e2e_tests/configuration.spec.d.ts} +0 -0
  144. /package/dist/{types/e2e_tests/performance-test.spec.d.ts → e2e_tests/debounce.spec.d.ts} +0 -0
  145. /package/dist/{types/e2e_tests/e2e-utils.d.ts → e2e_tests/e2eUtils.d.ts} +0 -0
  146. /package/dist/{types/e2e_tests/sanity-checks.spec.d.ts → e2e_tests/extraKeybindings.spec.d.ts} +0 -0
  147. /package/dist/{types/e2e_tests/syntax-highlighting.spec.d.ts → e2e_tests/historyNavigation.spec.d.ts} +0 -0
  148. /package/dist/{types/e2e_tests/syntax-validation.spec.d.ts → e2e_tests/sanityChecks.spec.d.ts} +0 -0
  149. /package/dist/{types/lang-cypher/contants.test.d.ts → e2e_tests/signatureHelp.spec.d.ts} +0 -0
  150. /package/dist/{types/ndl-tokens-copy.test.d.ts → e2e_tests/snippets.spec.d.ts} +0 -0
  151. /package/dist/{types/lang-cypher/create-cypher-theme.d.ts → lang-cypher/createCypherTheme.d.ts} +0 -0
  152. /package/dist/{types/lang-cypher/theme-icons.d.ts → lang-cypher/themeIcons.d.ts} +0 -0
  153. /package/dist/{types/ndl-tokens-copy.d.ts → ndlTokensCopy.d.ts} +0 -0
  154. /package/dist/{types/neo4j-setup.d.ts → neo4jSetup.d.ts} +0 -0
  155. /package/src/lang-cypher/{theme-icons.ts → themeIcons.ts} +0 -0
  156. /package/src/{ndl-tokens-copy.ts → ndlTokensCopy.ts} +0 -0
@@ -0,0 +1,472 @@
1
+ import { testData } from '@neo4j-cypher/language-support';
2
+ import { expect, test } from '@playwright/experimental-ct-react';
3
+ import type { Page } from '@playwright/test';
4
+ import { CypherEditor } from '../CypherEditor';
5
+
6
+ test('hello world end 2 end test', async ({ mount }) => {
7
+ const component = await mount(<CypherEditor value="hello world" />);
8
+ await expect(component).toContainText('hello world');
9
+ await component.update(<CypherEditor value="RETURN 123" />);
10
+ await expect(component).toContainText('RETURN 123');
11
+ });
12
+
13
+ test('can complete in the middle of statement', async ({ mount, page }) => {
14
+ const component = await mount(
15
+ <CypherEditor
16
+ value={`MATCH ()
17
+ WHER true
18
+ RETURN n;`}
19
+ />,
20
+ );
21
+
22
+ // Move into the statement and trigger autocompletion
23
+ const textField = page.getByRole('textbox');
24
+
25
+ await textField.focus();
26
+ await textField.press('ArrowDown');
27
+ await textField.press('ArrowRight');
28
+ await textField.press('ArrowRight');
29
+ await textField.press('ArrowRight');
30
+ await textField.press('ArrowRight');
31
+
32
+ await textField.press('Control+ ');
33
+
34
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
35
+ await page.locator('.cm-tooltip-autocomplete').getByText('WHERE').click();
36
+
37
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
38
+
39
+ await expect(component).toContainText('WHERE true');
40
+ });
41
+
42
+ test('get completions when typing and can accept completions with tab', async ({
43
+ mount,
44
+ page,
45
+ }) => {
46
+ const component = await mount(<CypherEditor />);
47
+ const textField = page.getByRole('textbox');
48
+
49
+ await textField.fill('RETU');
50
+
51
+ await expect(
52
+ page.locator('.cm-tooltip-autocomplete').getByText('RETURN'),
53
+ ).toBeVisible();
54
+
55
+ // We need to wait for the editor to realise there is a completion open
56
+ // so that it does not just indent with tab key
57
+ await page.waitForTimeout(500);
58
+ await textField.press('Tab');
59
+
60
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
61
+
62
+ await expect(component).toContainText('RETURN');
63
+ });
64
+
65
+ test('get completions when typing in controlled component', async ({
66
+ mount,
67
+ page,
68
+ }) => {
69
+ let value = '';
70
+ const onChange = (val: string) => {
71
+ value = val;
72
+ void component.update(<CypherEditor value={val} onChange={onChange} />);
73
+ };
74
+
75
+ const component = await mount(
76
+ <CypherEditor value={value} onChange={onChange} />,
77
+ );
78
+ const textField = page.getByRole('textbox');
79
+
80
+ await textField.fill('RETU');
81
+ await page.waitForTimeout(500); // wait for debounce
82
+
83
+ await expect(
84
+ page.locator('.cm-tooltip-autocomplete').getByText('RETURN'),
85
+ ).toBeVisible();
86
+
87
+ // We need to wait for the editor to realise there is a completion open
88
+ // so that it does not just indent with tab key
89
+ await page.waitForTimeout(500);
90
+ await textField.press('Tab');
91
+
92
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
93
+
94
+ await expect(component).toContainText('RETURN');
95
+ });
96
+
97
+ test('can complete labels', async ({ mount, page }) => {
98
+ const component = await mount(
99
+ <CypherEditor
100
+ schema={{
101
+ labels: ['Pokemon'],
102
+ }}
103
+ />,
104
+ );
105
+
106
+ const textField = page.getByRole('textbox');
107
+
108
+ await textField.fill('MATCH (n :P');
109
+
110
+ await page.locator('.cm-tooltip-autocomplete').getByText('Pokemon').click();
111
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
112
+
113
+ await expect(component).toContainText('MATCH (n :Pokemon');
114
+ });
115
+
116
+ test('can update dbschema', async ({ mount, page }) => {
117
+ const component = await mount(
118
+ <CypherEditor
119
+ schema={{
120
+ labels: ['Pokemon'],
121
+ }}
122
+ />,
123
+ );
124
+
125
+ const textField = page.getByRole('textbox');
126
+
127
+ await textField.fill('MATCH (n :');
128
+
129
+ await expect(
130
+ page.locator('.cm-tooltip-autocomplete').getByText('Pokemon'),
131
+ ).toBeVisible();
132
+
133
+ await textField.press('Escape');
134
+
135
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
136
+
137
+ await component.update(
138
+ <CypherEditor
139
+ schema={{
140
+ labels: ['Pokemon', 'Digimon'],
141
+ }}
142
+ />,
143
+ );
144
+
145
+ await textField.press('Control+ ');
146
+
147
+ await expect(
148
+ page.locator('.cm-tooltip-autocomplete').getByText('Pokemon'),
149
+ ).toBeVisible();
150
+
151
+ await expect(
152
+ page.locator('.cm-tooltip-autocomplete').getByText('Digimon'),
153
+ ).toBeVisible();
154
+ });
155
+
156
+ test('can complete rel types', async ({ page, mount }) => {
157
+ const component = await mount(
158
+ <CypherEditor
159
+ schema={{
160
+ relationshipTypes: ['KNOWS'],
161
+ }}
162
+ />,
163
+ );
164
+
165
+ const textField = page.getByRole('textbox');
166
+
167
+ await textField.fill('MATCH (n)-[:');
168
+
169
+ await page.locator('.cm-tooltip-autocomplete').getByText('KNOWS').click();
170
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
171
+
172
+ await expect(component).toContainText('MATCH (n)-[:KNOWS');
173
+ });
174
+
175
+ test('can complete functions', async ({ page, mount }) => {
176
+ const component = await mount(
177
+ <CypherEditor
178
+ schema={{
179
+ functions: {
180
+ function123: {
181
+ ...testData.emptyFunction,
182
+ name: 'function123',
183
+ },
184
+ },
185
+ }}
186
+ />,
187
+ );
188
+
189
+ const textField = page.getByRole('textbox');
190
+
191
+ await textField.fill('RETURN func');
192
+
193
+ await page
194
+ .locator('.cm-tooltip-autocomplete')
195
+ .getByText('function123')
196
+ .click();
197
+
198
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
199
+
200
+ await expect(component).toContainText('RETURN function123');
201
+ });
202
+
203
+ test('can complete procedures', async ({ page, mount }) => {
204
+ const component = await mount(
205
+ <CypherEditor
206
+ schema={{
207
+ procedures: {
208
+ 'db.ping': { ...testData.emptyProcedure, name: 'db.ping' },
209
+ },
210
+ }}
211
+ />,
212
+ );
213
+
214
+ const textField = page.getByRole('textbox');
215
+
216
+ await textField.fill('CALL d');
217
+
218
+ await page.locator('.cm-tooltip-autocomplete').getByText('db.ping').click();
219
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
220
+
221
+ await expect(component).toContainText('CALL db.ping');
222
+ });
223
+
224
+ test('can complete parameters', async ({ page, mount }) => {
225
+ const component = await mount(
226
+ <CypherEditor
227
+ schema={{
228
+ parameters: { parameter: { type: 'string' } },
229
+ }}
230
+ />,
231
+ );
232
+
233
+ const textField = page.getByRole('textbox');
234
+
235
+ await textField.fill('RETURN $p');
236
+
237
+ await page.locator('.cm-tooltip-autocomplete').getByText('parameter').click();
238
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
239
+
240
+ await expect(component).toContainText('RETURN $parameter');
241
+ });
242
+
243
+ test('completes allShortestPaths correctly', async ({ page, mount }) => {
244
+ await mount(
245
+ <CypherEditor
246
+ schema={{
247
+ parameters: { parameter: { type: 'string' } },
248
+ }}
249
+ />,
250
+ );
251
+
252
+ const textField = page.getByRole('textbox');
253
+
254
+ // The first query contains errors on purpose so the
255
+ // syntax errors get triggered before the auto-completion
256
+ await textField.fill('MATCH (n) REURN n; MATCH a');
257
+
258
+ await page
259
+ .locator('.cm-tooltip-autocomplete')
260
+ .getByText('allShortestPaths')
261
+ .click();
262
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
263
+
264
+ expect(await textField.textContent()).toEqual(
265
+ 'MATCH (n) REURN n; MATCH allShortestPaths',
266
+ );
267
+ });
268
+
269
+ async function getInfoTooltip(page: Page, methodName: string) {
270
+ const infoTooltip = page.locator('.cm-completionInfo');
271
+ const firstOption = page.locator('li[aria-selected="true"]');
272
+ let selectedOption = firstOption;
273
+
274
+ while (!(await infoTooltip.textContent()).includes(methodName)) {
275
+ await page.keyboard.press('ArrowDown');
276
+ const currentSelected = page.locator('li[aria-selected="true"]');
277
+ expect(currentSelected).not.toBe(selectedOption);
278
+ expect(currentSelected).not.toBe(firstOption);
279
+ selectedOption = currentSelected;
280
+ }
281
+
282
+ return infoTooltip;
283
+ }
284
+
285
+ test('shows signature help information on auto-completion for procedures', async ({
286
+ page,
287
+ mount,
288
+ }) => {
289
+ await mount(
290
+ <CypherEditor
291
+ schema={testData.mockSchema}
292
+ featureFlags={{
293
+ signatureInfoOnAutoCompletions: true,
294
+ }}
295
+ />,
296
+ );
297
+ const procName = 'apoc.periodic.iterate';
298
+ const procedure = testData.mockSchema.procedures[procName];
299
+
300
+ const textField = page.getByRole('textbox');
301
+ await textField.fill('CALL apoc.periodic.');
302
+
303
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
304
+
305
+ const infoTooltip = await getInfoTooltip(page, procName);
306
+ await expect(infoTooltip).toContainText(procedure.signature);
307
+ await expect(infoTooltip).toContainText(procedure.description);
308
+ });
309
+
310
+ test('shows signature help information on auto-completion for functions', async ({
311
+ page,
312
+ mount,
313
+ }) => {
314
+ await mount(
315
+ <CypherEditor
316
+ schema={testData.mockSchema}
317
+ featureFlags={{
318
+ signatureInfoOnAutoCompletions: true,
319
+ }}
320
+ />,
321
+ );
322
+ const fnName = 'apoc.coll.combinations';
323
+ const fn = testData.mockSchema.functions[fnName];
324
+
325
+ const textField = page.getByRole('textbox');
326
+ await textField.fill('RETURN apoc.coll.');
327
+
328
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
329
+
330
+ const infoTooltip = await getInfoTooltip(page, fnName);
331
+ await expect(infoTooltip).toContainText(fn.signature);
332
+ await expect(infoTooltip).toContainText(fn.description);
333
+ });
334
+
335
+ test('shows deprecated procedures as strikethrough on auto-completion', async ({
336
+ page,
337
+ mount,
338
+ }) => {
339
+ const procName = 'apoc.trigger.resume';
340
+
341
+ await mount(
342
+ <CypherEditor
343
+ schema={{
344
+ procedures: { [procName]: testData.mockSchema.procedures[procName] },
345
+ }}
346
+ featureFlags={{
347
+ signatureInfoOnAutoCompletions: true,
348
+ }}
349
+ />,
350
+ );
351
+ const textField = page.getByRole('textbox');
352
+ await textField.fill('CALL apoc.trigger.');
353
+
354
+ // We need to assert on the element having the right class
355
+ // and trusting the CSS is making this truly strikethrough
356
+ await expect(page.locator('.cm-deprecated-completion')).toBeVisible();
357
+ });
358
+
359
+ test('shows deprecated function as strikethrough on auto-completion', async ({
360
+ page,
361
+ mount,
362
+ }) => {
363
+ const fnName = 'apoc.create.uuid';
364
+
365
+ await mount(
366
+ <CypherEditor
367
+ schema={{
368
+ functions: { [fnName]: testData.mockSchema.functions[fnName] },
369
+ }}
370
+ featureFlags={{
371
+ signatureInfoOnAutoCompletions: true,
372
+ }}
373
+ />,
374
+ );
375
+ const textField = page.getByRole('textbox');
376
+ await textField.fill('RETURN apoc.create.');
377
+
378
+ // We need to assert on the element having the right class
379
+ // and trusting the CSS is making this truly strikethrough
380
+ await expect(page.locator('.cm-deprecated-completion')).toBeVisible();
381
+ });
382
+
383
+ test('does not signature help information on auto-completion if flag not enabled explicitly', async ({
384
+ page,
385
+ mount,
386
+ }) => {
387
+ await mount(<CypherEditor schema={testData.mockSchema} />);
388
+
389
+ const textField = page.getByRole('textbox');
390
+ await textField.fill('CALL apoc.periodic.');
391
+
392
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
393
+ await expect(page.locator('.cm-completionInfo')).not.toBeVisible();
394
+ });
395
+
396
+ test('does not signature help information on auto-completion if docs and signature are empty', async ({
397
+ page,
398
+ mount,
399
+ }) => {
400
+ await mount(
401
+ <CypherEditor
402
+ schema={testData.mockSchema}
403
+ featureFlags={{
404
+ signatureInfoOnAutoCompletions: true,
405
+ }}
406
+ />,
407
+ );
408
+
409
+ const textField = page.getByRole('textbox');
410
+ await textField.fill('C');
411
+
412
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
413
+ await expect(page.locator('.cm-completionInfo')).not.toBeVisible();
414
+ });
415
+
416
+ test('shows signature help information on auto-completion if description is not empty, signature is', async ({
417
+ page,
418
+ mount,
419
+ }) => {
420
+ await mount(
421
+ <CypherEditor
422
+ schema={{
423
+ procedures: {
424
+ 'db.ping': {
425
+ ...testData.emptyProcedure,
426
+ description: 'foo',
427
+ signature: '',
428
+ name: 'db.ping',
429
+ },
430
+ },
431
+ }}
432
+ featureFlags={{
433
+ signatureInfoOnAutoCompletions: true,
434
+ }}
435
+ />,
436
+ );
437
+
438
+ const textField = page.getByRole('textbox');
439
+ await textField.fill('CALL db.');
440
+
441
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
442
+ await expect(page.locator('.cm-completionInfo')).toBeVisible();
443
+ });
444
+
445
+ test('shows signature help information on auto-completion if signature is not empty, description is', async ({
446
+ page,
447
+ mount,
448
+ }) => {
449
+ await mount(
450
+ <CypherEditor
451
+ schema={{
452
+ procedures: {
453
+ 'db.ping': {
454
+ ...testData.emptyProcedure,
455
+ description: '',
456
+ signature: 'foo',
457
+ name: 'db.ping',
458
+ },
459
+ },
460
+ }}
461
+ featureFlags={{
462
+ signatureInfoOnAutoCompletions: true,
463
+ }}
464
+ />,
465
+ );
466
+
467
+ const textField = page.getByRole('textbox');
468
+ await textField.fill('CALL db.');
469
+
470
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
471
+ await expect(page.locator('.cm-completionInfo')).toBeVisible();
472
+ });
@@ -0,0 +1,111 @@
1
+ import { expect, test } from '@playwright/experimental-ct-react';
2
+ import { CypherEditor } from '../CypherEditor';
3
+
4
+ test('prompt shows up', async ({ mount, page }) => {
5
+ const component = await mount(<CypherEditor prompt="neo4j>" />);
6
+
7
+ await expect(component).toContainText('neo4j>');
8
+
9
+ await component.update(<CypherEditor prompt="test>" />);
10
+ await expect(component).toContainText('test>');
11
+
12
+ const textField = page.getByRole('textbox');
13
+ await textField.press('a');
14
+
15
+ await expect(textField).toHaveText('a');
16
+ });
17
+
18
+ test('line numbers can be turned on/off', async ({ mount }) => {
19
+ const component = await mount(<CypherEditor lineNumbers />);
20
+
21
+ await expect(component).toContainText('1');
22
+
23
+ await component.update(<CypherEditor lineNumbers={false} />);
24
+ await expect(component).not.toContainText('1');
25
+ });
26
+
27
+ test('can configure readonly', async ({ mount, page }) => {
28
+ const component = await mount(<CypherEditor readonly />);
29
+
30
+ const textField = page.getByRole('textbox');
31
+ await textField.press('a');
32
+ await expect(textField).not.toHaveText('a');
33
+
34
+ await component.update(<CypherEditor readonly={false} />);
35
+ await textField.press('b');
36
+ await expect(textField).toHaveText('b');
37
+ });
38
+
39
+ test('can set placeholder ', async ({ mount, page }) => {
40
+ const component = await mount(<CypherEditor placeholder="bulbasaur" />);
41
+
42
+ const textField = page.getByRole('textbox');
43
+ await expect(textField).toHaveText('bulbasaur');
44
+
45
+ await component.update(<CypherEditor placeholder="venusaur" />);
46
+ await expect(textField).not.toHaveText('bulbasaur');
47
+ await expect(textField).toHaveText('venusaur');
48
+
49
+ await textField.fill('abc');
50
+ await expect(textField).not.toHaveText('venusaur');
51
+ await expect(textField).toHaveText('abc');
52
+ });
53
+
54
+ test('can set/unset onFocus/onBlur', async ({ mount, page }) => {
55
+ const component = await mount(<CypherEditor />);
56
+
57
+ let focusFireCount = 0;
58
+ let blurFireCount = 0;
59
+
60
+ const focus = () => {
61
+ focusFireCount += 1;
62
+ };
63
+ const blur = () => {
64
+ blurFireCount += 1;
65
+ };
66
+
67
+ await component.update(<CypherEditor domEventHandlers={{ blur, focus }} />);
68
+
69
+ const textField = page.getByRole('textbox');
70
+ await textField.click();
71
+ await expect(textField).toBeFocused();
72
+
73
+ // this is to give the events time to fire
74
+ await expect(() => {
75
+ expect(focusFireCount).toBe(1);
76
+ expect(blurFireCount).toBe(0);
77
+ }).toPass();
78
+
79
+ await textField.blur();
80
+
81
+ await expect(() => {
82
+ expect(focusFireCount).toBe(1);
83
+ expect(blurFireCount).toBe(1);
84
+ }).toPass();
85
+
86
+ await component.update(<CypherEditor />);
87
+ await textField.click();
88
+ await expect(textField).toBeFocused();
89
+ await textField.blur();
90
+
91
+ await expect(() => {
92
+ expect(focusFireCount).toBe(1);
93
+ expect(blurFireCount).toBe(1);
94
+ }).toPass();
95
+ });
96
+
97
+ test('aria-label is not set by default', async ({ mount, page }) => {
98
+ await mount(<CypherEditor />);
99
+
100
+ const textField = page.getByRole('textbox');
101
+ expect(await textField.getAttribute('aria-label')).toBeNull();
102
+ });
103
+
104
+ test('can set aria-label', async ({ mount, page }) => {
105
+ const ariaLabel = 'Cypher Editor';
106
+
107
+ await mount(<CypherEditor ariaLabel={ariaLabel} />);
108
+
109
+ const textField = page.getByRole('textbox');
110
+ expect(await textField.getAttribute('aria-label')).toEqual(ariaLabel);
111
+ });
@@ -0,0 +1,101 @@
1
+ import { expect, test } from '@playwright/experimental-ct-react';
2
+ import { DEBOUNCE_TIME } from '../constants';
3
+ import { CypherEditor } from '../CypherEditor';
4
+ import { CypherEditorPage } from './e2eUtils';
5
+
6
+ const DEBOUNCE_TIME_WITH_MARGIN = DEBOUNCE_TIME + 100;
7
+ // value updates from outside onExecute are overwritten by pending updates
8
+ test.fail(
9
+ 'external updates should override debounced updates',
10
+ async ({ mount, page }) => {
11
+ const editorPage = new CypherEditorPage(page);
12
+ let value = '';
13
+
14
+ const onChange = (val: string) => {
15
+ value = val;
16
+ void component.update(<CypherEditor value={val} onChange={onChange} />);
17
+ };
18
+
19
+ const component = await mount(
20
+ <CypherEditor value={value} onChange={onChange} />,
21
+ );
22
+
23
+ await editorPage.getEditor().pressSequentially('RETURN 1');
24
+ onChange('foo');
25
+ await page.waitForTimeout(DEBOUNCE_TIME_WITH_MARGIN);
26
+ await expect(component).toContainText('foo');
27
+ },
28
+ );
29
+
30
+ test('onExecute updates should override debounce updates', async ({
31
+ mount,
32
+ page,
33
+ }) => {
34
+ const editorPage = new CypherEditorPage(page);
35
+ let value = '';
36
+
37
+ const onExecute = () => {
38
+ value = '';
39
+ void component.update(
40
+ <CypherEditor value={value} onChange={onChange} onExecute={onExecute} />,
41
+ );
42
+ };
43
+
44
+ const onChange = (val: string) => {
45
+ value = val;
46
+ void component.update(
47
+ <CypherEditor value={val} onChange={onChange} onExecute={onExecute} />,
48
+ );
49
+ };
50
+
51
+ const component = await mount(
52
+ <CypherEditor value={value} onChange={onChange} onExecute={onExecute} />,
53
+ );
54
+
55
+ await editorPage.getEditor().pressSequentially('RETURN 1');
56
+ await editorPage.getEditor().press('Enter');
57
+ await page.waitForTimeout(DEBOUNCE_TIME_WITH_MARGIN);
58
+ await expect(component).not.toContainText('RETURN 1');
59
+
60
+ await editorPage.getEditor().pressSequentially('RETURN 1');
61
+ await editorPage.getEditor().pressSequentially('');
62
+ await editorPage.getEditor().pressSequentially('RETURN 1');
63
+ await editorPage.getEditor().press('Enter');
64
+ await page.waitForTimeout(DEBOUNCE_TIME_WITH_MARGIN);
65
+ await expect(component).not.toContainText('RETURN 1');
66
+ });
67
+
68
+ test('onExecute should fire after debounced updates', async ({
69
+ mount,
70
+ page,
71
+ }) => {
72
+ const editorPage = new CypherEditorPage(page);
73
+ let value = '';
74
+ let executedCommand = '';
75
+
76
+ const onExecute = (cmd: string) => {
77
+ executedCommand = cmd;
78
+ void component.update(
79
+ <CypherEditor value={value} onChange={onChange} onExecute={onExecute} />,
80
+ );
81
+ };
82
+
83
+ const onChange = (val: string) => {
84
+ value = val;
85
+ void component.update(
86
+ <CypherEditor value={val} onChange={onChange} onExecute={onExecute} />,
87
+ );
88
+ };
89
+
90
+ const component = await mount(
91
+ <CypherEditor value={value} onChange={onChange} onExecute={onExecute} />,
92
+ );
93
+
94
+ await editorPage.getEditor().fill('RETURN 1');
95
+ await editorPage.getEditor().press('Enter');
96
+ await editorPage.getEditor().fill('RETURN 2');
97
+ await editorPage.getEditor().press('Enter');
98
+ await page.waitForTimeout(DEBOUNCE_TIME_WITH_MARGIN);
99
+ await expect(component).toContainText('RETURN 2');
100
+ expect(executedCommand).toBe('RETURN 2');
101
+ });
@@ -65,11 +65,21 @@ export class CypherEditorPage {
65
65
  expectedMsg: string,
66
66
  ) {
67
67
  await expect(this.page.locator('.cm-lintRange-' + type).last()).toBeVisible(
68
- { timeout: 2000 },
68
+ { timeout: 3000 },
69
69
  );
70
70
 
71
71
  await this.page.getByText(queryChunk, { exact: true }).hover();
72
72
  await expect(this.page.locator('.cm-tooltip-hover').last()).toBeVisible();
73
73
  await expect(this.page.getByText(expectedMsg)).toBeVisible();
74
+ /* Return the mouse to the beginning of the query and
75
+ This is because if for example we have an overlay with a
76
+ first interaction that covers the element we want to perform
77
+ the second interaction on, we won't be able to see that second element
78
+ */
79
+ await this.page.mouse.move(0, 0);
80
+ // Make the sure the tooltip closed
81
+ await expect(
82
+ this.page.locator('.cm-tooltip-hover').last(),
83
+ ).not.toBeVisible();
74
84
  }
75
85
  }