logseq/e2e-tests/editor.spec.ts

109 lines
3.9 KiB
TypeScript
Raw Normal View History

2022-02-17 10:54:30 +00:00
import { expect } from '@playwright/test'
import { test } from './fixtures'
2022-03-30 17:34:18 +00:00
import { createRandomPage } from './utils'
import { dispatch_kb_events } from './util/keyboard-events'
2022-03-07 12:08:38 +00:00
import * as kb_events from './util/keyboard-events'
2022-03-07 12:08:38 +00:00
test(
"press Chinese parenthesis 【 by 2 times #3251 should trigger [[]], " +
"but dont trigger RIME #3440 ",
// cases should trigger [[]] #3251
2022-03-07 12:08:38 +00:00
async ({ page }) => {
for (let [idx, events] of [
kb_events.win10_pinyin_left_full_square_bracket,
kb_events.macos_pinyin_left_full_square_bracket
2022-03-07 12:08:38 +00:00
// TODO: support #3741
// kb_events.win10_legacy_pinyin_left_full_square_bracket,
].entries()) {
2022-03-07 12:08:38 +00:00
await createRandomPage(page)
let check_text = "#3251 test " + idx
await page.fill(':nth-match(textarea, 1)', check_text + "【")
await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text + '【')
await page.fill(':nth-match(textarea, 1)', 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)
2022-03-07 18:16:55 +00:00
let check_text = "#3440 test " + idx
await page.fill(':nth-match(textarea, 1)', check_text)
await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
2022-03-07 18:16:55 +00:00
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text)
await dispatch_kb_events(page, ':nth-match(textarea, 1)', events)
2022-03-07 18:16:55 +00:00
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(check_text)
}
2022-03-07 12:08:38 +00:00
})
2022-02-17 10:54:30 +00:00
test('hashtag and quare brackets in same line #4178', async ({ page }) => {
await createRandomPage(page)
await page.type(':nth-match(textarea, 1)', '#foo bar')
await page.press(':nth-match(textarea, 1)', 'Enter')
await page.type(':nth-match(textarea, 1)', 'bar [[blah]]')
for (let i = 0; i < 12; i++) {
2022-02-17 10:54:30 +00:00
await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
}
await page.type(':nth-match(textarea, 1)', ' ')
await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
await page.type(':nth-match(textarea, 1)', '#')
await page.waitForSelector('text="Search for a page"', { state: 'visible' })
await page.type(':nth-match(textarea, 1)', 'fo')
await page.click('.absolute >> text=' + 'foo')
expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(
'#foo bar [[blah]]'
)
})
// FIXME: ClipboardItem is not defined when running with this test
// test('copy & paste block ref and replace its content', async ({ page }) => {
// await createRandomPage(page)
// await page.type(':nth-match(textarea, 1)', 'Some random text')
// if (IsMac) {
// await page.keyboard.press('Meta+c')
// } else {
// await page.keyboard.press('Control+c')
// }
// await page.pause()
// await page.press(':nth-match(textarea, 1)', 'Enter')
// if (IsMac) {
// await page.keyboard.press('Meta+v')
// } else {
// await page.keyboard.press('Control+v')
// }
// await page.keyboard.press('Escape')
// 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);
// // Edit the last block
// await blockRef$.press('Enter')
// // Move cursor into the block ref
// for (let i = 0; i < 4; i++) {
// await page.press(':nth-match(textarea, 1)', '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')
// }
// })