Files
AFFiNE-Mirror/tests/quick-search.spec.ts
DarkSky 6c2c7dcd48 milestone: publish alpha version (#637)
- document folder
- full-text search
- blob storage
- basic edgeless support

Co-authored-by: tzhangchi <terry.zhangchi@outlook.com>
Co-authored-by: QiShaoXuan <qishaoxuan777@gmail.com>
Co-authored-by: DiamondThree <diamond.shx@gmail.com>
Co-authored-by: MingLiang Wang <mingliangwang0o0@gmail.com>
Co-authored-by: JimmFly <yangjinfei001@gmail.com>
Co-authored-by: Yifeng Wang <doodlewind@toeverything.info>
Co-authored-by: Himself65 <himself65@outlook.com>
Co-authored-by: lawvs <18554747+lawvs@users.noreply.github.com>
Co-authored-by: Qi <474021214@qq.com>
2022-12-30 21:40:15 +08:00

109 lines
3.6 KiB
TypeScript

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