2023-04-25 06:12:48 +03:00
|
|
|
import { test } from '@affine-test/kit/playwright';
|
2023-07-13 12:05:01 +03:00
|
|
|
import { withCtrlOrMeta } from '@affine-test/kit/utils/keyboard';
|
|
|
|
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
2023-08-22 02:36:39 +03:00
|
|
|
import {
|
2023-09-02 08:57:04 +03:00
|
|
|
clickNewPageButton,
|
2023-08-22 02:36:39 +03:00
|
|
|
getBlockSuiteEditorTitle,
|
2023-09-02 06:31:07 +03:00
|
|
|
waitForEditorLoad,
|
2023-08-22 02:36:39 +03:00
|
|
|
} from '@affine-test/kit/utils/page-logic';
|
2023-02-05 13:41:18 +03:00
|
|
|
import { expect, type Page } from '@playwright/test';
|
2023-02-17 10:33:32 +03:00
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
const openQuickSearchByShortcut = async (page: Page) => {
|
2022-12-30 16:40:15 +03:00
|
|
|
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
|
2023-08-29 13:07:05 +03:00
|
|
|
await page.waitForTimeout(500);
|
|
|
|
};
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-02-09 01:05:15 +03:00
|
|
|
async function assertTitle(page: Page, text: string) {
|
2023-02-23 11:22:00 +03:00
|
|
|
const edgeless = page.locator('affine-edgeless-page');
|
|
|
|
if (!edgeless) {
|
2023-08-05 02:55:28 +03:00
|
|
|
const locator = page.locator('.affine-doc-page-block-title').nth(0);
|
2023-02-23 11:22:00 +03:00
|
|
|
const actual = await locator.inputValue();
|
|
|
|
expect(actual).toBe(text);
|
|
|
|
}
|
2022-12-30 16:40:15 +03:00
|
|
|
}
|
2023-04-17 00:02:41 +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-04-17 00:02:41 +03:00
|
|
|
|
2023-02-09 01:05:15 +03:00
|
|
|
async function titleIsFocused(page: Page) {
|
2023-02-23 11:22:00 +03:00
|
|
|
const edgeless = page.locator('affine-edgeless-page');
|
|
|
|
if (!edgeless) {
|
2023-08-05 02:55:28 +03:00
|
|
|
const title = page.locator('.affine-doc-page-block-title');
|
2023-02-23 11:22:00 +03:00
|
|
|
await expect(title).toBeVisible();
|
|
|
|
await expect(title).toBeFocused();
|
|
|
|
}
|
2023-02-09 01:05:15 +03:00
|
|
|
}
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Click slider bar button', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
const quickSearchButton = page.locator(
|
|
|
|
'[data-testid=slider-bar-quick-search-button]'
|
|
|
|
);
|
|
|
|
await quickSearchButton.click();
|
|
|
|
const quickSearch = page.locator('[data-testid=quickSearch]');
|
|
|
|
await expect(quickSearch).toBeVisible();
|
|
|
|
});
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Click arrowDown icon after title', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
const quickSearchButton = page.locator(
|
|
|
|
'[data-testid=slider-bar-quick-search-button]'
|
|
|
|
);
|
|
|
|
await quickSearchButton.click();
|
|
|
|
const quickSearch = page.locator('[data-testid=quickSearch]');
|
|
|
|
await expect(quickSearch).toBeVisible();
|
|
|
|
});
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Press the shortcut key cmd+k', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const quickSearch = page.locator('[data-testid=quickSearch]');
|
|
|
|
await expect(quickSearch).toBeVisible();
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Create a new page without keyword', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const addNewPage = page.locator('[data-testid=quick-search-add-new-page]');
|
|
|
|
await addNewPage.click();
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertTitle(page, '');
|
|
|
|
});
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Create a new page with keyword', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
const addNewPage = page.locator('[data-testid=quick-search-add-new-page]');
|
|
|
|
await addNewPage.click();
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertTitle(page, 'test123456');
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Enter a keyword to search for', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
const actual = await page.locator('[cmdk-input]').inputValue();
|
|
|
|
expect(actual).toBe('test123456');
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
2023-04-17 00:02:41 +03:00
|
|
|
|
|
|
|
test('Create a new page and search this page', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
// input title and create new page
|
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
const addNewPage = page.locator('[data-testid=quick-search-add-new-page]');
|
|
|
|
await addNewPage.click();
|
|
|
|
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertTitle(page, 'test123456');
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertResultList(page, ['test123456']);
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertTitle(page, 'test123456');
|
2023-08-23 03:38:02 +03:00
|
|
|
|
|
|
|
await page.reload();
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-08-23 03:38:02 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertResultList(page, ['test123456']);
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertTitle(page, 'test123456');
|
2023-02-07 08:21:42 +03:00
|
|
|
});
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Navigate to the 404 page and try to open quick search', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await page.goto('http://localhost:8080/404');
|
2023-09-17 06:50:26 +03:00
|
|
|
const notFoundTip = page.getByTestId('not-found');
|
2023-04-17 00:02:41 +03:00
|
|
|
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
|
|
|
});
|
2023-02-09 01:05:15 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Open quick search on local page', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const publishedSearchResults = page.locator('[publishedSearchResults]');
|
|
|
|
await expect(publishedSearchResults).toBeVisible({ visible: false });
|
2023-02-09 01:05:15 +03:00
|
|
|
});
|
2023-04-13 11:31:28 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
test('Autofocus input after opening quick search', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
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 openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
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 openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const addNewPage = page.locator('[data-testid=quick-search-add-new-page]');
|
|
|
|
await addNewPage.click();
|
|
|
|
await titleIsFocused(page);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Not show navigation path if page is not a subpage or current page is not in editor', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
expect(await page.getByTestId('navigation-path').count()).toBe(0);
|
|
|
|
});
|
2023-08-21 20:01:53 +03:00
|
|
|
|
2023-08-22 03:19:59 +03:00
|
|
|
test('assert the recent browse pages are on the recent list', async ({
|
2023-08-21 20:01:53 +03:00
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-08-21 20:01:53 +03:00
|
|
|
|
|
|
|
// create first page
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-08-22 03:19:59 +03:00
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.type('sgtokidoki', {
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
}
|
2023-08-22 02:36:39 +03:00
|
|
|
await page.waitForTimeout(200);
|
2023-08-21 20:01:53 +03:00
|
|
|
|
|
|
|
// create second page
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const addNewPage = page.getByTestId('quick-search-add-new-page');
|
|
|
|
await addNewPage.click();
|
2023-08-22 03:19:59 +03:00
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.type('theliquidhorse', {
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
}
|
2023-08-22 02:36:39 +03:00
|
|
|
await page.waitForTimeout(200);
|
2023-08-21 20:01:53 +03:00
|
|
|
|
|
|
|
// create thrid page
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await addNewPage.click();
|
2023-08-22 03:19:59 +03:00
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.type('battlekot', {
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
}
|
2023-08-22 02:36:39 +03:00
|
|
|
await page.waitForTimeout(200);
|
2023-08-21 20:01:53 +03:00
|
|
|
|
|
|
|
await openQuickSearchByShortcut(page);
|
2023-08-22 02:36:39 +03:00
|
|
|
await page.waitForTimeout(200);
|
|
|
|
{
|
|
|
|
// check does all 3 pages exists on recent page list
|
|
|
|
const quickSearchItems = page.locator('[cmdk-item]');
|
|
|
|
expect(await quickSearchItems.nth(0).textContent()).toBe('battlekot');
|
|
|
|
expect(await quickSearchItems.nth(1).textContent()).toBe('theliquidhorse');
|
|
|
|
expect(await quickSearchItems.nth(2).textContent()).toBe('sgtokidoki');
|
|
|
|
}
|
2023-08-21 20:01:53 +03:00
|
|
|
|
2023-08-22 02:36:39 +03:00
|
|
|
// create forth page, and check does the recent page list only contains three pages
|
2023-08-22 07:17:45 +03:00
|
|
|
await page.reload();
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-08-21 20:01:53 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
2023-08-22 07:17:45 +03:00
|
|
|
{
|
|
|
|
const addNewPage = page.getByTestId('quick-search-add-new-page');
|
|
|
|
await addNewPage.click();
|
|
|
|
}
|
2023-08-22 02:36:39 +03:00
|
|
|
await page.waitForTimeout(200);
|
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.type('affine is the best', {
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
await page.waitForTimeout(1000);
|
2023-08-21 20:01:53 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
2023-08-22 02:36:39 +03:00
|
|
|
{
|
|
|
|
const quickSearchItems = page.locator('[cmdk-item]');
|
|
|
|
expect(await quickSearchItems.nth(0).textContent()).toBe(
|
|
|
|
'affine is the best'
|
|
|
|
);
|
|
|
|
}
|
2023-08-21 20:01:53 +03:00
|
|
|
});
|