-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfiguration.spec.tsx
97 lines (71 loc) · 2.75 KB
/
configuration.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { expect, test } from '@playwright/experimental-ct-react';
import { CypherEditor } from '../CypherEditor';
test.use({ viewport: { width: 500, height: 500 } });
test('prompt shows up', async ({ mount, page }) => {
const component = await mount(<CypherEditor prompt="neo4j>" />);
await expect(component).toContainText('neo4j>');
await component.update(<CypherEditor prompt="test>" />);
await expect(component).toContainText('test>');
const textField = page.getByRole('textbox');
await textField.press('a');
await expect(textField).toHaveText('a');
});
test('line numbers can be turned on/off', async ({ mount }) => {
const component = await mount(<CypherEditor lineNumbers />);
await expect(component).toContainText('1');
await component.update(<CypherEditor lineNumbers={false} />);
await expect(component).not.toContainText('1');
});
test('can configure readonly', async ({ mount, page }) => {
const component = await mount(<CypherEditor readonly />);
const textField = page.getByRole('textbox');
await textField.press('a');
await expect(textField).not.toHaveText('a');
await component.update(<CypherEditor readonly={false} />);
await textField.press('b');
await expect(textField).toHaveText('b');
});
test('can set placeholder ', async ({ mount, page }) => {
const component = await mount(<CypherEditor placeholder="bulbasaur" />);
const textField = page.getByRole('textbox');
await expect(textField).toHaveText('bulbasaur');
await component.update(<CypherEditor placeholder="venusaur" />);
await expect(textField).not.toHaveText('bulbasaur');
await expect(textField).toHaveText('venusaur');
await textField.fill('abc');
await expect(textField).not.toHaveText('venusaur');
await expect(textField).toHaveText('abc');
});
test('can set/unset onFocus/onBlur', async ({ mount, page }) => {
const component = await mount(<CypherEditor />);
let focusFireCount = 0;
let blurFireCount = 0;
const focus = () => {
focusFireCount += 1;
};
const blur = () => {
blurFireCount += 1;
};
await component.update(<CypherEditor domEventHandlers={{ blur, focus }} />);
const textField = page.getByRole('textbox');
await textField.click();
await expect(textField).toBeFocused();
// this is to give the events time to fire
await expect(() => {
expect(focusFireCount).toBe(1);
expect(blurFireCount).toBe(0);
}).toPass();
await textField.blur();
await expect(() => {
expect(focusFireCount).toBe(1);
expect(blurFireCount).toBe(1);
}).toPass();
await component.update(<CypherEditor />);
await textField.click();
await expect(textField).toBeFocused();
await textField.blur();
await expect(() => {
expect(focusFireCount).toBe(1);
expect(blurFireCount).toBe(1);
}).toPass();
});