fix(core): polling to search in cmdk (#5274)

This is a temporary solution until https://github.com/toeverything/blocksuite/issues/5668 be solved.
This commit is contained in:
EYHN
2023-12-12 10:22:34 +00:00
committed by JimmFly
parent 9aa33d0228
commit b782b3fb1b
3 changed files with 74 additions and 27 deletions

View File

@@ -16,6 +16,12 @@ const openQuickSearchByShortcut = async (page: Page, checkVisible = true) => {
}
};
const insertInputText = async (page: Page, text: string) => {
await page.locator('[cmdk-input]').fill(text);
const actual = await page.locator('[cmdk-input]').inputValue();
expect(actual).toBe(text);
};
const keyboardDownAndSelect = async (page: Page, label: string) => {
await page.keyboard.press('ArrowDown');
if (
@@ -77,14 +83,16 @@ async function waitForScrollToFinish(page: Page) {
}
async function assertResultList(page: Page, texts: string[]) {
const actual = await page
.locator('[cmdk-item] [data-testid=cmdk-label]')
.allInnerTexts();
const actualSplit = actual[0].split('\n');
expect(actualSplit[0]).toEqual(texts[0]);
if (actualSplit[1]) {
expect(actualSplit[1]).toEqual(texts[1]);
}
await expect(async () => {
const actual = await page
.locator('[cmdk-item] [data-testid=cmdk-label]')
.allInnerTexts();
const actualSplit = actual[0].split('\n');
expect(actualSplit[0]).toEqual(texts[0]);
if (actualSplit[1]) {
expect(actualSplit[1]).toEqual(texts[1]);
}
}).toPass();
}
async function titleIsFocused(page: Page) {
@@ -137,7 +145,7 @@ test('Create a new page with keyword', async ({ page }) => {
await waitForEditorLoad(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('"test123456"');
await insertInputText(page, '"test123456"');
const addNewPage = page.locator(
'[cmdk-item] >> text=New ""test123456"" Page'
);
@@ -151,9 +159,7 @@ test('Enter a keyword to search for', async ({ page }) => {
await waitForEditorLoad(page);
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test123456');
const actual = await page.locator('[cmdk-input]').inputValue();
expect(actual).toBe('test123456');
await insertInputText(page, 'test123456');
});
test('Create a new page and search this page', async ({ page }) => {
@@ -162,7 +168,7 @@ test('Create a new page and search this page', async ({ page }) => {
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
// input title and create new page
await page.keyboard.insertText('test123456');
await insertInputText(page, 'test123456');
await page.waitForTimeout(300);
const addNewPage = page.locator('[cmdk-item] >> text=New "test123456" Page');
await addNewPage.click();
@@ -170,7 +176,7 @@ test('Create a new page and search this page', async ({ page }) => {
await page.waitForTimeout(300);
await assertTitle(page, 'test123456');
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test123456');
await insertInputText(page, 'test123456');
await page.waitForTimeout(300);
await assertResultList(page, ['test123456', 'test123456']);
await page.keyboard.press('Enter');
@@ -180,7 +186,7 @@ test('Create a new page and search this page', async ({ page }) => {
await page.reload();
await waitForEditorLoad(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test123456');
await insertInputText(page, 'test123456');
await page.waitForTimeout(300);
await assertResultList(page, ['test123456', 'test123456']);
await page.keyboard.press('Enter');
@@ -375,7 +381,7 @@ test('show not found item', async ({ page }) => {
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
// input title and create new page
await page.keyboard.insertText('test123456');
await insertInputText(page, 'test123456');
const notFoundItem = page.getByTestId('cmdk-search-not-found');
await expect(notFoundItem).toBeVisible();
await expect(notFoundItem).toHaveText('Search for "test123456"');
@@ -395,15 +401,17 @@ test('can use cmdk to search page content and scroll to it, then the block will
await page.keyboard.press('Enter', { delay: 10 });
}
await page.keyboard.insertText('123456');
const textBlock = page.getByText('123456');
await expect(textBlock).toBeVisible();
await clickSideBarAllPageButton(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('123456');
await insertInputText(page, '123456');
await page.waitForTimeout(300);
await assertResultList(page, [
'this is a new page to search for content',
'123456',
]);
await page.keyboard.press('Enter');
await page.locator('[cmdk-item] [data-testid=cmdk-label]').first().click();
await waitForScrollToFinish(page);
const isVisitable = await checkElementIsInView(page, '123456');
expect(isVisitable).toBe(true);
@@ -424,7 +432,7 @@ test('Create a new page with special characters in the title and search for this
await getBlockSuiteEditorTitle(page).fill(specialTitle);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText(specialTitle);
await insertInputText(page, specialTitle);
await page.waitForTimeout(300);
await assertResultList(page, [specialTitle, specialTitle]);