2023-02-05 13:41:18 +03:00
|
|
|
import { expect, type Page } from '@playwright/test';
|
2023-02-17 05:43:52 +03:00
|
|
|
import { test } from './libs/playwright';
|
|
|
|
import { loadPage } from './libs/load-page';
|
|
|
|
import { withCtrlOrMeta } from './libs/keyboard';
|
|
|
|
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-02-09 01:05:15 +03:00
|
|
|
async function assertTitle(page: Page, text: string) {
|
|
|
|
const locator = page.locator('.affine-default-page-block-title').nth(0);
|
|
|
|
const actual = await locator.inputValue();
|
|
|
|
expect(actual).toBe(text);
|
2022-12-30 16:40:15 +03:00
|
|
|
}
|
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);
|
|
|
|
}
|
2023-02-09 01:05:15 +03:00
|
|
|
async function titleIsFocused(page: Page) {
|
|
|
|
const title = page.locator('.affine-default-page-block-title');
|
|
|
|
await expect(title).toBeVisible();
|
|
|
|
await expect(title).toBeFocused();
|
|
|
|
}
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-02-05 12:53:14 +03:00
|
|
|
test.describe('Open quick search', () => {
|
2022-12-30 16:40:15 +03:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2023-02-05 12:53:14 +03:00
|
|
|
test.describe('Add new page in quick search', () => {
|
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-02-07 05:14:23 +03:00
|
|
|
await page.waitForTimeout(300);
|
2023-02-09 01:05:15 +03:00
|
|
|
await assertTitle(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-02-07 05:14:23 +03:00
|
|
|
await page.waitForTimeout(300);
|
2023-02-09 01:05:15 +03:00
|
|
|
await assertTitle(page, 'test123456');
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-05 12:53:14 +03:00
|
|
|
test.describe('Search and select', () => {
|
2023-02-09 01:05:15 +03:00
|
|
|
test('Enter a keyword to search for', async ({ page }) => {
|
|
|
|
await newPage(page);
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
const actual = await page.locator('[cmdk-input]').inputValue();
|
|
|
|
expect(actual).toBe('test123456');
|
|
|
|
});
|
2023-02-07 06:12:01 +03:00
|
|
|
test('Create a new page and search this page', async ({ page }) => {
|
2023-01-03 11:23:43 +03:00
|
|
|
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-02-07 05:14:23 +03:00
|
|
|
await page.waitForTimeout(300);
|
2023-02-09 01:05:15 +03:00
|
|
|
await assertTitle(page, 'test123456');
|
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']);
|
2023-02-07 05:14:23 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await page.waitForTimeout(300);
|
2023-02-09 01:05:15 +03:00
|
|
|
await assertTitle(page, 'test123456');
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
|
|
|
});
|
2023-02-07 08:21:42 +03:00
|
|
|
test.describe('Disable search on 404 page', () => {
|
|
|
|
test('Navigate to the 404 page and try to open quick search', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await page.goto('http://localhost:8080/404');
|
|
|
|
const notFoundTip = page.locator('[data-testid=notFound]');
|
|
|
|
await expect(notFoundTip).toBeVisible();
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const quickSearch = page.locator('[data-testid=quickSearch]');
|
|
|
|
await expect(quickSearch).toBeVisible({ visible: false });
|
|
|
|
});
|
|
|
|
});
|
2023-02-07 08:56:58 +03:00
|
|
|
test.describe('Open quick search on the published page', () => {
|
|
|
|
test('Open quick search on local page', async ({ page }) => {
|
|
|
|
await newPage(page);
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const publishedSearchResults = page.locator('[publishedSearchResults]');
|
|
|
|
await expect(publishedSearchResults).toBeVisible({ visible: false });
|
|
|
|
});
|
|
|
|
});
|
2023-02-09 01:05:15 +03:00
|
|
|
|
|
|
|
test.describe('Focus event for quick search', () => {
|
|
|
|
test('Autofocus input after opening quick search', async ({ page }) => {
|
|
|
|
await newPage(page);
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const locator = page.locator('[cmdk-input]');
|
|
|
|
await expect(locator).toBeVisible();
|
|
|
|
await expect(locator).toBeFocused();
|
|
|
|
});
|
|
|
|
test('Autofocus input after select', async ({ page }) => {
|
|
|
|
await newPage(page);
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await page.keyboard.press('ArrowUp');
|
|
|
|
const locator = page.locator('[cmdk-input]');
|
|
|
|
await expect(locator).toBeVisible();
|
|
|
|
await expect(locator).toBeFocused();
|
|
|
|
});
|
|
|
|
test('Focus title after creating a new page', async ({ page }) => {
|
|
|
|
await newPage(page);
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
|
|
|
|
await addNewPage.click();
|
|
|
|
await titleIsFocused(page);
|
|
|
|
});
|
|
|
|
});
|