2022-03-31 18:56:51 +00:00
|
|
|
import { expect, Page } from '@playwright/test'
|
2021-12-20 08:21:07 +00:00
|
|
|
import { test } from './fixtures'
|
2022-11-30 12:27:36 +00:00
|
|
|
import { Block } from './types'
|
2023-03-21 09:02:56 +00:00
|
|
|
import { modKey, createRandomPage, newInnerBlock, randomString, lastBlock, enterNextBlock } from './utils'
|
2023-03-16 13:03:38 +00:00
|
|
|
import { searchPage, closeSearchBox } from './util/search-modal'
|
2021-12-20 08:21:07 +00:00
|
|
|
|
2022-01-23 04:31:49 +00:00
|
|
|
/***
|
2022-01-12 04:31:58 +00:00
|
|
|
* Test alias features
|
2023-02-20 11:44:01 +00:00
|
|
|
* Test search referring features
|
2022-01-12 04:31:58 +00:00
|
|
|
* Consider diacritics
|
|
|
|
***/
|
|
|
|
|
2023-03-07 12:26:03 +00:00
|
|
|
let hotkeyOpenLink = modKey + '+o'
|
|
|
|
let hotkeyBack = modKey + '+['
|
2022-02-17 13:54:28 +00:00
|
|
|
|
2022-11-30 05:52:22 +00:00
|
|
|
test('Search page and blocks (diacritics)', async ({ page, block }) => {
|
2022-02-17 13:54:28 +00:00
|
|
|
const rand = randomString(20)
|
|
|
|
|
|
|
|
// diacritic opening test
|
|
|
|
await createRandomPage(page)
|
|
|
|
|
2022-11-29 05:03:41 +00:00
|
|
|
await block.mustType('[[Einführung in die Allgemeine Sprachwissenschaft' + rand + ']] diacritic-block-1', { delay: 10 })
|
2023-03-07 02:44:56 +00:00
|
|
|
await page.waitForTimeout(500)
|
|
|
|
await page.keyboard.press(hotkeyOpenLink, { delay: 10 })
|
|
|
|
await page.waitForTimeout(500)
|
2022-02-17 13:54:28 +00:00
|
|
|
|
2022-11-29 05:03:41 +00:00
|
|
|
const pageTitle = page.locator('.page-title').first()
|
|
|
|
expect(await pageTitle.innerText()).toEqual('Einführung in die Allgemeine Sprachwissenschaft' + rand)
|
|
|
|
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
|
2022-02-17 13:54:28 +00:00
|
|
|
// build target Page with diacritics
|
2022-11-29 05:03:41 +00:00
|
|
|
await block.activeEditing(0)
|
|
|
|
await block.mustType('Diacritic title test content', { delay: 10 })
|
2022-02-17 13:54:28 +00:00
|
|
|
|
2022-11-29 05:03:41 +00:00
|
|
|
await block.enterNext()
|
|
|
|
await block.mustType('[[Einführung in die Allgemeine Sprachwissenschaft' + rand + ']] diacritic-block-2', { delay: 10 })
|
2023-10-16 15:02:27 +00:00
|
|
|
await page.waitForTimeout(500)
|
2022-02-17 13:54:28 +00:00
|
|
|
await page.keyboard.press(hotkeyBack)
|
|
|
|
|
|
|
|
// check if diacritics are indexed
|
2023-03-16 13:03:38 +00:00
|
|
|
const results = await searchPage(page, 'Einführung in die Allgemeine Sprachwissenschaft' + rand)
|
2024-01-15 09:41:26 +00:00
|
|
|
await expect(results.length).toEqual(5) // 2 block + 1 current page
|
2023-03-16 13:03:38 +00:00
|
|
|
await closeSearchBox(page)
|
2022-02-17 13:54:28 +00:00
|
|
|
})
|
|
|
|
|
2022-11-30 05:52:22 +00:00
|
|
|
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 })
|
2023-03-07 05:27:34 +00:00
|
|
|
await page.waitForTimeout(500)
|
|
|
|
await page.keyboard.press(hotkeyOpenLink, { delay: 10 })
|
|
|
|
await page.waitForTimeout(500)
|
2022-11-30 05:52:22 +00:00
|
|
|
|
|
|
|
const pageTitle = page.locator('.page-title').first()
|
2022-11-30 12:27:36 +00:00
|
|
|
expect(await pageTitle.innerText()).toEqual('今日daytime进度条' + rand)
|
2022-11-30 05:52:22 +00:00
|
|
|
|
|
|
|
await page.waitForTimeout(500)
|
2021-12-20 08:21:07 +00:00
|
|
|
|
2023-03-16 13:03:38 +00:00
|
|
|
// check if CJK are indexed
|
|
|
|
const results = await searchPage(page, '进度')
|
2024-01-15 09:41:26 +00:00
|
|
|
await expect(results.length).toEqual(4) // 1 page + 1 block + new whiteboard
|
2023-03-16 13:03:38 +00:00
|
|
|
await closeSearchBox(page)
|
2022-11-30 05:52:22 +00:00
|
|
|
})
|
|
|
|
|
2023-03-07 02:44:56 +00:00
|
|
|
async function alias_test(block: Block, page: Page, page_name: string, search_kws: string[]) {
|
2022-12-01 07:19:55 +00:00
|
|
|
await createRandomPage(page)
|
|
|
|
|
2022-01-11 12:16:51 +00:00
|
|
|
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)
|
|
|
|
|
2022-12-01 07:19:55 +00:00
|
|
|
await page.type('textarea >> nth=0', '[[' + target_name)
|
2021-12-20 08:21:07 +00:00
|
|
|
await page.keyboard.press(hotkeyOpenLink)
|
|
|
|
|
2022-03-31 14:52:42 +00:00
|
|
|
await lastBlock(page)
|
2022-03-31 18:56:51 +00:00
|
|
|
|
2021-12-20 08:21:07 +00:00
|
|
|
// build target Page with alias
|
2022-08-22 10:52:36 +00:00
|
|
|
// the target page will contains the content in
|
2022-07-13 13:30:17 +00:00
|
|
|
// alias_test_content_1,
|
|
|
|
// alias_test_content_2, and
|
2023-02-20 11:44:01 +00:00
|
|
|
// alias_test_content_3 sequentially, to validate the target page state
|
2023-03-07 02:44:56 +00:00
|
|
|
await page.type('textarea >> nth=0', 'alias:: [[' + alias_name, { delay: 10 })
|
|
|
|
await page.keyboard.press('Enter', { delay: 200 }) // Enter for finishing selection
|
2023-10-17 09:38:13 +00:00
|
|
|
await page.keyboard.press('Enter', { delay: 200 })
|
|
|
|
await page.keyboard.press('Escape')
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await block.clickNext()
|
2022-11-30 11:08:43 +00:00
|
|
|
await block.activeEditing(1)
|
2022-03-31 14:52:42 +00:00
|
|
|
await page.type('textarea >> nth=0', alias_test_content_1)
|
2022-08-29 07:47:24 +00:00
|
|
|
await lastBlock(page)
|
2022-11-30 11:08:43 +00:00
|
|
|
page.keyboard.press(hotkeyBack)
|
2021-12-20 08:21:07 +00:00
|
|
|
|
2022-11-30 11:08:43 +00:00
|
|
|
await page.waitForNavigation()
|
2022-12-01 07:19:55 +00:00
|
|
|
await block.escapeEditing()
|
2021-12-20 08:21:07 +00:00
|
|
|
// create alias ref in origin Page
|
2022-11-30 11:08:43 +00:00
|
|
|
await block.activeEditing(0)
|
|
|
|
await block.enterNext()
|
2023-03-07 02:44:56 +00:00
|
|
|
await page.type('textarea >> nth=0', '[[' + alias_name, { delay: 20 })
|
2022-11-30 11:08:43 +00:00
|
|
|
await page.keyboard.press('Enter') // Enter for finishing selection
|
2022-03-31 18:56:51 +00:00
|
|
|
await page.waitForTimeout(100)
|
|
|
|
|
2022-11-30 11:08:43 +00:00
|
|
|
page.keyboard.press(hotkeyOpenLink)
|
|
|
|
await page.waitForNavigation()
|
2022-12-01 07:19:55 +00:00
|
|
|
await block.escapeEditing()
|
2021-12-20 08:21:07 +00:00
|
|
|
|
|
|
|
// shortcut opening test
|
2022-11-30 11:08:43 +00:00
|
|
|
await block.activeEditing(1)
|
2022-03-31 14:52:42 +00:00
|
|
|
expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_1)
|
2022-03-31 18:56:51 +00:00
|
|
|
|
|
|
|
await enterNextBlock(page)
|
2023-10-16 15:02:27 +00:00
|
|
|
await page.waitForTimeout(100)
|
2022-03-31 14:52:42 +00:00
|
|
|
await page.type('textarea >> nth=0', alias_test_content_2)
|
2023-10-16 15:02:27 +00:00
|
|
|
await page.waitForTimeout(100)
|
2022-11-30 11:08:43 +00:00
|
|
|
page.keyboard.press(hotkeyBack)
|
2021-12-20 08:21:07 +00:00
|
|
|
|
2022-11-30 11:08:43 +00:00
|
|
|
await page.waitForNavigation()
|
2022-12-01 07:19:55 +00:00
|
|
|
await block.escapeEditing()
|
2022-11-30 12:27:36 +00:00
|
|
|
// pressing enter on alias opening test
|
2022-11-30 11:08:43 +00:00
|
|
|
await block.activeEditing(1)
|
2022-03-31 14:52:42 +00:00
|
|
|
await page.press('textarea >> nth=0', 'ArrowLeft')
|
|
|
|
await page.press('textarea >> nth=0', 'ArrowLeft')
|
|
|
|
await page.press('textarea >> nth=0', 'ArrowLeft')
|
2022-11-30 11:08:43 +00:00
|
|
|
page.press('textarea >> nth=0', 'Enter')
|
|
|
|
await page.waitForNavigation()
|
2022-12-01 07:19:55 +00:00
|
|
|
await block.escapeEditing()
|
2022-11-30 11:08:43 +00:00
|
|
|
await block.activeEditing(2)
|
2022-03-31 14:52:42 +00:00
|
|
|
expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_2)
|
2021-12-21 00:29:22 +00:00
|
|
|
await newInnerBlock(page)
|
2023-10-16 15:02:27 +00:00
|
|
|
await page.waitForTimeout(100)
|
2022-03-31 14:52:42 +00:00
|
|
|
await page.type('textarea >> nth=0', alias_test_content_3)
|
2023-10-16 15:02:27 +00:00
|
|
|
await page.waitForTimeout(100)
|
2022-11-30 11:08:43 +00:00
|
|
|
page.keyboard.press(hotkeyBack)
|
2023-03-07 02:44:56 +00:00
|
|
|
|
2022-11-30 11:08:43 +00:00
|
|
|
await page.waitForNavigation()
|
2022-12-01 07:19:55 +00:00
|
|
|
await block.escapeEditing()
|
2022-11-30 12:27:36 +00:00
|
|
|
// clicking alias ref opening test
|
2022-11-30 11:08:43 +00:00
|
|
|
await block.activeEditing(1)
|
2022-11-30 12:27:36 +00:00
|
|
|
await block.enterNext()
|
2022-01-12 06:51:34 +00:00
|
|
|
await page.waitForSelector('.page-blocks-inner .ls-block .page-ref >> nth=-1')
|
2021-12-20 08:21:07 +00:00
|
|
|
await page.click('.page-blocks-inner .ls-block .page-ref >> nth=-1')
|
2022-03-31 14:52:42 +00:00
|
|
|
await lastBlock(page)
|
|
|
|
expect(await page.inputValue('textarea >> nth=0')).toBe(alias_test_content_3)
|
2021-12-20 08:21:07 +00:00
|
|
|
|
|
|
|
// TODO: test alias from graph clicking
|
2022-01-11 12:16:51 +00:00
|
|
|
|
2022-01-12 04:31:58 +00:00
|
|
|
// test alias from search
|
2022-02-10 11:00:41 +00:00
|
|
|
for (let kw of search_kws) {
|
2022-01-18 17:34:28 +00:00
|
|
|
let kw_name = kw + ' alias ' + rand
|
|
|
|
|
2023-03-16 13:03:38 +00:00
|
|
|
const results = await searchPage(page, kw_name)
|
2022-01-18 17:34:28 +00:00
|
|
|
|
|
|
|
// test search results
|
2024-02-22 14:20:30 +00:00
|
|
|
expect(await results[0].innerText()).toContain(alias_name.normalize('NFKC'))
|
2022-01-18 17:34:28 +00:00
|
|
|
|
|
|
|
// test search entering (page)
|
|
|
|
page.keyboard.press("Enter")
|
|
|
|
await page.waitForNavigation()
|
2022-12-01 07:19:55 +00:00
|
|
|
await page.waitForSelector('.ls-block span.inline')
|
2022-01-18 17:34:28 +00:00
|
|
|
|
|
|
|
// test search clicking (block)
|
2023-03-16 13:03:38 +00:00
|
|
|
await searchPage(page, kw_name)
|
2022-02-10 11:00:41 +00:00
|
|
|
}
|
2022-01-11 12:16:51 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 07:55:14 +00:00
|
|
|
test('page diacritic alias', async ({ block, page }) => {
|
2022-11-30 12:27:36 +00:00
|
|
|
await alias_test(block, page, "ü", ["ü", "ü", "Ü"])
|
2022-03-31 14:52:42 +00:00
|
|
|
})
|