AFFiNE/tests/affine-local/e2e/local-first-favorites-items.spec.ts

152 lines
4.7 KiB
TypeScript
Raw Normal View History

import { test } from '@affine-test/kit/playwright';
import { clickPageModeButton } from '@affine-test/kit/utils/editor';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
2023-09-02 08:57:04 +03:00
clickNewPageButton,
clickPageMoreActions,
createLinkedPage,
getBlockSuiteEditorTitle,
getPageByTitle,
waitForEditorLoad,
2024-02-06 06:20:54 +03:00
waitForEmptyEditor,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
2023-07-13 15:41:46 +03:00
test('Show favorite items in sidebar', async ({ page, workspace }) => {
await openHomePage(page);
await waitForEditorLoad(page);
2023-09-02 08:57:04 +03:00
await clickNewPageButton(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 = getPageByTitle(page, '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(
'favourite-page-' + newPageId
);
expect(await favoriteListItemInSidebar.textContent()).toBe(
'this is a new page to favorite'
);
2023-07-13 15:41:46 +03:00
const currentWorkspace = await workspace.current();
2023-12-15 10:20:50 +03:00
expect(currentWorkspace.meta.flavour).toContain('local');
});
2023-07-13 15:41:46 +03:00
test('Show favorite reference in sidebar', async ({ page, workspace }) => {
await openHomePage(page);
await waitForEditorLoad(page);
2023-09-02 08:57:04 +03:00
await clickNewPageButton(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 = 'favourite-page-' + 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="reference-page"] >> text=Another page')
).toBeVisible();
2023-07-13 15:41:46 +03:00
const currentWorkspace = await workspace.current();
2023-12-15 10:20:50 +03:00
expect(currentWorkspace.meta.flavour).toContain('local');
});
test("Deleted page's reference will not be shown in sidebar", async ({
page,
2023-07-13 15:41:46 +03:00
workspace,
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
2023-09-02 08:57:04 +03:00
await clickNewPageButton(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();
2024-02-06 06:20:54 +03:00
await expect(
page.locator('.doc-title-container:has-text("Another page")')
).toBeVisible();
// 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 = 'favourite-page-' + 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');
2023-07-13 15:41:46 +03:00
const currentWorkspace = await workspace.current();
2023-12-15 10:20:50 +03:00
expect(currentWorkspace.meta.flavour).toContain('local');
});
test('Add new favorite page via sidebar', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await page.getByTestId('slider-bar-add-favorite-button').first().click();
await clickPageModeButton(page);
2024-02-06 06:20:54 +03:00
await waitForEmptyEditor(page);
// enter random page title
await getBlockSuiteEditorTitle(page).fill('this is a new fav page');
// check if the page title is shown in the favorite list
const favItem = page
.getByTestId('favourites')
.locator('[data-draggable] >> text=this is a new fav page');
await expect(favItem).toBeVisible();
});