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-11-02 14:49:49 +03:00
|
|
|
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
|
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-10-12 08:04:58 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-08-29 13:07:05 +03:00
|
|
|
};
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-09-22 17:31:26 +03:00
|
|
|
const keyboardDownAndSelect = async (page: Page, label: string) => {
|
|
|
|
await page.keyboard.press('ArrowDown');
|
|
|
|
if (
|
|
|
|
(await page
|
|
|
|
.locator('[cmdk-item][data-selected] [data-testid="cmdk-label"]')
|
|
|
|
.innerText()) !== label
|
|
|
|
) {
|
|
|
|
await keyboardDownAndSelect(page, label);
|
|
|
|
} else {
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-02 06:22:12 +03:00
|
|
|
const commandsIsVisible = async (page: Page, label: string) => {
|
|
|
|
const locators = page.locator('[cmdk-item] [data-testid="cmdk-label"]');
|
|
|
|
const actual = (await locators.allInnerTexts()).find(text => text === label);
|
|
|
|
return !!actual;
|
|
|
|
};
|
|
|
|
|
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-11-02 14:49:49 +03:00
|
|
|
async function checkElementIsInView(page: Page, searchText: string) {
|
|
|
|
const element = page.getByText(searchText);
|
|
|
|
// check if the element is in view
|
|
|
|
const elementRect = await element.boundingBox();
|
|
|
|
const viewportHeight = page.viewportSize()?.height;
|
|
|
|
|
|
|
|
if (!elementRect || !viewportHeight) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
expect(elementRect.y).toBeLessThan(viewportHeight);
|
|
|
|
expect(elementRect.y + elementRect.height).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function waitForScrollToFinish(page: Page) {
|
|
|
|
await page.evaluate(async () => {
|
|
|
|
await new Promise(resolve => {
|
|
|
|
let lastScrollTop: number;
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
const { scrollTop } = document.documentElement;
|
|
|
|
if (scrollTop != lastScrollTop) {
|
|
|
|
lastScrollTop = scrollTop;
|
|
|
|
} else {
|
|
|
|
clearInterval(interval);
|
|
|
|
resolve(null);
|
|
|
|
}
|
|
|
|
}, 500); // you can adjust the interval time
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-03 11:23:43 +03:00
|
|
|
async function assertResultList(page: Page, texts: string[]) {
|
2023-09-22 17:31:26 +03:00
|
|
|
const actual = await page
|
|
|
|
.locator('[cmdk-item] [data-testid=cmdk-label]')
|
|
|
|
.allInnerTexts();
|
2023-10-24 08:54:37 +03:00
|
|
|
const actualSplit = actual[0].split('\n');
|
|
|
|
expect(actualSplit[0]).toEqual(texts[0]);
|
2023-11-02 14:49:49 +03:00
|
|
|
expect(actualSplit[1]).toEqual(texts[1]);
|
2022-12-30 16:40:15 +03:00
|
|
|
}
|
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();
|
2023-09-22 17:31:26 +03:00
|
|
|
const quickSearch = page.locator('[data-testid=cmdk-quick-search]');
|
2023-04-17 00:02:41 +03:00
|
|
|
await expect(quickSearch).toBeVisible();
|
|
|
|
});
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-09-22 17:31:26 +03:00
|
|
|
test('Press the shortcut key cmd+k and close with esc', async ({ page }) => {
|
2023-04-17 00:02:41 +03:00
|
|
|
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);
|
2023-09-22 17:31:26 +03:00
|
|
|
const quickSearch = page.locator('[data-testid=cmdk-quick-search]');
|
2023-04-17 00:02:41 +03:00
|
|
|
await expect(quickSearch).toBeVisible();
|
2023-09-22 17:31:26 +03:00
|
|
|
|
|
|
|
// press esc to close quick search
|
|
|
|
await page.keyboard.press('Escape');
|
|
|
|
await expect(quickSearch).toBeVisible({ visible: false });
|
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);
|
2023-09-22 17:31:26 +03:00
|
|
|
const addNewPage = page.locator('[cmdk-item] >> text=New Page');
|
2023-04-17 00:02:41 +03:00
|
|
|
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');
|
2023-11-02 11:22:54 +03:00
|
|
|
const addNewPage = page.locator('[cmdk-item] >> text=New "test123456" Page');
|
2023-04-17 00:02:41 +03:00
|
|
|
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);
|
2023-11-02 11:22:54 +03:00
|
|
|
const addNewPage = page.locator('[cmdk-item] >> text=New "test123456" Page');
|
2023-04-17 00:02:41 +03:00
|
|
|
await addNewPage.click();
|
|
|
|
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertTitle(page, 'test123456');
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
await page.waitForTimeout(300);
|
2023-11-02 14:49:49 +03:00
|
|
|
await assertResultList(page, ['test123456', 'test123456']);
|
2023-04-17 00:02:41 +03:00
|
|
|
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);
|
2023-11-02 14:49:49 +03:00
|
|
|
await assertResultList(page, ['test123456', 'test123456']);
|
2023-08-23 03:38:02 +03:00
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertTitle(page, 'test123456');
|
2023-02-07 08:21:42 +03:00
|
|
|
});
|
2023-10-12 08:04:58 +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-22 17:31:26 +03:00
|
|
|
const notFoundTip = page.locator('button >> text=Back to My Content');
|
2023-04-17 00:02:41 +03:00
|
|
|
await expect(notFoundTip).toBeVisible();
|
|
|
|
await openQuickSearchByShortcut(page);
|
2023-09-22 17:31:26 +03:00
|
|
|
const quickSearch = page.locator('[data-testid=cmdk-quick-search]');
|
2023-04-17 00:02:41 +03:00
|
|
|
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);
|
2023-09-22 17:31:26 +03:00
|
|
|
const addNewPage = page.locator('[cmdk-item] >> text=New Page');
|
2023-04-17 00:02:41 +03:00
|
|
|
await addNewPage.click();
|
|
|
|
await titleIsFocused(page);
|
|
|
|
});
|
|
|
|
|
2023-09-22 17:31:26 +03:00
|
|
|
test('can use keyboard down to select goto setting', async ({ page }) => {
|
2023-04-17 00:02:41 +03:00
|
|
|
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);
|
2023-09-22 17:31:26 +03:00
|
|
|
await keyboardDownAndSelect(page, 'Go to Settings');
|
|
|
|
|
|
|
|
await expect(page.getByTestId('setting-modal')).toBeVisible();
|
2023-04-17 00:02:41 +03:00
|
|
|
});
|
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-10-24 08:54:37 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-08-22 03:19:59 +03:00
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-10-24 08:54:37 +03:00
|
|
|
await title.pressSequentially('sgtokidoki');
|
|
|
|
expect(await title.innerText()).toBe('sgtokidoki');
|
2023-08-22 03:19:59 +03:00
|
|
|
}
|
2023-08-21 20:01:53 +03:00
|
|
|
|
|
|
|
// create second page
|
|
|
|
await openQuickSearchByShortcut(page);
|
2023-09-22 17:31:26 +03:00
|
|
|
const addNewPage = page.locator('[cmdk-item] >> text=New Page');
|
2023-08-21 20:01:53 +03:00
|
|
|
await addNewPage.click();
|
2023-10-24 08:54:37 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-08-22 03:19:59 +03:00
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-10-24 08:54:37 +03:00
|
|
|
await title.pressSequentially('theliquidhorse');
|
|
|
|
expect(await title.innerText()).toBe('theliquidhorse');
|
2023-08-22 03:19:59 +03:00
|
|
|
}
|
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-10-24 08:54:37 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-08-22 03:19:59 +03:00
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-10-24 08:54:37 +03:00
|
|
|
await title.pressSequentially('battlekot');
|
|
|
|
expect(await title.innerText()).toBe('battlekot');
|
2023-08-22 03:19:59 +03:00
|
|
|
}
|
2023-08-21 20:01:53 +03:00
|
|
|
|
|
|
|
await openQuickSearchByShortcut(page);
|
2023-08-22 02:36:39 +03:00
|
|
|
{
|
|
|
|
// check does all 3 pages exists on recent page list
|
2023-09-22 17:31:26 +03:00
|
|
|
const quickSearchItems = page.locator(
|
|
|
|
'[cmdk-item] [data-testid="cmdk-label"]'
|
|
|
|
);
|
2023-08-22 02:36:39 +03:00
|
|
|
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
|
|
|
{
|
2023-09-22 17:31:26 +03:00
|
|
|
const addNewPage = page.locator('[cmdk-item] >> text=New Page');
|
2023-08-22 07:17:45 +03:00
|
|
|
await addNewPage.click();
|
|
|
|
}
|
2023-10-24 08:54:37 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-08-22 02:36:39 +03:00
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
2023-10-24 08:54:37 +03:00
|
|
|
await title.pressSequentially('affine is the best');
|
|
|
|
expect(await title.innerText()).toBe('affine is the best');
|
2023-08-22 02:36:39 +03:00
|
|
|
}
|
|
|
|
await page.waitForTimeout(1000);
|
2023-08-21 20:01:53 +03:00
|
|
|
await openQuickSearchByShortcut(page);
|
2023-08-22 02:36:39 +03:00
|
|
|
{
|
2023-09-22 17:31:26 +03:00
|
|
|
const quickSearchItems = page.locator(
|
|
|
|
'[cmdk-item] [data-testid="cmdk-label"]'
|
|
|
|
);
|
2023-08-22 02:36:39 +03:00
|
|
|
expect(await quickSearchItems.nth(0).textContent()).toBe(
|
|
|
|
'affine is the best'
|
|
|
|
);
|
|
|
|
}
|
2023-08-21 20:01:53 +03:00
|
|
|
});
|
2023-10-02 06:22:12 +03:00
|
|
|
|
|
|
|
test('can use cmdk to export pdf', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
await getBlockSuiteEditorTitle(page).click();
|
|
|
|
await getBlockSuiteEditorTitle(page).fill('this is a new page to export');
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const [download] = await Promise.all([
|
|
|
|
page.waitForEvent('download'),
|
|
|
|
keyboardDownAndSelect(page, 'Export to PDF'),
|
|
|
|
]);
|
|
|
|
expect(download.suggestedFilename()).toBe('this is a new page to export.pdf');
|
|
|
|
});
|
|
|
|
test('can use cmdk to export png', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
await getBlockSuiteEditorTitle(page).click();
|
|
|
|
await getBlockSuiteEditorTitle(page).fill('this is a new page to export');
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
const [download] = await Promise.all([
|
|
|
|
page.waitForEvent('download'),
|
|
|
|
keyboardDownAndSelect(page, 'Export to PNG'),
|
|
|
|
]);
|
|
|
|
expect(download.suggestedFilename()).toBe('this is a new page to export.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('can use cmdk to delete page and restore it', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
await getBlockSuiteEditorTitle(page).click();
|
|
|
|
await getBlockSuiteEditorTitle(page).fill('this is a new page to delete');
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await keyboardDownAndSelect(page, 'Move to Trash');
|
|
|
|
await page.getByTestId('confirm-delete-page').click();
|
|
|
|
const restoreButton = page.getByTestId('page-restore-button');
|
|
|
|
await expect(restoreButton).toBeVisible();
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
expect(await commandsIsVisible(page, 'Move to Trash')).toBe(false);
|
|
|
|
expect(await commandsIsVisible(page, 'Export to PDF')).toBe(false);
|
|
|
|
expect(await commandsIsVisible(page, 'Restore from Trash')).toBe(true);
|
|
|
|
await keyboardDownAndSelect(page, 'Restore from Trash');
|
|
|
|
await expect(restoreButton).not.toBeVisible();
|
|
|
|
});
|
2023-10-24 08:54:37 +03:00
|
|
|
|
|
|
|
test('show not found item', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
// input title and create new page
|
|
|
|
await page.keyboard.insertText('test123456');
|
|
|
|
const notFoundItem = page.getByTestId('cmdk-search-not-found');
|
|
|
|
await expect(notFoundItem).toBeVisible();
|
|
|
|
await expect(notFoundItem).toHaveText('Search for "test123456"');
|
|
|
|
});
|
2023-11-02 14:49:49 +03:00
|
|
|
|
2023-11-10 06:02:56 +03:00
|
|
|
test('can use cmdk to search page content and scroll to it, then the block will be selected', async ({
|
2023-11-02 14:49:49 +03:00
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
await getBlockSuiteEditorTitle(page).click();
|
|
|
|
await getBlockSuiteEditorTitle(page).fill(
|
|
|
|
'this is a new page to search for content'
|
|
|
|
);
|
2023-11-10 06:02:56 +03:00
|
|
|
for (let i = 0; i < 30; i++) {
|
|
|
|
await page.keyboard.press('Enter', { delay: 10 });
|
2023-11-02 14:49:49 +03:00
|
|
|
}
|
|
|
|
await page.keyboard.insertText('123456');
|
|
|
|
await clickSideBarAllPageButton(page);
|
|
|
|
await openQuickSearchByShortcut(page);
|
|
|
|
await page.keyboard.insertText('123456');
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
await assertResultList(page, [
|
|
|
|
'this is a new page to search for content',
|
|
|
|
'123456',
|
|
|
|
]);
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await waitForScrollToFinish(page);
|
|
|
|
const isVisitable = await checkElementIsInView(page, '123456');
|
|
|
|
expect(isVisitable).toBe(true);
|
2023-11-10 06:02:56 +03:00
|
|
|
const selectionElement = page.locator('affine-block-selection');
|
|
|
|
await expect(selectionElement).toBeVisible();
|
2023-11-02 14:49:49 +03:00
|
|
|
});
|