소스 검색

test(e2e): improve search modal e2e stability 2

Junyi Du 2 년 전
부모
커밋
b952e2992f
2개의 변경된 파일25개의 추가작업 그리고 22개의 파일을 삭제
  1. 2 1
      e2e-tests/hotkey.spec.ts
  2. 23 21
      e2e-tests/util/search-modal.ts

+ 2 - 1
e2e-tests/hotkey.spec.ts

@@ -1,9 +1,10 @@
 import { expect } from '@playwright/test'
 import { test } from './fixtures'
-import { createRandomPage, enterNextBlock, lastBlock, modKey, IsLinux } from './utils'
+import { createRandomPage, enterNextBlock, lastBlock, modKey, IsLinux, closeSearchBox } from './utils'
 
 test('open search dialog', async ({ page }) => {
   await page.waitForTimeout(200)
+  await closeSearchBox(page)
   await page.keyboard.press(modKey + '+k')
 
   await page.waitForSelector('[placeholder="Search or create page"]')

+ 23 - 21
e2e-tests/util/search-modal.ts

@@ -1,9 +1,15 @@
 import { Page, Locator, ElementHandle } from '@playwright/test'
 import { randomString } from './basic'
 
+export async function closeSearchBox(page: Page): Promise<void> {
+    await page.keyboard.press("Escape") // escape (potential) search box typing
+    await page.waitForTimeout(500)
+    await page.keyboard.press("Escape") // escape modal
+}
+
 export async function createRandomPage(page: Page) {
     const randomTitle = randomString(20)
-  
+    await closeSearchBox(page)
     // Click #search-button
     await page.click('#search-button')
     // Fill [placeholder="Search or create page"]
@@ -16,9 +22,10 @@ export async function createRandomPage(page: Page) {
     await page.waitForSelector('textarea >> nth=0', { state: 'visible' })
   
     return randomTitle;
-  }
+}
   
-  export async function createPage(page: Page, page_name: string) {// Click #search-button
+export async function createPage(page: Page, page_name: string) {// Click #search-button
+    await closeSearchBox(page)
     await page.click('#search-button')
     // Fill [placeholder="Search or create page"]
     await page.fill('[placeholder="Search or create page"]', page_name)
@@ -30,30 +37,25 @@ export async function createRandomPage(page: Page) {
     return page_name;
   }
   
-  export async function searchAndJumpToPage(page: Page, pageTitle: string) {
+export async function searchAndJumpToPage(page: Page, pageTitle: string) {
+    await closeSearchBox(page)
     await page.click('#search-button')
     await page.type('[placeholder="Search or create page"]', pageTitle)
     await page.waitForSelector(`[data-page-ref="${pageTitle}"]`, { state: 'visible' })
     page.click(`[data-page-ref="${pageTitle}"]`)
     await page.waitForNavigation()
     return pageTitle;
-  }
-  
-  export async function closeSearchBox(page: Page): Promise<void> {
-    await page.keyboard.press("Escape") // escape (potential) search box typing
-    await page.waitForTimeout(500)
-    await page.keyboard.press("Escape") // escape modal
-  }
+}
 
-  /**
-   * type a search query into the search box
-   * stop at the point where search box shows up
-   * 
-   * @param page the pw page object
-   * @param query the search query to type into the search box
-   * @returns the HTML element for the search results ui
-   */
-  export async function searchPage(page: Page, query: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>{
+/**
+ * type a search query into the search box
+ * stop at the point where search box shows up
+ * 
+ * @param page the pw page object
+ * @param query the search query to type into the search box
+ * @returns the HTML element for the search results ui
+ */
+export async function searchPage(page: Page, query: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>{
     await closeSearchBox(page)
     await page.click('#search-button')
     await page.waitForSelector('[placeholder="Search or create page"]')
@@ -61,4 +63,4 @@ export async function createRandomPage(page: Page) {
     await page.waitForTimeout(2000) // wait longer for search contents to render
   
     return page.$$('#ui__ac-inner>div');
-  }
+}