2023-04-25 06:12:48 +03:00
|
|
|
import { test } from '@affine-test/kit/playwright';
|
2024-02-22 12:37:55 +03:00
|
|
|
import { clickPageModeButton } from '@affine-test/kit/utils/editor';
|
2023-07-13 12:05:01 +03:00
|
|
|
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
2023-03-02 20:38:17 +03:00
|
|
|
import {
|
2023-09-02 08:57:04 +03:00
|
|
|
clickNewPageButton,
|
2023-03-02 20:38:17 +03:00
|
|
|
clickPageMoreActions,
|
2023-05-18 08:18:40 +03:00
|
|
|
createLinkedPage,
|
2023-03-02 20:38:17 +03:00
|
|
|
getBlockSuiteEditorTitle,
|
2023-10-27 12:06:59 +03:00
|
|
|
getPageByTitle,
|
2023-09-02 06:31:07 +03:00
|
|
|
waitForEditorLoad,
|
2024-02-06 06:20:54 +03:00
|
|
|
waitForEmptyEditor,
|
2023-07-13 12:05:01 +03:00
|
|
|
} from '@affine-test/kit/utils/page-logic';
|
2024-08-16 13:59:43 +03:00
|
|
|
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
2023-07-13 12:05:01 +03:00
|
|
|
import { expect } from '@playwright/test';
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-07-13 15:41:46 +03:00
|
|
|
test('Show favorite items in sidebar', async ({ page, workspace }) => {
|
2023-04-17 00:02:41 +03:00
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await getBlockSuiteEditorTitle(page).click();
|
|
|
|
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
|
2024-08-16 13:59:43 +03:00
|
|
|
const newPageId = getCurrentDocIdFromUrl(page);
|
2023-05-12 06:13:51 +03:00
|
|
|
await page.getByTestId('all-pages').click();
|
2023-10-27 12:06:59 +03:00
|
|
|
const cell = getPageByTitle(page, 'this is a new page to favorite');
|
2023-04-17 00:02:41 +03:00
|
|
|
await expect(cell).toBeVisible();
|
|
|
|
await cell.click();
|
|
|
|
await clickPageMoreActions(page);
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
|
|
|
|
await favoriteBtn.click();
|
|
|
|
const favoriteListItemInSidebar = page.getByTestId(
|
2024-07-26 07:35:31 +03:00
|
|
|
'explorer-doc-' + newPageId
|
2023-04-17 00:02:41 +03:00
|
|
|
);
|
|
|
|
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-04-17 00:02:41 +03:00
|
|
|
});
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-07-13 15:41:46 +03:00
|
|
|
test('Show favorite reference in sidebar', async ({ page, workspace }) => {
|
2023-04-17 00:02:41 +03:00
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-04-17 00:02:41 +03:00
|
|
|
await getBlockSuiteEditorTitle(page).click();
|
|
|
|
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
|
2023-05-18 08:18:40 +03:00
|
|
|
|
|
|
|
// goes to main content
|
|
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
|
|
|
|
|
|
|
await createLinkedPage(page, 'Another page');
|
|
|
|
|
2024-08-16 13:59:43 +03:00
|
|
|
const newPageId = getCurrentDocIdFromUrl(page);
|
2023-05-18 08:18:40 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
await clickPageMoreActions(page);
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-04-17 00:02:41 +03:00
|
|
|
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
|
|
|
|
await favoriteBtn.click();
|
2023-03-01 19:50:23 +03:00
|
|
|
|
2024-07-26 07:35:31 +03:00
|
|
|
const favItemTestId = 'explorer-doc-' + newPageId;
|
2023-05-18 08:18:40 +03:00
|
|
|
|
|
|
|
const favoriteListItemInSidebar = page.getByTestId(favItemTestId);
|
|
|
|
expect(await favoriteListItemInSidebar.textContent()).toBe(
|
|
|
|
'this is a new page to favorite'
|
|
|
|
);
|
2023-05-12 06:13:51 +03:00
|
|
|
|
2024-07-26 07:35:31 +03:00
|
|
|
const collapseButton = favoriteListItemInSidebar.getByTestId(
|
|
|
|
'explorer-collapsed-button'
|
2023-05-18 08:18:40 +03:00
|
|
|
);
|
2023-04-17 00:02:41 +03:00
|
|
|
|
2023-05-18 08:18:40 +03:00
|
|
|
await expect(collapseButton).toBeVisible();
|
|
|
|
await collapseButton.click();
|
|
|
|
await expect(
|
2024-07-26 07:35:31 +03:00
|
|
|
favoriteListItemInSidebar.locator(
|
|
|
|
'[data-testid^="explorer-doc-"]:has-text("Another page")'
|
|
|
|
)
|
2023-05-18 08:18:40 +03:00
|
|
|
).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');
|
2022-12-30 16:40:15 +03:00
|
|
|
});
|
2023-06-06 05:36:58 +03:00
|
|
|
|
|
|
|
test("Deleted page's reference will not be shown in sidebar", async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await openHomePage(page);
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-09-02 08:57:04 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-06-06 05:36:58 +03:00
|
|
|
await getBlockSuiteEditorTitle(page).click();
|
|
|
|
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
|
|
|
|
|
2024-08-16 13:59:43 +03:00
|
|
|
const newPageId = getCurrentDocIdFromUrl(page);
|
2023-06-06 05:36:58 +03:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2024-08-16 13:59:43 +03:00
|
|
|
const anotherPageId = getCurrentDocIdFromUrl(page);
|
2024-07-02 12:18:01 +03:00
|
|
|
|
2024-07-26 07:35:31 +03:00
|
|
|
const favItemTestId = 'explorer-doc-' + newPageId;
|
2024-07-02 12:18:01 +03:00
|
|
|
|
|
|
|
await expect(page.getByTestId(favItemTestId)).toHaveText(
|
|
|
|
'this is a new page to favorite'
|
|
|
|
);
|
|
|
|
|
|
|
|
await page
|
|
|
|
.getByTestId(favItemTestId)
|
2024-07-26 07:35:31 +03:00
|
|
|
.getByTestId('explorer-collapsed-button')
|
2024-07-02 12:18:01 +03:00
|
|
|
.click();
|
|
|
|
|
2024-07-26 07:35:31 +03:00
|
|
|
const favItemAnotherPageTestId = 'explorer-doc-' + anotherPageId;
|
2024-07-02 12:18:01 +03:00
|
|
|
|
2024-07-26 07:35:31 +03:00
|
|
|
await expect(
|
|
|
|
page.getByTestId(favItemTestId).getByTestId(favItemAnotherPageTestId)
|
|
|
|
).toBeVisible();
|
2024-07-02 12:18:01 +03:00
|
|
|
|
2023-06-06 05:36:58 +03:00
|
|
|
// 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();
|
|
|
|
|
2024-07-26 07:35:31 +03:00
|
|
|
await expect(
|
|
|
|
page.getByTestId(favItemTestId).getByTestId(favItemAnotherPageTestId)
|
|
|
|
).toBeHidden();
|
2023-06-06 05:36:58 +03:00
|
|
|
});
|
2023-09-04 20:14:02 +03:00
|
|
|
|
|
|
|
test('Add new favorite page via sidebar', async ({ page }) => {
|
|
|
|
await openHomePage(page);
|
|
|
|
await waitForEditorLoad(page);
|
2024-02-22 12:37:55 +03:00
|
|
|
|
2024-07-26 07:35:31 +03:00
|
|
|
await page.getByTestId('explorer-bar-add-favorite-button').first().click();
|
2024-02-22 12:37:55 +03:00
|
|
|
await clickPageModeButton(page);
|
2024-02-06 06:20:54 +03:00
|
|
|
await waitForEmptyEditor(page);
|
2023-09-04 20:14:02 +03:00
|
|
|
|
|
|
|
// 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
|
2024-03-29 07:04:26 +03:00
|
|
|
const favItem = page
|
2024-07-26 07:35:31 +03:00
|
|
|
.getByTestId('explorer-favorites')
|
|
|
|
.locator('[draggable] >> text=this is a new fav page');
|
2023-09-04 20:14:02 +03:00
|
|
|
await expect(favItem).toBeVisible();
|
|
|
|
});
|