From 8798ffed06d1348946a7959d00bb7f7f775c9a34 Mon Sep 17 00:00:00 2001 From: Junyi Du Date: Mon, 20 Dec 2021 16:21:07 +0800 Subject: [PATCH] test(e2e): add page alias tests --- e2e-tests/page-alias.spec.ts | 58 ++++++++++++++++++++++++++++++++++++ e2e-tests/utils.ts | 25 +++++++++++++--- 2 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 e2e-tests/page-alias.spec.ts diff --git a/e2e-tests/page-alias.spec.ts b/e2e-tests/page-alias.spec.ts new file mode 100644 index 00000000000..06247386223 --- /dev/null +++ b/e2e-tests/page-alias.spec.ts @@ -0,0 +1,58 @@ +import { expect } from '@playwright/test' +import { test } from './fixtures' +import { IsMac, createRandomPage, newBlock, lastBlock } from './utils' + + +test('page alias', async ({ page }) => { + let hotkeyOpenLink = 'Control+o' + let hotkeyBack = 'Control+[' + if (IsMac) { + hotkeyOpenLink = 'Meta+o' + hotkeyBack = 'Meta+[' + } + + // shortcut opening test + await createRandomPage(page) + + await page.fill(':nth-match(textarea, 1)', '[[page alias test target page]]') + await page.keyboard.press(hotkeyOpenLink) + + // build target Page with alias + await page.type(':nth-match(textarea, 1)', 'alias:: [[page alias test alias page]]') + await page.press(':nth-match(textarea, 1)', 'Enter') // double Enter for exit property editing + await page.press(':nth-match(textarea, 1)', 'Enter') + await page.type(':nth-match(textarea, 1)', 'page alias test content') + await page.keyboard.press(hotkeyBack) + + // create alias ref in origin Page + await newBlock(page) + await page.type(':nth-match(textarea, 1)', '[[page alias test alias page]]') + await page.keyboard.press(hotkeyOpenLink) + + // shortcut opening test + await lastBlock(page, true) + expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('page alias test content') + await newBlock(page, true) + await page.type(':nth-match(textarea, 1)', 'yet another page alias test content') + await page.keyboard.press(hotkeyBack) + + // pressing enter opening test + await lastBlock(page, true) + await page.press(':nth-match(textarea, 1)', 'ArrowLeft') + 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 lastBlock(page, true) + expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('yet another page alias test content') + await newBlock(page, true) + await page.type(':nth-match(textarea, 1)', 'still another page alias test content') + await page.keyboard.press(hotkeyBack) + + // clicking opening test + await page.click('.page-blocks-inner .ls-block .page-ref >> nth=-1') + await lastBlock(page, true) + expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('still another page alias test content') + + // TODO: test alias from graph clicking + // TODO: test alias from search clicking +}) \ No newline at end of file diff --git a/e2e-tests/utils.ts b/e2e-tests/utils.ts index d8311d694ce..448b0babe03 100644 --- a/e2e-tests/utils.ts +++ b/e2e-tests/utils.ts @@ -35,19 +35,36 @@ export async function createRandomPage(page: Page) { await page.waitForSelector(':nth-match(textarea, 1)', { state: 'visible' }) } -export async function lastBlock(page: Page): Promise { +/** +* Locate the last block in the editor +* @param page The Playwright Page object. +* @param inner_only If true, only return the .page-inner-block which has no +extra blocks like linked references included. Defaults to false. +* @returns The locator of the last block. +*/ +export async function lastBlock(page: Page, inner_only: Boolean = false): Promise { // discard any popups await page.keyboard.press('Escape') // click last block - await page.click('.ls-block >> nth=-1') + if (inner_only) + await page.click('.page-blocks-inner .ls-block >> nth=-1') + else + await page.click('.ls-block >> nth=-1') // wait for textarea await page.waitForSelector(':nth-match(textarea, 1)', { state: 'visible' }) return page.locator(':nth-match(textarea, 1)') } -export async function newBlock(page: Page): Promise { - await lastBlock(page) +/** +* Create and locate a new block at the end of the editor +* @param page The Playwright Page object +* @param inner_only If true, only consider the .page-inner-block that no extra +blocks like linked references considered. Defaults to false. +* @returns The locator of the last block +*/ +export async function newBlock(page: Page, inner_only: Boolean = false): Promise { + await lastBlock(page, inner_only) await page.press(':nth-match(textarea, 1)', 'Enter') return page.locator(':nth-match(textarea, 1)')