forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-search.spec.ts
181 lines (145 loc) · 6.65 KB
/
page-search.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
import { expect, Page } from '@playwright/test'
import { test } from './fixtures'
import { Block } from './types'
import { modKey, createRandomPage, newInnerBlock, randomString, lastBlock, enterNextBlock } from './utils'
import { searchPage, closeSearchBox } from './util/search-modal'
/***
* Test alias features
* Test search referring features
* Consider diacritics
***/
let hotkeyOpenLink = modKey + '+o'
let hotkeyBack = modKey + '+['
test('Search page and blocks (diacritics)', async ({ page, block }) => {
const rand = randomString(20)
// diacritic opening test
await createRandomPage(page)
await block.mustType('[[Einführung in die Allgemeine Sprachwissenschaft' + rand + ']] diacritic-block-1', { delay: 10 })
await page.waitForTimeout(500)
await page.keyboard.press(hotkeyOpenLink, { delay: 10 })
await page.waitForTimeout(500)
const pageTitle = page.locator('.page-title').first()
expect(await pageTitle.innerText()).toEqual('Einführung in die Allgemeine Sprachwissenschaft' + rand)
await page.waitForTimeout(500)
// build target Page with diacritics
await block.activeEditing(0)
await block.mustType('Diacritic title test content', { delay: 10 })
await block.enterNext()
await block.mustType('[[Einführung in die Allgemeine Sprachwissenschaft' + rand + ']] diacritic-block-2', { delay: 10 })
await page.keyboard.press(hotkeyBack)
// check if diacritics are indexed
const results = await searchPage(page, 'Einführung in die Allgemeine Sprachwissenschaft' + rand)
await expect(results.length).toEqual(5) // 1 page + 2 block + 2 page content
await closeSearchBox(page)
})
test('Search CJK', async ({ page, block }) => {
const rand = randomString(20)
// diacritic opening test
await createRandomPage(page)
await block.mustType('[[今日daytime进度条' + rand + ']] diacritic-block-1', { delay: 10 })
await page.waitForTimeout(500)
await page.keyboard.press(hotkeyOpenLink, { delay: 10 })
await page.waitForTimeout(500)
const pageTitle = page.locator('.page-title').first()
expect(await pageTitle.innerText()).toEqual('今日daytime进度条' + rand)
await page.waitForTimeout(500)
// check if CJK are indexed
const results = await searchPage(page, '进度')
await expect(results.length).toEqual(5) // 1 page + 1 block + 1 page content + new whiteboard
await closeSearchBox(page)
})
async function alias_test(block: Block, page: Page, page_name: string, search_kws: string[]) {
await createRandomPage(page)
const rand = randomString(10)
let target_name = page_name + ' target ' + rand
let alias_name = page_name + ' alias ' + rand
let alias_test_content_1 = randomString(20)
let alias_test_content_2 = randomString(20)
let alias_test_content_3 = randomString(20)
await page.type('textarea >> nth=0', '[[' + target_name)
await page.keyboard.press(hotkeyOpenLink)
await lastBlock(page)
// build target Page with alias
// the target page will contains the content in
// alias_test_content_1,
// alias_test_content_2, and
// alias_test_content_3 sequentially, to validate the target page state
await page.type('textarea >> nth=0', 'alias:: [[' + alias_name, { delay: 10 })
await page.keyboard.press('Enter', { delay: 200 }) // Enter for finishing selection
await page.keyboard.press('Enter', { delay: 200 }) // double Enter for exit property editing
await page.keyboard.press('Enter', { delay: 200 }) // double Enter for exit property editing
await page.waitForTimeout(200)
await block.activeEditing(1)
await page.type('textarea >> nth=0', alias_test_content_1)
await lastBlock(page)
page.keyboard.press(hotkeyBack)
await page.waitForNavigation()
await block.escapeEditing()
// create alias ref in origin Page
await block.activeEditing(0)
await block.enterNext()
await page.type('textarea >> nth=0', '[[' + alias_name, { delay: 20 })
await page.keyboard.press('Enter') // Enter for finishing selection
await page.waitForTimeout(100)
page.keyboard.press(hotkeyOpenLink)
await page.waitForNavigation()
await block.escapeEditing()
// shortcut opening test
await block.activeEditing(1)
expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_1)
await enterNextBlock(page)
await page.type('textarea >> nth=0', alias_test_content_2)
page.keyboard.press(hotkeyBack)
await page.waitForNavigation()
await block.escapeEditing()
// pressing enter on alias opening test
await block.activeEditing(1)
await page.press('textarea >> nth=0', 'ArrowLeft')
await page.press('textarea >> nth=0', 'ArrowLeft')
await page.press('textarea >> nth=0', 'ArrowLeft')
page.press('textarea >> nth=0', 'Enter')
await page.waitForNavigation()
await block.escapeEditing()
await block.activeEditing(2)
expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_2)
await newInnerBlock(page)
await page.type('textarea >> nth=0', alias_test_content_3)
page.keyboard.press(hotkeyBack)
await page.waitForNavigation()
await block.escapeEditing()
// clicking alias ref opening test
await block.activeEditing(1)
await block.enterNext()
await page.waitForSelector('.page-blocks-inner .ls-block .page-ref >> nth=-1')
await page.click('.page-blocks-inner .ls-block .page-ref >> nth=-1')
await lastBlock(page)
expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_3)
// TODO: test alias from graph clicking
// test alias from search
for (let kw of search_kws) {
let kw_name = kw + ' alias ' + rand
const results = await searchPage(page, kw_name)
await expect(results.length).toEqual(5) // page + block + alias property + page content
// test search results
expect(await results[0].innerText()).toContain("Alias -> " + target_name)
expect(await results[0].innerText()).toContain(alias_name)
expect(await results[1].innerText()).toContain("[[" + alias_name + "]]")
expect(await results[2].innerText()).toContain("[[" + alias_name + "]]")
// test search entering (page)
page.keyboard.press("Enter")
await page.waitForNavigation()
await page.waitForSelector('.ls-block span.inline')
expect(await page.locator('.ls-block span.inline >> nth=2').innerHTML()).toBe(alias_test_content_3)
// test search clicking (block)
await searchPage(page, kw_name)
page.click(":nth-match(.search-result, 3)")
await page.waitForNavigation()
await page.waitForSelector('.selected a.page-ref')
expect(await page.locator('.selected a.page-ref').innerHTML()).toBe(alias_name)
await page.keyboard.press(hotkeyBack)
}
// TODO: search clicking (alias property)
}
test('page diacritic alias', async ({ block, page }) => {
await alias_test(block, page, "ü", ["ü", "ü", "Ü"])
})