-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsanityChecks.spec.tsx
78 lines (54 loc) · 2.31 KB
/
sanityChecks.spec.tsx
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
import { expect, test } from '@playwright/experimental-ct-react';
import { CypherEditor } from '../CypherEditor';
test.use({ viewport: { width: 500, height: 500 } });
test('can mount the editor with text', async ({ mount }) => {
const component = await mount(<CypherEditor value="MATCH (n) RETURN n;" />);
await expect(component).toContainText('MATCH (n) RETURN n;');
});
test('the editors text can be externally controlled ', async ({ mount }) => {
const intitialValue = 'MATCH (n) RETURN n;';
const component = await mount(<CypherEditor value={intitialValue} />);
await expect(component).toContainText(intitialValue);
const newValue = 'RETURN 123';
await component.update(<CypherEditor value={newValue} />);
await expect(component).toContainText(newValue);
});
test('the editor can report changes to the text ', async ({ mount, page }) => {
const intitialValue = 'MATCH (n) ';
let editorValueCopy = intitialValue;
const onChange = (val: string) => {
editorValueCopy = val;
};
await mount(<CypherEditor value={intitialValue} onChange={onChange} />);
const textField = page.getByRole('textbox');
await textField.fill('RETURN 12');
// editor update is debounced, retry wait for debounced
await expect(() => {
expect(editorValueCopy).toBe('RETURN 12');
}).toPass({ intervals: [300, 300, 1000] });
await page.keyboard.type('34');
await expect(() => {
expect(editorValueCopy).toBe('RETURN 12');
}).toPass({ intervals: [300, 300, 1000] });
});
test('can complete RETURN', async ({ page, mount }) => {
await mount(<CypherEditor />);
const textField = page.getByRole('textbox');
await textField.fill('RETU');
await page.getByText('RETURN').click();
await expect(textField).toHaveText('RETURN');
});
test('can complete CALL/CREATE', async ({ page, mount }) => {
await mount(<CypherEditor />);
const textField = page.getByRole('textbox');
await textField.fill('C');
await expect(page.getByText('CALL')).toBeVisible();
await expect(page.getByText('CREATE')).toBeVisible();
await textField.fill('CA');
await expect(page.getByText('CALL')).toBeVisible();
await expect(page.getByText('CREATE')).not.toBeVisible();
// wait for the autocomplete interactivity
await page.waitForTimeout(500);
await textField.press('Enter');
await expect(textField).toHaveText('CALL');
});