feat(core): add search result highlighting (#4667)

Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
JimmFly
2023-10-24 13:54:37 +08:00
committed by GitHub
parent 14bee1811c
commit 5226d6c568
35 changed files with 479 additions and 305 deletions

View File

@@ -46,7 +46,9 @@ async function assertResultList(page: Page, texts: string[]) {
const actual = await page
.locator('[cmdk-item] [data-testid=cmdk-label]')
.allInnerTexts();
expect(actual).toEqual(texts);
const actualSplit = actual[0].split('\n');
expect(actualSplit[0]).toEqual(texts[0]);
expect(actualSplit[1]).toEqual(texts[0]);
}
async function titleIsFocused(page: Page) {
@@ -100,9 +102,7 @@ test('Create a new page with keyword', async ({ page }) => {
await clickNewPageButton(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test123456');
const addNewPage = page.locator(
'[cmdk-item] >> text=Create New Page as: test123456'
);
const addNewPage = page.locator('[cmdk-item] >> text=Create New Page as:');
await addNewPage.click();
await page.waitForTimeout(300);
await assertTitle(page, 'test123456');
@@ -126,9 +126,7 @@ test('Create a new page and search this page', async ({ page }) => {
// input title and create new page
await page.keyboard.insertText('test123456');
await page.waitForTimeout(300);
const addNewPage = page.locator(
'[cmdk-item] >> text=Create New Page as: test123456'
);
const addNewPage = page.locator('[cmdk-item] >> text=Create New Page as:');
await addNewPage.click();
await page.waitForTimeout(300);
@@ -218,36 +216,34 @@ test('assert the recent browse pages are on the recent list', async ({
// create first page
await clickNewPageButton(page);
await waitForEditorLoad(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('sgtokidoki', {
delay: 50,
});
await title.pressSequentially('sgtokidoki');
expect(await title.innerText()).toBe('sgtokidoki');
}
await page.waitForTimeout(200);
// create second page
await openQuickSearchByShortcut(page);
const addNewPage = page.locator('[cmdk-item] >> text=New Page');
await addNewPage.click();
await waitForEditorLoad(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('theliquidhorse', {
delay: 50,
});
await title.pressSequentially('theliquidhorse');
expect(await title.innerText()).toBe('theliquidhorse');
}
await page.waitForTimeout(200);
// create thrid page
await openQuickSearchByShortcut(page);
await addNewPage.click();
await waitForEditorLoad(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('battlekot', {
delay: 50,
});
await title.pressSequentially('battlekot');
expect(await title.innerText()).toBe('battlekot');
}
await page.waitForTimeout(200);
await openQuickSearchByShortcut(page);
{
@@ -268,12 +264,11 @@ test('assert the recent browse pages are on the recent list', async ({
const addNewPage = page.locator('[cmdk-item] >> text=New Page');
await addNewPage.click();
}
await page.waitForTimeout(200);
await waitForEditorLoad(page);
{
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('affine is the best', {
delay: 50,
});
await title.pressSequentially('affine is the best');
expect(await title.innerText()).toBe('affine is the best');
}
await page.waitForTimeout(1000);
await openQuickSearchByShortcut(page);
@@ -332,3 +327,15 @@ test('can use cmdk to delete page and restore it', async ({ page }) => {
await keyboardDownAndSelect(page, 'Restore from Trash');
await expect(restoreButton).not.toBeVisible();
});
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"');
});