AFFiNE/tests/affine-local/e2e/local-first-favorites-items.spec.ts
Peng Xiao 068c697be9
fix: app sidebar ui issues (#3783)
Co-authored-by: Alex Yang <himself65@outlook.com>
2023-08-17 18:36:17 +00:00

130 lines
3.9 KiB
TypeScript

import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickPageMoreActions,
createLinkedPage,
getBlockSuiteEditorTitle,
newPage,
waitEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
test('Show favorite items in sidebar', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
await getBlockSuiteEditorTitle(page).click();
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',
});
await expect(cell).toBeVisible();
await cell.click();
await clickPageMoreActions(page);
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
await favoriteBtn.click();
const favoriteListItemInSidebar = page.getByTestId(
'favorite-list-item-' + newPageId
);
expect(await favoriteListItemInSidebar.textContent()).toBe(
'this is a new page to favorite'
);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test('Show favorite reference in sidebar', async ({ page, workspace }) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
// goes to main content
await page.keyboard.press('Enter', { delay: 50 });
await createLinkedPage(page, 'Another page');
const newPageId = page.url().split('/').reverse()[0];
await clickPageMoreActions(page);
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
await favoriteBtn.click();
const favItemTestId = 'favorite-list-item-' + newPageId;
const favoriteListItemInSidebar = page.getByTestId(favItemTestId);
expect(await favoriteListItemInSidebar.textContent()).toBe(
'this is a new page to favorite'
);
const collapseButton = favoriteListItemInSidebar.locator(
'[data-testid="fav-collapsed-button"]'
);
await expect(collapseButton).toBeVisible();
await collapseButton.click();
await expect(
page.locator('[data-type="favorite-list-item"] >> text=Another page')
).toBeVisible();
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});
test("Deleted page's reference will not be shown in sidebar", async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
await newPage(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
const newPageId = page.url().split('/').reverse()[0];
// goes to main content
await page.keyboard.press('Enter', { delay: 50 });
await createLinkedPage(page, 'Another page');
await clickPageMoreActions(page);
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
await favoriteBtn.click();
// goto "Another page"
await page.locator('.affine-reference-title').click();
// delete the page
await clickPageMoreActions(page);
const deleteBtn = page.getByTestId('editor-option-menu-delete');
await deleteBtn.click();
// confirm delete
await page.locator('button >> text=Delete').click();
const favItemTestId = 'favorite-list-item-' + newPageId;
const favoriteListItemInSidebar = page.getByTestId(favItemTestId);
expect(await favoriteListItemInSidebar.textContent()).toBe(
'this is a new page to favorite'
);
const collapseButton = favoriteListItemInSidebar.locator(
'[data-testid="fav-collapsed-button"]'
);
expect(collapseButton).toHaveAttribute('data-disabled', 'true');
const currentWorkspace = await workspace.current();
expect(currentWorkspace.flavour).toContain('local');
});