feat: new collections (#4530)

Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
3720
2023-10-27 17:06:59 +08:00
committed by GitHub
parent 9fc0152cb1
commit ef8024c657
133 changed files with 8382 additions and 3743 deletions

View File

@@ -25,11 +25,9 @@ import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
function getAllPage(page: Page) {
const newPageButton = page
.locator('table')
.getByRole('button', { name: 'New Page' });
const newPageButton = page.getByTestId('new-page-button');
const newPageDropdown = newPageButton.locator('svg');
const edgelessBlockCard = page.getByTestId('new-edgeless-button-in-all-page');
const edgelessBlockCard = page.getByTestId('switch-edgeless-mode-button');
async function clickNewPageButton() {
return newPageButton.click();
@@ -91,7 +89,7 @@ test('allow creation of filters by created time', async ({ page }) => {
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const pages = await page.locator('[data-testid="title"]').all();
const pages = await page.locator('[data-testid="page-list-item"]').all();
const pageCount = pages.length;
expect(pageCount).not.toBe(0);
await createFirstFilter(page, 'Created');
@@ -123,7 +121,7 @@ test('creation of filters by created time, then click date picker to modify the
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const pages = await page.locator('[data-testid="title"]').all();
const pages = await page.locator('[data-testid="page-list-item"]').all();
const pageCount = pages.length;
expect(pageCount).not.toBe(0);
await createFirstFilter(page, 'Created');
@@ -176,18 +174,19 @@ test('allow creation of filters by tags', async ({ page }) => {
await waitForEditorLoad(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const pages = await page.locator('[data-testid="title"]').all();
const pages = await page.locator('[data-testid="page-list-item"]').all();
const pageCount = pages.length;
expect(pageCount).not.toBe(0);
await createFirstFilter(page, 'Tags');
await checkFilterName(page, 'is not empty');
const pagesWithTags = await page.locator('[data-testid="title"]').all();
const pagesWithTags = await page
.locator('[data-testid="page-list-item"]')
.all();
const pagesWithTagsCount = pagesWithTags.length;
expect(pagesWithTagsCount).not.toBe(0);
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, pagesWithTagsCount + 2);
await changeFilter(page, 'contains all');

View File

@@ -1,6 +1,6 @@
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import { dragTo, waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
test('drag a page from "All pages" list onto the "Trash" folder in the sidebar to move it to trash list', async ({
@@ -11,19 +11,17 @@ test('drag a page from "All pages" list onto the "Trash" folder in the sidebar t
{
await openHomePage(page);
await waitForEditorLoad(page);
await page.getByText('All Pages').click();
await page.getByTestId('app-sidebar').getByText('All Pages').click();
await page.waitForTimeout(500);
}
const title = 'AFFiNE - not just a note-taking app';
// Drag-and-drop
// Ref: https://playwright.dev/docs/input#dragging-manually
await page.getByText(title).hover();
await page.mouse.down();
await page.waitForTimeout(1000);
await page.getByText('Trash').hover();
await page.mouse.up();
await dragTo(
page,
page.locator(`[role="button"]:has-text("${title}")`),
page.getByTestId('app-sidebar').getByText('Trash')
);
await expect(
page.getByText('Successfully deleted'),

View File

@@ -1,8 +1,4 @@
import { test } from '@affine-test/kit/playwright';
import {
checkDatePicker,
selectDateFromDatePicker,
} from '@affine-test/kit/utils/filter';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
@@ -29,16 +25,17 @@ const createAndPinCollection = async (
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.getByTestId('all-pages').click();
const cell = page.getByRole('cell', {
name: 'test page',
});
const cell = page.getByTestId('page-list-item-title').getByText('test page');
await expect(cell).toBeVisible();
await page.getByTestId('create-first-filter').click({
delay: 200,
});
await page.getByTestId(`filler-tag-Created`).click({
delay: 200,
});
await page
.getByTestId('variable-select')
.getByTestId(`filler-tag-Created`)
.click({
delay: 200,
});
await page.getByTestId('save-as-collection').click({
delay: 200,
});
@@ -47,8 +44,6 @@ const createAndPinCollection = async (
await title.fill(options?.collectionName ?? 'test collection');
await page.getByTestId('save-collection').click();
await page.waitForTimeout(100);
await page.getByTestId('collection-bar-option-pin').click();
await page.waitForTimeout(100);
};
test('Show collections items in sidebar', async ({ page }) => {
@@ -93,32 +88,6 @@ test('Show collections items in sidebar', async ({ page }) => {
await page.getByTestId('workspace-card').nth(0).click();
});
test('pin and unpin collection', async ({ page }) => {
const name = 'asd';
await createAndPinCollection(page, { collectionName: name });
const collections = page.getByTestId('collections');
const items = collections.getByTestId('collection-item');
await page.waitForTimeout(50);
expect(await items.count()).toBe(1);
const first = items.first();
await first.hover();
await first.getByTestId('collection-options').click();
const deleteCollection = page
.getByTestId('collection-option')
.getByText('Unpin');
await deleteCollection.click();
await page.waitForTimeout(50);
expect(await items.count()).toBe(0);
await page.getByTestId('collection-select').click();
const option = page.locator('[data-testid=collection-select-option]', {
hasText: name,
});
await option.hover();
await option.getByTestId('collection-select-option-pin').click();
await page.waitForTimeout(100);
expect(await items.count()).toBe(1);
});
test('edit collection', async ({ page }) => {
await createAndPinCollection(page);
const collections = page.getByTestId('collections');
@@ -129,7 +98,7 @@ test('edit collection', async ({ page }) => {
await first.getByTestId('collection-options').click();
const editCollection = page
.getByTestId('collection-option')
.getByText('Edit Filter');
.getByText('Rename');
await editCollection.click();
const title = page.getByTestId('input-collection-title');
await title.fill('123');
@@ -148,14 +117,10 @@ test('edit collection and change filter date', async ({ page }) => {
await first.getByTestId('collection-options').click();
const editCollection = page
.getByTestId('collection-option')
.getByText('Edit Filter');
.getByText('Rename');
await editCollection.click();
const title = page.getByTestId('input-collection-title');
await title.fill('123');
const today = new Date();
await page.locator('[data-testid="filter-arg"]').locator('input').click();
await selectDateFromDatePicker(page, today);
await checkDatePicker(page, today);
await page.getByTestId('save-collection').click();
await page.waitForTimeout(100);
expect(await first.textContent()).toBe('123');
@@ -173,15 +138,15 @@ test('create temporary filter by click tag', async ({ page }) => {
await page.keyboard.press('Enter');
await page.keyboard.press('Escape');
await page.locator('.tag', { hasText: 'TODO Tag' }).click();
const cell = page.getByRole('cell', {
name: 'test page',
});
const cell = page.getByTestId('page-list-item-title').getByText('test page');
await expect(cell).toBeVisible();
expect(await page.getByTestId('title').count()).toBe(1);
expect(await page.getByTestId('page-list-item').count()).toBe(1);
await page.getByTestId('filter-arg').click();
await page.getByTestId('multi-select-TODO Tag').click();
expect(await page.getByTestId('title').count()).toBeGreaterThanOrEqual(2);
expect(
await page.getByTestId('page-list-item').count()
).toBeGreaterThanOrEqual(2);
});
test('add collection from sidebar', async ({ page }) => {
@@ -191,9 +156,7 @@ test('add collection from sidebar', async ({ page }) => {
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.getByTestId('all-pages').click();
const cell = page.getByRole('cell', {
name: 'test page',
});
const cell = page.getByTestId('page-list-item-title').getByText('test page');
await expect(cell).toBeVisible();
const nullCollection = page.getByTestId(
'slider-bar-collection-null-description'

View File

@@ -3,6 +3,8 @@ import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
getPageItem,
getPageOperationButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -22,22 +24,14 @@ test('page delete -> refresh page -> it should be disappear', async ({
name: 'this is a new page delete',
});
expect(cell).not.toBeUndefined();
await page
.getByTestId('more-actions-' + newPageId)
.getByRole('button')
.first()
.click();
await getPageOperationButton(page, newPageId).click();
const deleteBtn = page.getByTestId('move-to-trash');
await deleteBtn.click();
const confirmTip = page.getByText('Delete page?');
expect(confirmTip).not.toBeUndefined();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByTestId('trash-page').click();
await page
.getByTestId('more-actions-' + newPageId)
.getByRole('button')
.nth(1)
.click();
await getPageItem(page, newPageId).getByTestId('delete-page-button').click();
await page.getByText('Delete permanently?').dblclick();
await page.getByRole('button', { name: 'Delete' }).click();
await page.reload();
@@ -65,21 +59,15 @@ test('page delete -> create new page -> refresh page -> new page should be appea
name: 'this is a new page delete',
});
expect(cellDelete).not.toBeUndefined();
await page
.getByTestId('more-actions-' + newPageDeleteId)
.getByRole('button')
.first()
.click();
await getPageOperationButton(page, newPageDeleteId).click();
const deleteBtn = page.getByTestId('move-to-trash');
await deleteBtn.click();
const confirmTip = page.getByText('Delete page?');
expect(confirmTip).not.toBeUndefined();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByTestId('trash-page').click();
await page
.getByTestId('more-actions-' + newPageDeleteId)
.getByRole('button')
.nth(1)
await getPageItem(page, newPageDeleteId)
.getByTestId('delete-page-button')
.click();
await page.getByText('Delete permanently?').dblclick();
await page.getByRole('button', { name: 'Delete' }).click();
@@ -100,9 +88,9 @@ test('page delete -> create new page -> refresh page -> new page should be appea
const newPageId2 = page.url().split('/').reverse()[0];
await page.getByTestId('all-pages').click();
await page.reload();
await page.getByTestId(`page-list-item-${newPageId1}`).click();
await getPageItem(page, newPageId1).click();
await page.getByTestId('all-pages').click();
await page.getByTestId(`page-list-item-${newPageId2}`).click();
await getPageItem(page, newPageId2).click();
await page.getByTestId('all-pages').click();
const currentWorkspace = await workspace.current();
@@ -134,22 +122,14 @@ test('delete multiple pages -> create multiple pages -> refresh', async ({
name: 'this is a new page1',
});
expect(cellDelete1).not.toBeUndefined();
await page
.getByTestId('more-actions-' + newPageId1)
.getByRole('button')
.first()
.click();
await getPageOperationButton(page, newPageId1).click();
const deleteBtn1 = page.getByTestId('move-to-trash');
await deleteBtn1.click();
const confirmTip1 = page.getByText('Delete page?');
expect(confirmTip1).not.toBeUndefined();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByTestId('trash-page').click();
await page
.getByTestId('more-actions-' + newPageId1)
.getByRole('button')
.nth(1)
.click();
await getPageItem(page, newPageId1).getByTestId('delete-page-button').click();
await page.getByText('Delete permanently?').dblclick();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByTestId('all-pages').click();
@@ -159,22 +139,14 @@ test('delete multiple pages -> create multiple pages -> refresh', async ({
name: 'this is a new page2',
});
expect(cellDelete2).not.toBeUndefined();
await page
.getByTestId('more-actions-' + newPageId2)
.getByRole('button')
.first()
.click();
await getPageOperationButton(page, newPageId2).click();
const deleteBtn2 = page.getByTestId('move-to-trash');
await deleteBtn2.click();
const confirmTip2 = page.getByText('Delete page?');
expect(confirmTip2).not.toBeUndefined();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByTestId('trash-page').click();
await page
.getByTestId('more-actions-' + newPageId2)
.getByRole('button')
.nth(1)
.click();
await getPageItem(page, newPageId2).getByTestId('delete-page-button').click();
await page.getByText('Delete permanently?').dblclick();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByTestId('all-pages').click();

View File

@@ -4,6 +4,7 @@ import {
clickNewPageButton,
clickPageMoreActions,
getBlockSuiteEditorTitle,
getPageByTitle,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { waitForLogMessage } from '@affine-test/kit/utils/utils';
@@ -19,9 +20,9 @@ test('New a page and open it ,then favorite it', async ({
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
await page.getByTestId('all-pages').click();
const cell = page.getByRole('cell', {
name: 'this is a new page to favorite',
});
const cell = page
.getByTestId('page-list-item')
.getByText('this is a new page to favorite');
expect(cell).not.toBeUndefined();
await cell.click();
@@ -85,9 +86,7 @@ test('Cancel favorite', async ({ page, workspace }) => {
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
await page.getByTestId('all-pages').click();
const cell = page.getByRole('cell', {
name: 'this is a new page to favorite',
});
const cell = getPageByTitle(page, 'this is a new page to favorite');
expect(cell).not.toBeUndefined();
await cell.click();
@@ -105,9 +104,10 @@ test('Cancel favorite', async ({ page, workspace }) => {
await page.getByTestId('all-pages').click();
const box = await page
.getByRole('cell', { name: 'this is a new page to favorite' })
.boundingBox();
const box = await getPageByTitle(
page,
'this is a new page to favorite'
).boundingBox();
//hover table record
await page.mouse.move((box?.x ?? 0) + 10, (box?.y ?? 0) + 10);

View File

@@ -5,6 +5,7 @@ import {
clickPageMoreActions,
createLinkedPage,
getBlockSuiteEditorTitle,
getPageByTitle,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -17,9 +18,7 @@ test('Show favorite items in sidebar', async ({ page, workspace }) => {
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
const newPageId = page.url().split('/').reverse()[0];
await page.getByTestId('all-pages').click();
const cell = page.getByRole('cell', {
name: 'this is a new page to favorite',
});
const cell = getPageByTitle(page, 'this is a new page to favorite');
await expect(cell).toBeVisible();
await cell.click();
await clickPageMoreActions(page);

View File

@@ -3,6 +3,7 @@ import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
getPageOperationButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -18,11 +19,7 @@ test('click btn bew page and open in tab', async ({ page, workspace }) => {
await page.getByTestId('all-pages').click();
await page
.getByTestId('more-actions-' + newPageId)
.getByRole('button')
.first()
.click();
await getPageOperationButton(page, newPageId).click();
const [newTabPage] = await Promise.all([
page.waitForEvent('popup'),
page.getByRole('menuitem', { name: 'Open in new tab' }).click(),

View File

@@ -3,6 +3,7 @@ import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
getPageOperationButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -23,11 +24,7 @@ test('New a page , then delete it in all pages, restore it', async ({
});
expect(cell).not.toBeUndefined();
await page
.getByTestId('more-actions-' + newPageId)
.getByRole('button')
.first()
.click();
await getPageOperationButton(page, newPageId).click();
const deleteBtn = page.getByTestId('move-to-trash');
await deleteBtn.click();
const confirmTip = page.getByText('Delete page?');
@@ -39,11 +36,7 @@ test('New a page , then delete it in all pages, restore it', async ({
await page.waitForTimeout(50);
const trashPage = page.url();
// restore it
await page
.getByTestId('more-actions-' + newPageId)
.getByRole('button')
.first()
.click();
await page.getByTestId('restore-page-button').click();
// stay in trash page
expect(page.url()).toBe(trashPage);

View File

@@ -4,6 +4,7 @@ import {
clickNewPageButton,
clickPageMoreActions,
getBlockSuiteEditorTitle,
getPageOperationButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -18,9 +19,9 @@ test('New a page ,then open it and show delete modal', async ({
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to delete');
await page.getByTestId('all-pages').click();
const cell = page.getByRole('cell', {
name: 'this is a new page to delete',
});
const cell = page
.getByTestId('page-list-item')
.getByText('this is a new page to delete');
expect(cell).not.toBeUndefined();
await cell.click();
@@ -50,11 +51,7 @@ test('New a page ,then go to all pages and show delete modal', async ({
});
expect(cell).not.toBeUndefined();
await page
.getByTestId('more-actions-' + newPageId)
.getByRole('button')
.first()
.click();
await getPageOperationButton(page, newPageId).click();
const deleteBtn = page.getByTestId('move-to-trash');
await deleteBtn.click();
const confirmTip = page.getByText('Delete page?');

View File

@@ -4,6 +4,7 @@ import {
clickNewPageButton,
clickPageMoreActions,
getBlockSuiteEditorTitle,
getPageOperationButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
@@ -24,11 +25,7 @@ test('New a page , then delete it in all pages, finally find it in trash', async
});
expect(cell).not.toBeUndefined();
await page
.getByTestId('more-actions-' + newPageId)
.getByRole('button')
.first()
.click();
await getPageOperationButton(page, newPageId).click();
const deleteBtn = page.getByTestId('move-to-trash');
await deleteBtn.click();
const confirmTip = page.getByText('Delete page?');

View File

@@ -47,15 +47,15 @@ test('create one workspace in the workspace list', async ({
//check page list length
await page.keyboard.press('Escape');
await clickSideBarAllPageButton(page);
await page.waitForTimeout(1000);
await page.waitForTimeout(2000);
const pageList = page.locator('[data-testid=page-list-item]');
const result = await pageList.count();
expect(result).toBe(0);
expect(result).toBe(13);
await page.reload();
await page.waitForTimeout(1000);
await page.waitForTimeout(4000);
const pageList1 = page.locator('[data-testid=page-list-item]');
const result1 = await pageList1.count();
expect(result1).toBe(0);
expect(result1).toBe(13);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');

View File

@@ -22,7 +22,6 @@ const keyboardDownAndSelect = async (page: Page, label: string) => {
) {
await keyboardDownAndSelect(page, label);
} else {
await page.pause();
await page.keyboard.press('Enter');
}
};