mirror of https://github.com/logseq/logseq
test(e2e): improve search modal e2e stability 2
parent
6b0ad475f8
commit
b952e2992f
|
@ -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"]')
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue