@neo4j-cypher/react-codemirror 2.0.0-next.3 → 2.0.0-next.30

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 (163) hide show
  1. package/CHANGELOG.md +257 -0
  2. package/README.md +3 -2
  3. package/dist/{types → src}/CypherEditor.d.ts +81 -3
  4. package/dist/src/CypherEditor.js +336 -0
  5. package/dist/src/CypherEditor.js.map +1 -0
  6. package/dist/src/CypherEditor.test.js +154 -0
  7. package/dist/src/CypherEditor.test.js.map +1 -0
  8. package/dist/src/constants.d.ts +1 -0
  9. package/dist/src/constants.js +2 -0
  10. package/dist/src/constants.js.map +1 -0
  11. package/dist/src/e2e_tests/autoCompletion.spec.js +332 -0
  12. package/dist/src/e2e_tests/autoCompletion.spec.js.map +1 -0
  13. package/dist/src/e2e_tests/configuration.spec.js +83 -0
  14. package/dist/src/e2e_tests/configuration.spec.js.map +1 -0
  15. package/dist/src/e2e_tests/debounce.spec.js +66 -0
  16. package/dist/src/e2e_tests/debounce.spec.js.map +1 -0
  17. package/dist/{types/e2e_tests/e2e-utils.d.ts → src/e2e_tests/e2eUtils.d.ts} +2 -0
  18. package/dist/src/e2e_tests/e2eUtils.js +79 -0
  19. package/dist/src/e2e_tests/e2eUtils.js.map +1 -0
  20. package/dist/src/e2e_tests/extraKeybindings.spec.js +43 -0
  21. package/dist/src/e2e_tests/extraKeybindings.spec.js.map +1 -0
  22. package/dist/src/e2e_tests/historyNavigation.spec.js +227 -0
  23. package/dist/src/e2e_tests/historyNavigation.spec.js.map +1 -0
  24. package/dist/src/e2e_tests/performanceTest.spec.d.ts +6 -0
  25. package/dist/src/e2e_tests/performanceTest.spec.js +97 -0
  26. package/dist/src/e2e_tests/performanceTest.spec.js.map +1 -0
  27. package/dist/src/e2e_tests/sanityChecks.spec.js +53 -0
  28. package/dist/src/e2e_tests/sanityChecks.spec.js.map +1 -0
  29. package/dist/src/e2e_tests/signatureHelp.spec.js +228 -0
  30. package/dist/src/e2e_tests/signatureHelp.spec.js.map +1 -0
  31. package/dist/src/e2e_tests/snippets.spec.js +62 -0
  32. package/dist/src/e2e_tests/snippets.spec.js.map +1 -0
  33. package/dist/src/e2e_tests/syntaxHighlighting.spec.d.ts +1 -0
  34. package/dist/src/e2e_tests/syntaxHighlighting.spec.js +90 -0
  35. package/dist/src/e2e_tests/syntaxHighlighting.spec.js.map +1 -0
  36. package/dist/src/e2e_tests/syntaxValidation.spec.d.ts +1 -0
  37. package/dist/src/e2e_tests/syntaxValidation.spec.js +126 -0
  38. package/dist/src/e2e_tests/syntaxValidation.spec.js.map +1 -0
  39. package/dist/src/historyNavigation.js +163 -0
  40. package/dist/src/historyNavigation.js.map +1 -0
  41. package/dist/{types → src}/icons.d.ts +1 -1
  42. package/dist/src/icons.js +62 -0
  43. package/dist/src/icons.js.map +1 -0
  44. package/dist/src/index.d.ts +4 -0
  45. package/dist/src/index.js +5 -0
  46. package/dist/src/index.js.map +1 -0
  47. package/dist/src/lang-cypher/autocomplete.d.ts +6 -0
  48. package/dist/src/lang-cypher/autocomplete.js +113 -0
  49. package/dist/src/lang-cypher/autocomplete.js.map +1 -0
  50. package/dist/{types → src}/lang-cypher/constants.d.ts +11 -0
  51. package/dist/src/lang-cypher/constants.js +69 -0
  52. package/dist/src/lang-cypher/constants.js.map +1 -0
  53. package/dist/src/lang-cypher/contants.test.d.ts +1 -0
  54. package/dist/src/lang-cypher/contants.test.js +103 -0
  55. package/dist/src/lang-cypher/contants.test.js.map +1 -0
  56. package/dist/src/lang-cypher/createCypherTheme.js +183 -0
  57. package/dist/src/lang-cypher/createCypherTheme.js.map +1 -0
  58. package/dist/src/lang-cypher/langCypher.d.ts +13 -0
  59. package/dist/src/lang-cypher/langCypher.js +23 -0
  60. package/dist/src/lang-cypher/langCypher.js.map +1 -0
  61. package/dist/src/lang-cypher/lintWorker.mjs +2022 -0
  62. package/dist/src/lang-cypher/parser-adapter.d.ts +19 -0
  63. package/dist/src/lang-cypher/parser-adapter.js +113 -0
  64. package/dist/src/lang-cypher/parser-adapter.js.map +1 -0
  65. package/dist/src/lang-cypher/signatureHelp.d.ts +4 -0
  66. package/dist/src/lang-cypher/signatureHelp.js +109 -0
  67. package/dist/src/lang-cypher/signatureHelp.js.map +1 -0
  68. package/dist/{types/lang-cypher/syntax-validation.d.ts → src/lang-cypher/syntaxValidation.d.ts} +2 -1
  69. package/dist/src/lang-cypher/syntaxValidation.js +57 -0
  70. package/dist/src/lang-cypher/syntaxValidation.js.map +1 -0
  71. package/dist/src/lang-cypher/themeIcons.js +22 -0
  72. package/dist/src/lang-cypher/themeIcons.js.map +1 -0
  73. package/dist/src/lang-cypher/utils.d.ts +2 -0
  74. package/dist/src/lang-cypher/utils.js +10 -0
  75. package/dist/src/lang-cypher/utils.js.map +1 -0
  76. package/dist/src/ndlTokensCopy.d.ts +570 -0
  77. package/dist/src/ndlTokensCopy.js +571 -0
  78. package/dist/src/ndlTokensCopy.js.map +1 -0
  79. package/dist/src/ndlTokensCopy.test.d.ts +1 -0
  80. package/dist/src/ndlTokensCopy.test.js +12 -0
  81. package/dist/src/ndlTokensCopy.test.js.map +1 -0
  82. package/dist/src/neo4jSetup.d.ts +6 -0
  83. package/dist/src/neo4jSetup.js +120 -0
  84. package/dist/src/neo4jSetup.js.map +1 -0
  85. package/dist/src/richClipboardCopier.d.ts +4 -0
  86. package/dist/src/richClipboardCopier.js +78 -0
  87. package/dist/src/richClipboardCopier.js.map +1 -0
  88. package/dist/src/richClipboardCopier.test.d.ts +1 -0
  89. package/dist/src/richClipboardCopier.test.js +53 -0
  90. package/dist/src/richClipboardCopier.test.js.map +1 -0
  91. package/dist/{types → src}/themes.d.ts +1 -1
  92. package/dist/src/themes.js +93 -0
  93. package/dist/src/themes.js.map +1 -0
  94. package/dist/tsconfig.tsbuildinfo +1 -0
  95. package/package.json +43 -41
  96. package/src/CypherEditor.test.tsx +204 -0
  97. package/src/CypherEditor.tsx +316 -42
  98. package/src/constants.ts +1 -0
  99. package/src/e2e_tests/autoCompletion.spec.tsx +571 -0
  100. package/src/e2e_tests/configuration.spec.tsx +111 -0
  101. package/src/e2e_tests/debounce.spec.tsx +106 -0
  102. package/src/e2e_tests/{e2e-utils.ts → e2eUtils.ts} +41 -3
  103. package/src/e2e_tests/{extra-keybindings.spec.tsx → extraKeybindings.spec.tsx} +1 -3
  104. package/src/e2e_tests/{history-navigation.spec.tsx → historyNavigation.spec.tsx} +137 -18
  105. package/src/e2e_tests/performanceTest.spec.tsx +163 -0
  106. package/src/e2e_tests/{sanity-checks.spec.tsx → sanityChecks.spec.tsx} +7 -22
  107. package/src/e2e_tests/signatureHelp.spec.tsx +444 -0
  108. package/src/e2e_tests/snippets.spec.tsx +92 -0
  109. package/src/e2e_tests/{syntax-highlighting.spec.tsx → syntaxHighlighting.spec.tsx} +26 -24
  110. package/src/e2e_tests/syntaxValidation.spec.tsx +259 -0
  111. package/src/{history-navigation.ts → historyNavigation.ts} +1 -1
  112. package/src/icons.ts +3 -0
  113. package/src/index.ts +2 -2
  114. package/src/lang-cypher/autocomplete.ts +99 -18
  115. package/src/lang-cypher/constants.ts +27 -0
  116. package/src/lang-cypher/contants.test.ts +6 -2
  117. package/src/lang-cypher/{create-cypher-theme.ts → createCypherTheme.ts} +45 -2
  118. package/src/lang-cypher/langCypher.ts +42 -0
  119. package/src/lang-cypher/lintWorker.mjs +2022 -0
  120. package/src/lang-cypher/parser-adapter.ts +145 -0
  121. package/src/lang-cypher/signatureHelp.ts +151 -0
  122. package/src/lang-cypher/syntaxValidation.ts +72 -0
  123. package/src/lang-cypher/utils.ts +9 -0
  124. package/src/{ndl-tokens-copy.test.ts → ndlTokensCopy.test.ts} +2 -1
  125. package/src/ndlTokensCopy.ts +570 -0
  126. package/src/{neo4j-setup.tsx → neo4jSetup.tsx} +78 -17
  127. package/src/richClipboardCopier.test.ts +65 -0
  128. package/src/richClipboardCopier.ts +99 -0
  129. package/src/themes.ts +45 -70
  130. package/src/viteEnv.d.ts +1 -0
  131. package/dist/cjs/index.cjs +0 -1440
  132. package/dist/cjs/index.cjs.map +0 -7
  133. package/dist/esm/index.mjs +0 -1463
  134. package/dist/esm/index.mjs.map +0 -7
  135. package/dist/types/e2e_tests/mock-data.d.ts +0 -3779
  136. package/dist/types/index.d.ts +0 -4
  137. package/dist/types/lang-cypher/ParserAdapter.d.ts +0 -14
  138. package/dist/types/lang-cypher/autocomplete.d.ts +0 -3
  139. package/dist/types/lang-cypher/lang-cypher.d.ts +0 -7
  140. package/dist/types/ndl-tokens-copy.d.ts +0 -379
  141. package/dist/types/neo4j-setup.d.ts +0 -2
  142. package/dist/types/tsconfig.tsbuildinfo +0 -1
  143. package/src/e2e_tests/auto-completion.spec.tsx +0 -232
  144. package/src/e2e_tests/mock-data.ts +0 -4310
  145. package/src/e2e_tests/performance-test.spec.tsx +0 -71
  146. package/src/e2e_tests/syntax-validation.spec.tsx +0 -156
  147. package/src/lang-cypher/ParserAdapter.ts +0 -92
  148. package/src/lang-cypher/lang-cypher.ts +0 -32
  149. package/src/lang-cypher/syntax-validation.ts +0 -24
  150. package/src/ndl-tokens-copy.ts +0 -379
  151. /package/dist/{types/e2e_tests/auto-completion.spec.d.ts → src/CypherEditor.test.d.ts} +0 -0
  152. /package/dist/{types/e2e_tests/extra-keybindings.spec.d.ts → src/e2e_tests/autoCompletion.spec.d.ts} +0 -0
  153. /package/dist/{types/e2e_tests/history-navigation.spec.d.ts → src/e2e_tests/configuration.spec.d.ts} +0 -0
  154. /package/dist/{types/e2e_tests/performance-test.spec.d.ts → src/e2e_tests/debounce.spec.d.ts} +0 -0
  155. /package/dist/{types/e2e_tests/sanity-checks.spec.d.ts → src/e2e_tests/extraKeybindings.spec.d.ts} +0 -0
  156. /package/dist/{types/e2e_tests/syntax-highlighting.spec.d.ts → src/e2e_tests/historyNavigation.spec.d.ts} +0 -0
  157. /package/dist/{types/e2e_tests/syntax-validation.spec.d.ts → src/e2e_tests/sanityChecks.spec.d.ts} +0 -0
  158. /package/dist/{types/lang-cypher/contants.test.d.ts → src/e2e_tests/signatureHelp.spec.d.ts} +0 -0
  159. /package/dist/{types/ndl-tokens-copy.test.d.ts → src/e2e_tests/snippets.spec.d.ts} +0 -0
  160. /package/dist/{types/history-navigation.d.ts → src/historyNavigation.d.ts} +0 -0
  161. /package/dist/{types/lang-cypher/create-cypher-theme.d.ts → src/lang-cypher/createCypherTheme.d.ts} +0 -0
  162. /package/dist/{types/lang-cypher/theme-icons.d.ts → src/lang-cypher/themeIcons.d.ts} +0 -0
  163. /package/src/lang-cypher/{theme-icons.ts → themeIcons.ts} +0 -0
@@ -0,0 +1,571 @@
1
+ /* eslint-disable @typescript-eslint/unbound-method */
2
+ import { testData } from '@neo4j-cypher/language-support';
3
+ import { expect, test } from '@playwright/experimental-ct-react';
4
+ import type { Page } from '@playwright/test';
5
+ import { CypherEditor } from '../CypherEditor';
6
+
7
+ test('hello world end 2 end test', async ({ mount }) => {
8
+ const component = await mount(<CypherEditor value="hello world" />);
9
+ await expect(component).toContainText('hello world');
10
+ await component.update(<CypherEditor value="RETURN 123" />);
11
+ await expect(component).toContainText('RETURN 123');
12
+ });
13
+
14
+ test('can complete in the middle of statement', async ({ mount, page }) => {
15
+ const component = await mount(
16
+ <CypherEditor
17
+ value={`MATCH ()
18
+ WHER true
19
+ RETURN n;`}
20
+ />,
21
+ );
22
+
23
+ // Move into the statement and trigger autocompletion
24
+ const textField = page.getByRole('textbox');
25
+
26
+ await textField.focus();
27
+ await textField.press('ArrowDown');
28
+ await textField.press('ArrowRight');
29
+ await textField.press('ArrowRight');
30
+ await textField.press('ArrowRight');
31
+ await textField.press('ArrowRight');
32
+
33
+ await textField.press('Control+ ');
34
+
35
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
36
+ await page.locator('.cm-tooltip-autocomplete').getByText('WHERE', {exact: true}).click();
37
+
38
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
39
+
40
+ await expect(component).toContainText('WHERE true');
41
+ });
42
+
43
+ test('get completions when typing and can accept completions with tab', async ({
44
+ mount,
45
+ page,
46
+ }) => {
47
+ const component = await mount(<CypherEditor />);
48
+ const textField = page.getByRole('textbox');
49
+
50
+ await textField.fill('RETU');
51
+
52
+ await expect(
53
+ page.locator('.cm-tooltip-autocomplete').getByText('RETURN'),
54
+ ).toBeVisible();
55
+
56
+ // We need to wait for the editor to realise there is a completion open
57
+ // so that it does not just indent with tab key
58
+ await page.waitForTimeout(500);
59
+ await textField.press('Tab');
60
+
61
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
62
+
63
+ await expect(component).toContainText('RETURN');
64
+ });
65
+
66
+ test('get completions when typing in controlled component', async ({
67
+ mount,
68
+ page,
69
+ }) => {
70
+ let value = '';
71
+ const onChange = (val: string) => {
72
+ value = val;
73
+ void component.update(<CypherEditor value={val} onChange={onChange} />);
74
+ };
75
+
76
+ const component = await mount(
77
+ <CypherEditor value={value} onChange={onChange} />,
78
+ );
79
+ const textField = page.getByRole('textbox');
80
+
81
+ await textField.fill('RETU');
82
+ await page.waitForTimeout(500); // wait for debounce
83
+
84
+ await expect(
85
+ page.locator('.cm-tooltip-autocomplete').getByText('RETURN'),
86
+ ).toBeVisible();
87
+
88
+ // We need to wait for the editor to realise there is a completion open
89
+ // so that it does not just indent with tab key
90
+ await page.waitForTimeout(500);
91
+ await textField.press('Tab');
92
+
93
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
94
+
95
+ await expect(component).toContainText('RETURN');
96
+ });
97
+
98
+ test('can complete labels', async ({ mount, page }) => {
99
+ const component = await mount(
100
+ <CypherEditor
101
+ schema={{
102
+ labels: ['Pokemon'],
103
+ }}
104
+ />,
105
+ );
106
+
107
+ const textField = page.getByRole('textbox');
108
+
109
+ await textField.fill('MATCH (n :P');
110
+
111
+ await page.locator('.cm-tooltip-autocomplete').getByText('Pokemon').click();
112
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
113
+
114
+ await expect(component).toContainText('MATCH (n :Pokemon');
115
+ });
116
+
117
+ test('can complete properties with backticks', async ({ mount, page }) => {
118
+ const component = await mount(
119
+ <CypherEditor
120
+ schema={{
121
+ propertyKeys: ['foo bar'],
122
+ }}
123
+ />,
124
+ );
125
+
126
+ const textField = page.getByRole('textbox');
127
+
128
+ await textField.fill('MATCH (n) RETURN n.foo');
129
+ await textField.press('Escape');
130
+ await textField.press('Control+ ');
131
+
132
+ await page.locator('.cm-tooltip-autocomplete').getByText('foo bar').click();
133
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
134
+
135
+ await expect(component).toContainText('MATCH (n) RETURN n.`foo bar`');
136
+ });
137
+
138
+ test('can update dbschema', async ({ mount, page }) => {
139
+ const component = await mount(
140
+ <CypherEditor
141
+ schema={{
142
+ labels: ['Pokemon'],
143
+ }}
144
+ />,
145
+ );
146
+
147
+ const textField = page.getByRole('textbox');
148
+
149
+ await textField.fill('MATCH (n :');
150
+
151
+ await expect(
152
+ page.locator('.cm-tooltip-autocomplete').getByText('Pokemon'),
153
+ ).toBeVisible();
154
+
155
+ await textField.press('Escape');
156
+
157
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
158
+
159
+ await component.update(
160
+ <CypherEditor
161
+ schema={{
162
+ labels: ['Pokemon', 'Digimon'],
163
+ }}
164
+ />,
165
+ );
166
+
167
+ await textField.press('Control+ ');
168
+
169
+ await expect(
170
+ page.locator('.cm-tooltip-autocomplete').getByText('Pokemon'),
171
+ ).toBeVisible();
172
+
173
+ await expect(
174
+ page.locator('.cm-tooltip-autocomplete').getByText('Digimon'),
175
+ ).toBeVisible();
176
+ });
177
+
178
+ test('can complete rel types', async ({ page, mount }) => {
179
+ const component = await mount(
180
+ <CypherEditor
181
+ schema={{
182
+ relationshipTypes: ['KNOWS'],
183
+ }}
184
+ />,
185
+ );
186
+
187
+ const textField = page.getByRole('textbox');
188
+
189
+ await textField.fill('MATCH (n)-[:');
190
+
191
+ await page.locator('.cm-tooltip-autocomplete').getByText('KNOWS').click();
192
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
193
+
194
+ await expect(component).toContainText('MATCH (n)-[:KNOWS');
195
+ });
196
+
197
+ test('can complete YIELD clauses without manual trigger', async ({
198
+ page,
199
+ mount,
200
+ }) => {
201
+ const component = await mount(
202
+ <CypherEditor
203
+ schema={{
204
+ procedures: testData.mockSchema.procedures,
205
+ }}
206
+ />,
207
+ );
208
+
209
+ const textField = page.getByRole('textbox');
210
+
211
+ await textField.fill('CALL dbms.components() YIELD ');
212
+
213
+ await page.locator('.cm-tooltip-autocomplete').getByText('edition').click();
214
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
215
+
216
+ await expect(component).toContainText('CALL dbms.components() YIELD edition');
217
+ });
218
+
219
+ test('automatic yield trigger is not case sensitive', async ({
220
+ page,
221
+ mount,
222
+ }) => {
223
+ const component = await mount(
224
+ <CypherEditor
225
+ schema={{
226
+ procedures: testData.mockSchema.procedures,
227
+ }}
228
+ />,
229
+ );
230
+
231
+ const textField = page.getByRole('textbox');
232
+
233
+ await textField.fill('CALL dbms.components() yIeLd ');
234
+
235
+ await page.locator('.cm-tooltip-autocomplete').getByText('edition').click();
236
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
237
+
238
+ await expect(component).toContainText('CALL dbms.components() yIeLd edition');
239
+ });
240
+
241
+ test('can complete functions', async ({ page, mount }) => {
242
+ const component = await mount(
243
+ <CypherEditor
244
+ schema={{
245
+ functions: {
246
+ 'CYPHER 5': {
247
+ function123: {
248
+ ...testData.emptyFunction,
249
+ name: 'function123',
250
+ },
251
+ },
252
+ },
253
+ }}
254
+ />,
255
+ );
256
+
257
+ const textField = page.getByRole('textbox');
258
+
259
+ await textField.fill('RETURN func');
260
+
261
+ await page
262
+ .locator('.cm-tooltip-autocomplete')
263
+ .getByText('function123')
264
+ .click();
265
+
266
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
267
+
268
+ await expect(component).toContainText('RETURN function123');
269
+ });
270
+
271
+ test('can complete procedures', async ({ page, mount }) => {
272
+ const component = await mount(
273
+ <CypherEditor
274
+ schema={{
275
+ procedures: {
276
+ 'CYPHER 5': {
277
+ 'db.ping': { ...testData.emptyProcedure, name: 'db.ping' },
278
+ },
279
+ },
280
+ }}
281
+ />,
282
+ );
283
+
284
+ const textField = page.getByRole('textbox');
285
+
286
+ await textField.fill('CALL d');
287
+
288
+ await page.locator('.cm-tooltip-autocomplete').getByText('db.ping').click();
289
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
290
+
291
+ await expect(component).toContainText('CALL db.ping');
292
+ });
293
+
294
+ test('can complete parameters', async ({ page, mount }) => {
295
+ const component = await mount(
296
+ <CypherEditor
297
+ schema={{
298
+ parameters: { parameter: { type: 'string' } },
299
+ }}
300
+ />,
301
+ );
302
+
303
+ const textField = page.getByRole('textbox');
304
+
305
+ await textField.fill('RETURN $p');
306
+
307
+ await page.locator('.cm-tooltip-autocomplete').getByText('parameter').click();
308
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
309
+
310
+ await expect(component).toContainText('RETURN $parameter');
311
+ });
312
+
313
+ test('completes allShortestPaths correctly', async ({ page, mount }) => {
314
+ await mount(
315
+ <CypherEditor
316
+ schema={{
317
+ parameters: { parameter: { type: 'string' } },
318
+ }}
319
+ />,
320
+ );
321
+
322
+ const textField = page.getByRole('textbox');
323
+
324
+ // The first query contains errors on purpose so the
325
+ // syntax errors get triggered before the auto-completion
326
+ await textField.fill('MATCH (n) REURN n; MATCH a');
327
+
328
+ await page
329
+ .locator('.cm-tooltip-autocomplete')
330
+ .getByText('allShortestPaths')
331
+ .click();
332
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
333
+
334
+ expect(await textField.textContent()).toEqual(
335
+ 'MATCH (n) REURN n; MATCH allShortestPaths',
336
+ );
337
+ });
338
+
339
+ async function getInfoTooltip(page: Page, methodName: string) {
340
+ const infoTooltip = page.locator('.cm-completionInfo');
341
+ const firstOption = page.locator('li[aria-selected="true"]');
342
+ let selectedOption = firstOption;
343
+
344
+ while (!(await infoTooltip.textContent()).includes(methodName)) {
345
+ await page.keyboard.press('ArrowDown');
346
+ const currentSelected = page.locator('li[aria-selected="true"]');
347
+ expect(currentSelected).not.toBe(selectedOption);
348
+ expect(currentSelected).not.toBe(firstOption);
349
+ selectedOption = currentSelected;
350
+ }
351
+
352
+ return infoTooltip;
353
+ }
354
+
355
+ test('shows signature help information on auto-completion for procedures', async ({
356
+ page,
357
+ mount,
358
+ }) => {
359
+ await mount(<CypherEditor schema={testData.mockSchema} />);
360
+ const procName = 'apoc.periodic.iterate';
361
+ const procedure = testData.mockSchema.procedures['CYPHER 5'][procName];
362
+
363
+ const textField = page.getByRole('textbox');
364
+ await textField.fill('CALL apoc.periodic.');
365
+
366
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
367
+
368
+ const infoTooltip = await getInfoTooltip(page, procName);
369
+ await expect(infoTooltip).toContainText(procedure.signature);
370
+ await expect(infoTooltip).toContainText(procedure.description);
371
+ });
372
+
373
+ test('shows signature help information on auto-completion for functions', async ({
374
+ page,
375
+ mount,
376
+ }) => {
377
+ await mount(<CypherEditor schema={testData.mockSchema} />);
378
+ const fnName = 'apoc.coll.combinations';
379
+ const fn = testData.mockSchema.functions['CYPHER 5'][fnName];
380
+
381
+ const textField = page.getByRole('textbox');
382
+ await textField.fill('RETURN apoc.coll.');
383
+
384
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
385
+
386
+ const infoTooltip = await getInfoTooltip(page, fnName);
387
+ await expect(infoTooltip).toContainText(fn.signature);
388
+ await expect(infoTooltip).toContainText(fn.description);
389
+ });
390
+
391
+ test('shows deprecated procedures as strikethrough on auto-completion', async ({
392
+ page,
393
+ mount,
394
+ }) => {
395
+ const procName = 'apoc.trigger.resume';
396
+
397
+ await mount(
398
+ <CypherEditor
399
+ schema={{
400
+ procedures: {
401
+ 'CYPHER 5': {
402
+ [procName]: testData.mockSchema.procedures['CYPHER 5'][procName],
403
+ },
404
+ },
405
+ }}
406
+ />,
407
+ );
408
+ const textField = page.getByRole('textbox');
409
+ await textField.fill('CALL apoc.trigger.');
410
+
411
+ // We need to assert on the element having the right class
412
+ // and trusting the CSS is making this truly strikethrough
413
+ await expect(page.locator('.cm-deprecated-element')).toBeVisible();
414
+ });
415
+
416
+ test('shows deprecated function as strikethrough on auto-completion', async ({
417
+ page,
418
+ mount,
419
+ }) => {
420
+ const fnName = 'apoc.create.uuid';
421
+
422
+ await mount(
423
+ <CypherEditor
424
+ schema={{
425
+ functions: {
426
+ 'CYPHER 5': {
427
+ [fnName]: testData.mockSchema.functions['CYPHER 5'][fnName],
428
+ },
429
+ },
430
+ }}
431
+ />,
432
+ );
433
+ const textField = page.getByRole('textbox');
434
+ await textField.fill('RETURN apoc.create.');
435
+
436
+ // We need to assert on the element having the right class
437
+ // and trusting the CSS is making this truly strikethrough
438
+ await expect(page.locator('.cm-deprecated-element')).toBeVisible();
439
+ });
440
+
441
+ test('does not signature help information on auto-completion if docs and signature are empty', async ({
442
+ page,
443
+ mount,
444
+ }) => {
445
+ await mount(<CypherEditor schema={testData.mockSchema} />);
446
+
447
+ const textField = page.getByRole('textbox');
448
+ await textField.fill('C');
449
+
450
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
451
+ await expect(page.locator('.cm-completionInfo')).not.toBeVisible();
452
+ });
453
+
454
+ test('shows signature help information on auto-completion if description is not empty, signature is', async ({
455
+ page,
456
+ mount,
457
+ }) => {
458
+ await mount(
459
+ <CypherEditor
460
+ schema={{
461
+ procedures: {
462
+ 'CYPHER 5': {
463
+ 'db.ping': {
464
+ ...testData.emptyProcedure,
465
+ description: 'foo',
466
+ signature: '',
467
+ name: 'db.ping',
468
+ },
469
+ },
470
+ },
471
+ }}
472
+ />,
473
+ );
474
+
475
+ const textField = page.getByRole('textbox');
476
+ await textField.fill('CALL db.');
477
+
478
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
479
+ await expect(page.locator('.cm-completionInfo')).toBeVisible();
480
+ });
481
+
482
+ test('shows signature help information on auto-completion if signature is not empty, description is', async ({
483
+ page,
484
+ mount,
485
+ }) => {
486
+ await mount(
487
+ <CypherEditor
488
+ schema={{
489
+ procedures: {
490
+ 'CYPHER 5': {
491
+ 'db.ping': {
492
+ ...testData.emptyProcedure,
493
+ description: '',
494
+ signature: 'foo',
495
+ name: 'db.ping',
496
+ },
497
+ },
498
+ },
499
+ }}
500
+ />,
501
+ );
502
+
503
+ const textField = page.getByRole('textbox');
504
+ await textField.fill('CALL db.');
505
+
506
+ await expect(page.locator('.cm-tooltip-autocomplete')).toBeVisible();
507
+ await expect(page.locator('.cm-completionInfo')).toBeVisible();
508
+ });
509
+
510
+ test('completions depend on the Cypher version', async ({ page, mount }) => {
511
+ await mount(
512
+ <CypherEditor
513
+ schema={{
514
+ functions: {
515
+ 'CYPHER 5': {
516
+ cypher5Function: {
517
+ ...testData.emptyFunction,
518
+ name: 'cypher5Function',
519
+ },
520
+ },
521
+ 'CYPHER 25': {
522
+ cypher25Function: {
523
+ ...testData.emptyFunction,
524
+ name: 'cypher25Function',
525
+ },
526
+ },
527
+ },
528
+ }}
529
+ />,
530
+ );
531
+
532
+ const textField = page.getByRole('textbox');
533
+
534
+ await textField.fill('CYPHER 5 RETURN cypher');
535
+
536
+ await expect(
537
+ page.locator('.cm-tooltip-autocomplete').getByText('cypher5Function'),
538
+ ).toBeVisible();
539
+
540
+ await textField.fill('CYPHER 25 RETURN cypher');
541
+
542
+ await expect(
543
+ page.locator('.cm-tooltip-autocomplete').getByText('cypher25Function'),
544
+ ).toBeVisible();
545
+ });
546
+
547
+ test('does not complete properties for non node / relationship variables', async ({ page, mount }) => {
548
+ await mount(
549
+ <CypherEditor
550
+ schema={{
551
+ propertyKeys: ["nodeProperty"]
552
+ }}
553
+ />
554
+ );
555
+
556
+ const textField = page.getByRole('textbox');
557
+ await textField.fill('MATCH (n) RETURN n.');
558
+
559
+ await expect(
560
+ page.locator('.cm-tooltip-autocomplete').getByText('nodeProperty'),
561
+ ).toBeVisible();
562
+
563
+ await textField.fill('WITH 1 AS x RETURN x.');
564
+ // This could be flaky if the semantic analysis takes too long
565
+ await page.waitForTimeout(500)
566
+ await textField.press('Escape');
567
+ await textField.press('Control+ ');
568
+ await expect(
569
+ page.locator('.cm-tooltip-autocomplete').getByText('nodeProperty')
570
+ ).not.toBeVisible();
571
+ });
@@ -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
+ });