2022-12-30 16:40:15 +03:00
|
|
|
import { test, expect, type Page } from '@playwright/test';
|
|
|
|
import { loadPage } from './libs/load-page';
|
|
|
|
import { withCtrlOrMeta } from './libs/keyboard';
|
2023-01-03 11:23:43 +03:00
|
|
|
import { newPage } from './libs/page-logic';
|
2022-12-30 16:40:15 +03:00
|
|
|
loadPage();
|
|
|
|
|
|
|
|
const openQuickSearchByShortcut = async (page: Page) =>
|
|
|
|
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
|
|
|
|
|
2023-01-03 11:23:43 +03:00
|
|
|
async function assertTitleTexts(page: Page, texts: string[]) {
|
2022-12-30 16:40:15 +03:00
|
|
|
const actual = await page
|
2023-01-03 11:23:43 +03:00
|
|
|
.locator('.affine-default-page-block-title')
|
|
|
|
.allTextContents();
|
2022-12-30 16:40:15 +03:00
|
|
|
expect(actual).toEqual(texts);
|
|
|
|
}
|
2023-01-03 11:23:43 +03:00
|
|
|
async function assertResultList(page: Page, texts: string[]) {
|
2022-12-30 16:40:15 +03:00
|
|
|
const actual = await page.locator('[cmdk-item]').allInnerTexts();
|
|
|
|
expect(actual).toEqual(texts);
|
|
|
|
}
|
|
|
|
|
|
|
|
test.describe('Open quick search', () => {
|
|
|
|
test('Click slider bar button', async ({ page }) => {
|
2023-01-03 11:23:43 +03:00
|
|
|
await newPage(page);
|
2022-12-30 16:40:15 +03:00
|
|
|
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 }) => {
|
2023-01-03 11:23:43 +03:00
|
|
|
await newPage(page);
|
2022-12-30 16:40:15 +03:00
|
|
|
const quickSearchButton = page.locator(
|
|
|
|
'[data-testid=header-quickSearchButton]'
|
|
|
|
);
|
|
|
|
await quickSearchButton.click();
|
|
|
|
const quickSearch = page.locator('[data-testid=quickSearch]');
|
|
|
|
await expect(quickSearch).toBeVisible();
|
|
|
|
});
|
|
|
|
|
2023-01-03 11:23:43 +03:00
|
|
|
test('Press the shortcut key cmd+k', async ({ page }) => {
|
|
|
|
await newPage(page);
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const quickSearch = page.locator('[data-testid=quickSearch]');
|
|
|
|
await expect(quickSearch).toBeVisible();
|
|
|
|
});
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test.describe('Add new page in quick search', () => {
|
|
|
|
// FIXME: not working
|
2023-01-03 11:23:43 +03:00
|
|
|
test('Create a new page without keyword', async ({ page }) => {
|
|
|
|
await newPage(page);
|
2022-12-30 16:40:15 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
|
|
|
|
await addNewPage.click();
|
2023-01-03 11:40:59 +03:00
|
|
|
await page.waitForTimeout(200);
|
2023-01-03 11:23:43 +03:00
|
|
|
await assertTitleTexts(page, ['']);
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
|
|
|
|
2023-01-03 11:23:43 +03:00
|
|
|
test('Create a new page with keyword', async ({ page }) => {
|
|
|
|
await newPage(page);
|
2022-12-30 16:40:15 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
2023-01-03 11:23:43 +03:00
|
|
|
await page.keyboard.insertText('test123456');
|
2022-12-30 16:40:15 +03:00
|
|
|
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
|
|
|
|
await addNewPage.click();
|
2023-01-03 11:40:59 +03:00
|
|
|
await page.waitForTimeout(200);
|
2023-01-03 11:23:43 +03:00
|
|
|
await assertTitleTexts(page, ['test123456']);
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.describe('Search and select', () => {
|
2023-01-03 11:23:43 +03:00
|
|
|
test('Create a new page and search this page', async ({ page }) => {
|
|
|
|
await newPage(page);
|
2022-12-30 16:40:15 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
2023-01-03 11:23:43 +03:00
|
|
|
await page.keyboard.insertText('test123456');
|
2022-12-30 16:40:15 +03:00
|
|
|
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
|
|
|
|
await addNewPage.click();
|
2023-01-03 11:23:43 +03:00
|
|
|
await page.waitForTimeout(200);
|
2022-12-30 16:40:15 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
2023-01-03 11:23:43 +03:00
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
await assertResultList(page, ['test123456']);
|
2022-12-30 16:40:15 +03:00
|
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
2023-01-03 11:23:43 +03:00
|
|
|
await assertTitleTexts(page, ['test123456']);
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
|
|
|
});
|