feat: add tags support (#2988)

Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
3720
2023-07-04 15:32:11 +08:00
committed by Alex Yang
parent 65c6479ee4
commit 34ad5cdaef
34 changed files with 706 additions and 78 deletions

View File

@@ -6,6 +6,7 @@ import { openHomePage } from '../libs/load-page';
import {
closeDownloadTip,
getBlockSuiteEditorTitle,
newPage,
waitEditorLoad,
} from '../libs/page-logic';
import { clickSideBarAllPageButton } from '../libs/sidebar';
@@ -25,6 +26,7 @@ function getAllPage(page: Page) {
await newPageDropdown.click();
await edgelessBlockCard.click();
}
return { clickNewPageButton, clickNewEdgelessDropdown };
}
@@ -302,3 +304,62 @@ test('use monthpicker to modify the month of datepicker', async ({ page }) => {
await selectMonthFromMonthPicker(page, nextMonth);
await checkDatePickerMonth(page, nextMonth);
});
const createTag = async (page: Page, name: string) => {
await page.keyboard.type(name);
await page.keyboard.press('ArrowUp');
await page.keyboard.press('Enter');
};
const createPageWithTag = async (
page: Page,
options: {
title: string;
tags: string[];
}
) => {
await page.getByTestId('all-pages').click();
await newPage(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.locator('affine-page-meta-data').click();
await page.locator('.add-tag').click();
for (const name of options.tags) {
await createTag(page, name);
}
await page.keyboard.press('Escape');
};
const changeFilter = async (page: Page, to: string | RegExp) => {
await page.getByTestId('filter-name').click();
await page
.getByTestId('filter-name-select')
.locator('button', { hasText: to })
.click();
};
async function selectTag(page: Page, name: string | RegExp) {
await page.getByTestId('filter-arg').click();
await page
.getByTestId('multi-select')
.getByTestId('select-option')
.getByText(name)
.click();
await page.getByTestId('filter-arg').click();
}
test('allow creation of filters by tags', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await closeDownloadTip(page);
await createPageWithTag(page, { title: 'Page A', tags: ['A'] });
await createPageWithTag(page, { title: 'Page B', tags: ['B'] });
await clickSideBarAllPageButton(page);
await createFirstFilter(page, 'Tags');
await checkFilterName(page, 'is not empty');
await checkPagesCount(page, 2);
await changeFilter(page, /^contains all/);
await checkPagesCount(page, 3);
await selectTag(page, 'A');
await checkPagesCount(page, 1);
await changeFilter(page, /^does not contains all/);
await selectTag(page, 'B');
await checkPagesCount(page, 2);
});

View File

@@ -101,3 +101,26 @@ test('edit collection', async ({ page }) => {
await page.getByTestId('save-collection').click();
expect(await first.textContent()).toBe('123');
});
test('create temporary filter by click tag', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.locator('affine-page-meta-data').click();
await page.locator('.add-tag').click();
await page.keyboard.type('TODO Tag');
await page.keyboard.press('Enter');
await page.keyboard.press('Escape');
await page.locator('.tag', { hasText: 'TODO Tag' }).click();
await closeDownloadTip(page);
const cell = page.getByRole('cell', {
name: 'test page',
});
await expect(cell).toBeVisible();
expect(await page.getByTestId('title').count()).toBe(1);
await page.getByTestId('filter-arg').click();
await page.getByRole('tooltip').getByText('TODO Tag').click();
expect(await page.getByTestId('title').count()).toBe(2);
});