Browse Source

test(e2e): add page alias tests

Junyi Du 3 years ago
parent
commit
8798ffed06
2 changed files with 79 additions and 4 deletions
  1. 58 0
      e2e-tests/page-alias.spec.ts
  2. 21 4
      e2e-tests/utils.ts

+ 58 - 0
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
+})

+ 21 - 4
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<Locator> {
+/**
+* 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<Locator> {
     // 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<Locator> {
-    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<Locator> {
+    await lastBlock(page, inner_only)
     await page.press(':nth-match(textarea, 1)', 'Enter')
 
     return page.locator(':nth-match(textarea, 1)')