Selaa lähdekoodia

test(e2e): split util functions

Junyi Du 3 vuotta sitten
vanhempi
sitoutus
6aafeb40ca
2 muutettua tiedostoa jossa 31 lisäystä ja 20 poistoa
  1. 7 7
      e2e-tests/page-alias.spec.ts
  2. 24 13
      e2e-tests/utils.ts

+ 7 - 7
e2e-tests/page-alias.spec.ts

@@ -1,6 +1,6 @@
 import { expect } from '@playwright/test'
 import { test } from './fixtures'
-import { IsMac, createRandomPage, newBlock, lastBlock } from './utils'
+import { IsMac, createRandomPage, newBlock, newInnerBlock, lastBlock, lastInnerBlock } from './utils'
 
 
 test('page alias', async ({ page }) => {
@@ -30,27 +30,27 @@ test('page alias', async ({ page }) => {
   await page.keyboard.press(hotkeyOpenLink)
 
   // shortcut opening test
-  await lastBlock(page, true)
+  await lastInnerBlock(page)
   expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('page alias test content')
-  await newBlock(page, true)
+  await newInnerBlock(page)
   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 lastInnerBlock(page)
   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)
+  await lastInnerBlock(page)
   expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('yet another page alias test content')
-  await newBlock(page, true)
+  await newInnerBlock(page)
   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)
+  await lastInnerBlock(page)
   expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('still another page alias test content')
 
   // TODO: test alias from graph clicking

+ 24 - 13
e2e-tests/utils.ts

@@ -36,20 +36,26 @@ export async function createRandomPage(page: Page) {
 }
 
 /**
-* Locate the last block in the editor
+* Locate the last block in the inner 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> {
+export async function lastInnerBlock(page: Page): Promise<Locator> {
     // discard any popups
     await page.keyboard.press('Escape')
     // click last block
-    if (inner_only) 
-        await page.click('.page-blocks-inner .ls-block >> nth=-1')
-    else
-        await page.click('.ls-block >> nth=-1')
+    await page.click('.page-blocks-inner .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 lastBlock(page: Page): Promise<Locator> {
+    // discard any popups
+    await page.keyboard.press('Escape')
+    // click last block
+    await page.click('.ls-block >> nth=-1')
     // wait for textarea
     await page.waitForSelector(':nth-match(textarea, 1)', { state: 'visible' })
 
@@ -57,14 +63,19 @@ export async function lastBlock(page: Page, inner_only: Boolean = false): Promis
 }
 
 /**
-* Create and locate a new block at the end of the editor
+* Create and locate a new block at the end of the inner 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)
+export async function newInnerBlock(page: Page): Promise<Locator> {
+    await lastInnerBlock(page)
+    await page.press(':nth-match(textarea, 1)', 'Enter')
+
+    return page.locator(':nth-match(textarea, 1)')
+}
+
+export async function newBlock(page: Page): Promise<Locator> {
+    await lastBlock(page)
     await page.press(':nth-match(textarea, 1)', 'Enter')
 
     return page.locator(':nth-match(textarea, 1)')