Skip to content

Commit

Permalink
test(e2e): improve search modal e2e stability
Browse files Browse the repository at this point in the history
  • Loading branch information
cnrpman authored and logseq-cldwalker committed Jun 5, 2023
1 parent 8cbee20 commit 6b0ad47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion e2e-tests/page-rename.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, Page } from '@playwright/test'
import { test } from './fixtures'
import { createPage, randomLowerString, randomString, renamePage, searchPage } from './utils'
import { closeSearchBox, createPage, randomLowerString, randomString, renamePage, searchPage } from './utils'

/***
* Test rename feature
Expand Down Expand Up @@ -73,6 +73,7 @@ test('page rename test', async ({ page }) => {
const thirdResultRow = await results[2].innerText()
expect(thirdResultRow).toContain("dCBA_");
expect(thirdResultRow).not.toContain("DcBA_");
await closeSearchBox(page)
})

// TODO introduce more samples when #4722 is fixed
Expand Down
13 changes: 7 additions & 6 deletions e2e-tests/util/search-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export async function createRandomPage(page: Page) {
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
Expand All @@ -48,16 +54,11 @@ export async function createRandomPage(page: Page) {
* @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"]')
await page.type('[placeholder="Search or create page"]', query, { delay: 10 })
await page.waitForTimeout(2000) // wait longer for search contents to render

return page.$$('#ui__ac-inner>div');
}

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
}

0 comments on commit 6b0ad47

Please sign in to comment.