test: add test case for quick search

This commit is contained in:
JimmFly
2023-01-03 16:23:43 +08:00
committed by DarkSky
parent 570ebe7923
commit 10087761c8

View File

@@ -1,38 +1,26 @@
import { test, expect, type Page } from '@playwright/test'; import { test, expect, type Page } from '@playwright/test';
import { loadPage } from './libs/load-page'; import { loadPage } from './libs/load-page';
import { withCtrlOrMeta } from './libs/keyboard'; import { withCtrlOrMeta } from './libs/keyboard';
import { newPage } from './libs/page-logic';
loadPage(); loadPage();
const openQuickSearchByShortcut = async (page: Page) => const openQuickSearchByShortcut = async (page: Page) =>
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 })); await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
async function assertTitleTexts( async function assertTitleTexts(page: Page, texts: string[]) {
page: Page,
texts: string[],
option?: { delay: number }
) {
await page.mouse.move(100, 100);
const actual = await page const actual = await page
.locator('[class=affine-default-page-block-title]') .locator('.affine-default-page-block-title')
.allInnerTexts(); .allTextContents();
await page.waitForTimeout(option?.delay || 0);
expect(actual).toEqual(texts); expect(actual).toEqual(texts);
} }
async function assertResultList( async function assertResultList(page: Page, texts: string[]) {
page: Page,
texts: string[],
option?: { delay: number }
) {
await page.mouse.move(100, 100);
const actual = await page.locator('[cmdk-item]').allInnerTexts(); const actual = await page.locator('[cmdk-item]').allInnerTexts();
await page.waitForTimeout(option?.delay || 0);
expect(actual).toEqual(texts); expect(actual).toEqual(texts);
} }
test.describe('Open quick search', () => { test.describe('Open quick search', () => {
test('Click slider bar button', async ({ page }) => { test('Click slider bar button', async ({ page }) => {
await newPage(page);
const quickSearchButton = page.locator( const quickSearchButton = page.locator(
'[data-testid=sliderBar-quickSearchButton]' '[data-testid=sliderBar-quickSearchButton]'
); );
@@ -42,7 +30,7 @@ test.describe('Open quick search', () => {
}); });
test('Click arrowDown icon after title', async ({ page }) => { test('Click arrowDown icon after title', async ({ page }) => {
//header-quickSearchButton await newPage(page);
const quickSearchButton = page.locator( const quickSearchButton = page.locator(
'[data-testid=header-quickSearchButton]' '[data-testid=header-quickSearchButton]'
); );
@@ -51,58 +39,46 @@ test.describe('Open quick search', () => {
await expect(quickSearch).toBeVisible(); await expect(quickSearch).toBeVisible();
}); });
// test('Press the shortcut key cmd+k', async ({ page }) => { test('Press the shortcut key cmd+k', async ({ page }) => {
// // why 1000ms page wait? await newPage(page);
// page.waitForTimeout(1000); await openQuickSearchByShortcut(page);
// await openQuickSearchByShortcut(page); const quickSearch = page.locator('[data-testid=quickSearch]');
// const quickSearch = page.locator('[data-testid=quickSearch]'); await expect(quickSearch).toBeVisible();
});
// await expect(quickSearch).toBeVisible();
// });
}); });
test.describe('Add new page in quick search', () => { test.describe('Add new page in quick search', () => {
// FIXME: not working // FIXME: not working
test.skip('Create a new page without keyword', async ({ page }) => { test('Create a new page without keyword', async ({ page }) => {
await newPage(page);
await openQuickSearchByShortcut(page); await openQuickSearchByShortcut(page);
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]'); const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
await addNewPage.click(); await addNewPage.click();
await assertTitleTexts(page, [''], { delay: 50 }); await assertTitleTexts(page, ['']);
}); });
test.skip('Create a new page with keyword', async ({ page }) => { test('Create a new page with keyword', async ({ page }) => {
await newPage(page);
await openQuickSearchByShortcut(page); await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test'); await page.keyboard.insertText('test123456');
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]'); const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
await addNewPage.click(); await addNewPage.click();
await assertTitleTexts(page, ['test'], { delay: 50 }); await assertTitleTexts(page, ['test123456']);
}); });
}); });
test.describe('Search and select', () => { test.describe('Search and select', () => {
// test('Search and get results', async ({ page }) => { test('Create a new page and search this page', async ({ page }) => {
// // why 1000ms page wait? await newPage(page);
// await openQuickSearchByShortcut(page);
// await page.keyboard.insertText('Welcome');
// await assertResultList(page, ['Welcome to the AFFiNE Alpha'], {
// delay: 50,
// });
// });
//TODO FIXME: This test is not working
test.skip('Create a new page and search this page', async ({ page }) => {
await openQuickSearchByShortcut(page); await openQuickSearchByShortcut(page);
await page.keyboard.insertText('Welcome'); await page.keyboard.insertText('test123456');
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]'); const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
await addNewPage.click(); await addNewPage.click();
await page.waitForTimeout(500); await page.waitForTimeout(200);
await openQuickSearchByShortcut(page); await openQuickSearchByShortcut(page);
await page.keyboard.insertText('Welcome'); await page.keyboard.insertText('test123456');
await assertResultList(page, ['Welcome to the AFFiNE Alpha', 'Welcome']); await assertResultList(page, ['test123456']);
await page.keyboard.press('ArrowDown', { delay: 50 });
await page.keyboard.press('Enter', { delay: 50 }); await page.keyboard.press('Enter', { delay: 50 });
await assertTitleTexts(page, ['Welcome'], { await assertTitleTexts(page, ['test123456']);
delay: 50,
});
}); });
}); });