forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.spec.ts
301 lines (229 loc) · 10.3 KB
/
basic.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import { expect } from '@playwright/test'
import fs from 'fs/promises'
import path from 'path'
import { test, graphDir } from './fixtures'
import { randomString, createRandomPage, newBlock } from './utils'
test('render app', async ({ page }) => {
// NOTE: part of app startup tests is moved to `fixtures.ts`.
await page.waitForFunction('window.document.title != "Loading"')
expect(await page.title()).toMatch(/^Logseq.*?/)
})
test('toggle sidebar', async ({ page }) => {
let sidebar = page.locator('#left-sidebar')
// Left sidebar is toggled by `is-open` class
if (/is-open/.test(await sidebar.getAttribute('class'))) {
await page.click('#left-menu.button')
expect(await sidebar.getAttribute('class')).not.toMatch(/is-open/)
} else {
await page.click('#left-menu.button')
expect(await sidebar.getAttribute('class')).toMatch(/is-open/)
await page.click('#left-menu.button')
expect(await sidebar.getAttribute('class')).not.toMatch(/is-open/)
}
await page.click('#left-menu.button')
expect(await sidebar.getAttribute('class')).toMatch(/is-open/)
await page.waitForSelector('#left-sidebar .left-sidebar-inner', { state: 'visible' })
await page.waitForSelector('#left-sidebar a:has-text("New page")', { state: 'visible' })
})
test('search', async ({ page }) => {
await page.click('#search-button')
await page.waitForSelector('[placeholder="Search or create page"]')
await page.fill('[placeholder="Search or create page"]', 'welcome')
await page.waitForTimeout(500)
const results = await page.$$('#ui__ac-inner .block')
expect(results.length).toBeGreaterThanOrEqual(1)
})
test('create page and blocks', async ({ page }) => {
const pageTitle = await createRandomPage(page)
// do editing
await page.fill(':nth-match(textarea, 1)', 'this is my first bullet')
await page.press(':nth-match(textarea, 1)', 'Enter')
// first block
expect(await page.$$('.block-content')).toHaveLength(1)
await page.fill(':nth-match(textarea, 1)', 'this is my second bullet')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.fill(':nth-match(textarea, 1)', 'this is my third bullet')
await page.press(':nth-match(textarea, 1)', 'Tab')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.keyboard.type('continue editing test')
await page.keyboard.press('Shift+Enter')
await page.keyboard.type('continue')
await page.keyboard.press('Enter')
await page.keyboard.press('Shift+Tab')
await page.keyboard.press('Shift+Tab')
await page.keyboard.type('test ok')
await page.keyboard.press('Escape')
const blocks = await page.$$('.ls-block')
expect(blocks).toHaveLength(5)
// active edit
await page.click('.ls-block >> nth=-1')
await page.press('textarea >> nth=0', 'Enter')
await page.fill('textarea >> nth=0', 'test')
for (let i = 0; i < 5; i++) {
await page.keyboard.press('Backspace')
}
await page.keyboard.press('Escape')
await page.waitForTimeout(500)
expect(await page.$$('.ls-block')).toHaveLength(5)
await page.waitForTimeout(1000)
const contentOnDisk = await fs.readFile(
path.join(graphDir, `pages/${pageTitle}.md`),
'utf8'
)
expect(contentOnDisk.trim()).toEqual(`
- this is my first bullet
- this is my second bullet
- this is my third bullet
- continue editing test
continue
- test ok`.trim())
})
test('delete and backspace', async ({ page }) => {
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'test')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('test')
// backspace
await page.keyboard.press('Backspace')
await page.keyboard.press('Backspace')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('te')
// refill
await page.fill(':nth-match(textarea, 1)', 'test')
await page.keyboard.press('ArrowLeft')
await page.keyboard.press('ArrowLeft')
// delete
await page.keyboard.press('Delete')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('tet')
await page.keyboard.press('Delete')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('te')
await page.keyboard.press('Delete')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('te')
// TODO: test delete & backspace across blocks
})
test('selection', async ({ page }) => {
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'line 1')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.fill(':nth-match(textarea, 1)', 'line 2')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.press(':nth-match(textarea, 1)', 'Tab')
await page.fill(':nth-match(textarea, 1)', 'line 3')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.fill(':nth-match(textarea, 1)', 'line 4')
await page.press(':nth-match(textarea, 1)', 'Tab')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.fill(':nth-match(textarea, 1)', 'line 5')
await page.keyboard.down('Shift')
await page.keyboard.press('ArrowUp')
await page.keyboard.press('ArrowUp')
await page.keyboard.press('ArrowUp')
await page.keyboard.up('Shift')
await page.waitForTimeout(500)
await page.keyboard.press('Backspace')
expect(await page.$$('.ls-block')).toHaveLength(2)
})
test('template', async ({ page }) => {
const randomTemplate = randomString(10)
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'template')
await page.press(':nth-match(textarea, 1)', 'Shift+Enter')
await page.type(':nth-match(textarea, 1)', 'template:: ' + randomTemplate)
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.press(':nth-match(textarea, 1)', 'Tab')
await page.fill(':nth-match(textarea, 1)', 'line1')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.fill(':nth-match(textarea, 1)', 'line2')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.press(':nth-match(textarea, 1)', 'Tab')
await page.fill(':nth-match(textarea, 1)', 'line3')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.press(':nth-match(textarea, 1)', 'Enter')
expect(await page.$$('.ls-block')).toHaveLength(5)
await page.type(':nth-match(textarea, 1)', '/template')
await page.click('[title="Insert a created template here"]')
// type to search template name
await page.keyboard.type(randomTemplate.substring(0, 3))
await page.click('.absolute >> text=' + randomTemplate)
await page.waitForTimeout(500)
expect(await page.$$('.ls-block')).toHaveLength(8)
})
test('auto completion square brackets', async ({ page }) => {
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'Auto-completion test')
await page.press(':nth-match(textarea, 1)', 'Enter')
// [[]]
await page.type(':nth-match(textarea, 1)', 'This is a [')
await page.inputValue(':nth-match(textarea, 1)').then(text => {
expect(text).toBe('This is a []')
})
await page.type(':nth-match(textarea, 1)', '[')
// wait for search popup
await page.waitForSelector('text="Search for a page"')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('This is a [[]]')
// re-enter edit mode
await page.press(':nth-match(textarea, 1)', 'Escape')
await page.click('.ls-block >> nth=-1')
await page.waitForSelector(':nth-match(textarea, 1)', { state: 'visible' })
// #3253
await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.waitForSelector('text="Search for a page"', { state: 'visible' })
// type more `]`s
await page.type(':nth-match(textarea, 1)', ']')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('This is a [[]]')
await page.type(':nth-match(textarea, 1)', ']')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('This is a [[]]')
await page.type(':nth-match(textarea, 1)', ']')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('This is a [[]]]')
})
test('auto completion and auto pair', async ({ page }) => {
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'Auto-completion test')
await page.press(':nth-match(textarea, 1)', 'Enter')
// {{
await page.type(':nth-match(textarea, 1)', 'type {{')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type {{}}')
// ((
await newBlock(page)
await page.type(':nth-match(textarea, 1)', 'type (')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type ()')
await page.type(':nth-match(textarea, 1)', '(')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type (())')
// 99 #3444
// TODO: Test under different keyboard layout when Playwright supports it
// await newBlock(page)
// await page.type(':nth-match(textarea, 1)', 'type 9')
// expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type 9')
// await page.type(':nth-match(textarea, 1)', '9')
// expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type 99')
// [[ #3251
await newBlock(page)
await page.type(':nth-match(textarea, 1)', 'type [')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type []')
await page.type(':nth-match(textarea, 1)', '[')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type [[]]')
// ``
await newBlock(page)
await page.type(':nth-match(textarea, 1)', 'type `')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type ``')
await page.type(':nth-match(textarea, 1)', 'code here')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('type `code here`')
})
// FIXME: Electron with filechooser is not working
test.skip('open directory', async ({ page }) => {
await page.click('#left-sidebar >> text=Journals')
await page.waitForSelector('h1:has-text("Open a local directory")')
await page.click('h1:has-text("Open a local directory")')
// await page.waitForEvent('filechooser')
await page.keyboard.press('Escape')
await page.click('#left-sidebar >> text=Journals')
})
test('invalid page props #3944', async ({ page }) => {
await createRandomPage(page)
await page.fill(':nth-match(textarea, 1)', 'public:: true\nsize:: 65535')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.waitForTimeout(1000)
})