-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
editor.spec.ts
236 lines (192 loc) · 7.98 KB
/
editor.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
import { expect } from '@playwright/test'
import { test } from './fixtures'
import { createRandomPage, enterNextBlock, systemModifier, IsMac } from './utils'
import { dispatch_kb_events } from './util/keyboard-events'
import * as kb_events from './util/keyboard-events'
test('hashtag and quare brackets in same line #4178', async ({ page }) => {
await createRandomPage(page)
await page.type('textarea >> nth=0', '#foo bar')
await enterNextBlock(page)
await page.type('textarea >> nth=0', 'bar [[blah]]', { delay: 100 })
for (let i = 0; i < 12; i++) {
await page.press('textarea >> nth=0', 'ArrowLeft')
}
await page.type('textarea >> nth=0', ' ')
await page.press('textarea >> nth=0', 'ArrowLeft')
await page.type('textarea >> nth=0', '#')
await page.waitForSelector('text="Search for a page"', { state: 'visible' })
await page.type('textarea >> nth=0', 'fo')
await page.click('.absolute >> text=' + 'foo')
expect(await page.inputValue('textarea >> nth=0')).toBe(
'#foo bar [[blah]]'
)
})
test('disappeared children #4814', async ({ page, block }) => {
await createRandomPage(page)
await block.mustType('parent')
await block.enterNext()
expect(await block.indent()).toBe(true)
for (let i = 0; i < 5; i++) {
await block.mustType(i.toString())
await block.enterNext()
}
// collapse
await page.click('.block-control >> nth=0')
// expand
await page.click('.block-control >> nth=0')
await block.waitForBlocks(7) // 1 + 5 + 1 empty
// Ensures there's no active editor
await expect(page.locator('.editor-inner')).toHaveCount(0, { timeout: 500 })
})
test('create new page from bracketing text #4971', async ({ page, block }) => {
let title = 'Page not Exists yet'
await createRandomPage(page)
await block.mustType(`[[${title}]]`)
await page.keyboard.press(systemModifier('Control+o'))
// Check page title equals to `title`
await page.waitForTimeout(100)
expect(await page.locator('h1.title').innerText()).toContain(title)
// Check there're linked references
await page.waitForSelector(`.references .ls-block >> nth=1`, { state: 'detached', timeout: 100 })
})
test.skip('backspace and cursor position #4897', async ({ page, block }) => {
await createRandomPage(page)
// Delete to previous block, and check cursor postion, with markup
await block.mustFill('`012345`')
await block.enterNext()
await block.mustType('`abcdef', { toBe: '`abcdef`' }) // "`" auto-completes
expect(await block.selectionStart()).toBe(7)
expect(await block.selectionEnd()).toBe(7)
for (let i = 0; i < 7; i++) {
await page.keyboard.press('ArrowLeft')
}
expect(await block.selectionStart()).toBe(0)
await page.keyboard.press('Backspace')
await block.waitForBlocks(1) // wait for delete and re-render
expect(await block.selectionStart()).toBe(8)
})
test.skip('next block and cursor position', async ({ page, block }) => {
await createRandomPage(page)
// Press Enter and check cursor postion, with markup
await block.mustType('abcde`12345', { toBe: 'abcde`12345`' }) // "`" auto-completes
for (let i = 0; i < 7; i++) {
await page.keyboard.press('ArrowLeft')
}
expect(await block.selectionStart()).toBe(5) // after letter 'e'
await block.enterNext()
expect(await block.selectionStart()).toBe(0) // should at the beginning of the next block
const locator = page.locator('textarea >> nth=0')
await expect(locator).toHaveText('`12345`', { timeout: 1000 })
})
test(
"Press CJK Left Black Lenticular Bracket `【` by 2 times #3251 should trigger [[]], " +
"but dont trigger RIME #3440 ",
// cases should trigger [[]] #3251
async ({ page, block }) => {
for (let [idx, events] of [
kb_events.win10_pinyin_left_full_square_bracket,
kb_events.macos_pinyin_left_full_square_bracket
// TODO: support #3741
// kb_events.win10_legacy_pinyin_left_full_square_bracket,
].entries()) {
await createRandomPage(page)
let check_text = "#3251 test " + idx
await block.mustFill(check_text + "【")
await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text + '【')
await block.mustFill(check_text + "【【")
await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text + '[[]]')
};
// dont trigger RIME #3440
for (let [idx, events] of [
kb_events.macos_pinyin_selecting_candidate_double_left_square_bracket,
kb_events.win10_RIME_selecting_candidate_double_left_square_bracket
].entries()) {
await createRandomPage(page)
let check_text = "#3440 test " + idx
await block.mustFill(check_text)
await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text)
await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text)
}
})
test('copy & paste block ref and replace its content', async ({ page, block }) => {
await createRandomPage(page)
await block.mustFill('Some random text')
// FIXME: copy instantly will make content disappear
await page.waitForTimeout(1000)
if (IsMac) {
await page.keyboard.press('Meta+c')
} else {
await page.keyboard.press('Control+c')
}
await page.press('textarea >> nth=0', 'Enter')
if (IsMac) {
await page.keyboard.press('Meta+v')
} else {
await page.keyboard.press('Control+v')
}
await page.keyboard.press('Enter')
const blockRef = page.locator('.block-ref >> text="Some random text"');
// Check if the newly created block-ref has the same referenced content
await expect(blockRef).toHaveCount(1);
// Move cursor into the block ref
for (let i = 0; i < 4; i++) {
await page.press('textarea >> nth=0', 'ArrowLeft')
}
// Trigger replace-block-reference-with-content-at-point
if (IsMac) {
await page.keyboard.press('Meta+Shift+r')
} else {
await page.keyboard.press('Control+Shift+v')
}
})
test('copy and paste block after editing new block #5962', async ({ page, block }) => {
await createRandomPage(page)
// Create a block and copy it in block-select mode
await block.mustFill('Block being copied')
await page.waitForTimeout(100)
await page.keyboard.press('Escape')
await page.waitForTimeout(100)
if (IsMac) {
await page.keyboard.press('Meta+c')
} else {
await page.keyboard.press('Control+c')
}
// await page.waitForTimeout(100)
await page.keyboard.press('Enter')
await page.waitForTimeout(100)
await page.keyboard.press('Enter')
await page.waitForTimeout(100)
// Create a new block with some text
await page.keyboard.insertText("Typed block")
// Quickly paste the copied block
if (IsMac) {
await page.keyboard.press('Meta+v')
} else {
await page.keyboard.press('Control+v')
}
await expect(page.locator('text="Typed block"')).toHaveCount(1);
})
test('press escape when autocomplete menu is open, should close autocomplete menu only #6270', async ({ page, block }) => {
for (const [commandTrigger, modalName] of [['[[', 'page-search'], ['/', 'commands']]) {
await createRandomPage(page)
// Open the action modal
await block.mustFill('text ')
await page.waitForTimeout(550)
for (const char of commandTrigger) {
await page.keyboard.type(char) // Type it one character at a time, because too quickly can fail to trigger it sometimes
}
await page.waitForTimeout(100)
await expect(page.locator(`[data-modal-name="${modalName}"]`)).toBeVisible()
await page.waitForTimeout(100)
// Press escape; should close action modal instead of exiting edit mode
await page.keyboard.press('Escape')
await page.waitForTimeout(100)
await expect(page.locator(`[data-modal-name="${modalName}"]`)).not.toBeVisible()
await page.waitForTimeout(1000)
expect(await block.isEditing()).toBe(true)
}
})