mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 10:22:55 +08:00
feat(core): mode in query string (#7904)
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
filterTags,
|
||||
removeSelectedTag,
|
||||
} from '@affine-test/kit/utils/properties';
|
||||
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
||||
import { expect, type Page } from '@playwright/test';
|
||||
|
||||
const searchAndCreateTag = async (page: Page, name: string) => {
|
||||
@@ -64,7 +65,7 @@ test('New a page and open it ,then open info modal in the title bar more action
|
||||
});
|
||||
|
||||
test('New a page, then open info modal from all doc', async ({ page }) => {
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
|
||||
await page.getByTestId('all-pages').click();
|
||||
const cell = getPageByTitle(page, 'this is a new page');
|
||||
@@ -83,7 +84,7 @@ test('New a page, then open info modal from all doc', async ({ page }) => {
|
||||
test('New a page and add to favourites, then open info modal from sidebar', async ({
|
||||
page,
|
||||
}) => {
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
|
||||
await clickPageMoreActions(page);
|
||||
await page.getByTestId('editor-option-menu-favorite').click();
|
||||
|
||||
@@ -8,6 +8,10 @@ import {
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
|
||||
import {
|
||||
getCurrentCollectionIdFromUrl,
|
||||
getCurrentDocIdFromUrl,
|
||||
} from '@affine-test/kit/utils/url';
|
||||
import type { Locator, Page } from '@playwright/test';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
@@ -32,7 +36,7 @@ const createCollection = async (page: Page, name: string) => {
|
||||
await expect(input).toBeVisible();
|
||||
await input.fill(name);
|
||||
await page.getByTestId('save-collection').click();
|
||||
const newCollectionId = page.url().split('/').reverse()[0];
|
||||
const newCollectionId = getCurrentCollectionIdFromUrl(page);
|
||||
const collection = page.getByTestId(`explorer-collection-${newCollectionId}`);
|
||||
await expect(collection).toBeVisible();
|
||||
return collection;
|
||||
@@ -85,7 +89,7 @@ test('drag a page from "All pages" list to favourites, then drag to trash', asyn
|
||||
const title = 'this is a new page to drag';
|
||||
await waitForEditorLoad(page);
|
||||
await createPage(page, title);
|
||||
const pageId = page.url().split('/').reverse()[0];
|
||||
const pageId = getCurrentDocIdFromUrl(page);
|
||||
await clickSideBarAllPageButton(page);
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
@@ -133,7 +137,7 @@ test('drag a page from favourites to collection', async ({ page }) => {
|
||||
const title = 'this is a new page to drag';
|
||||
await createPage(page, title);
|
||||
|
||||
const pageId = page.url().split('/').reverse()[0];
|
||||
const pageId = getCurrentDocIdFromUrl(page);
|
||||
await clickSideBarAllPageButton(page);
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
@@ -152,7 +156,7 @@ test('drag a collection to favourites', async ({ page }) => {
|
||||
await clickSideBarAllPageButton(page);
|
||||
await page.waitForTimeout(500);
|
||||
const collection = await createCollection(page, 'test collection');
|
||||
const collectionId = page.url().split('/').reverse()[0];
|
||||
const collectionId = getCurrentCollectionIdFromUrl(page);
|
||||
await dragToFavourites(page, collection, collectionId, 'collection');
|
||||
});
|
||||
|
||||
@@ -167,7 +171,7 @@ test('items in favourites can be reordered by dragging', async ({ page }) => {
|
||||
|
||||
{
|
||||
const collection = await createCollection(page, 'test collection');
|
||||
const collectionId = page.url().split('/').reverse()[0];
|
||||
const collectionId = getCurrentCollectionIdFromUrl(page);
|
||||
await dragToFavourites(page, collection, collectionId, 'collection');
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
getPageOperationButton,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
test('page delete -> refresh page -> it should be disappear', async ({
|
||||
@@ -18,7 +19,7 @@ test('page delete -> refresh page -> it should be disappear', async ({
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page delete');
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
const cell = page.getByRole('cell', {
|
||||
name: 'this is a new page delete',
|
||||
@@ -54,7 +55,7 @@ test('page delete -> create new page -> refresh page -> new page should be appea
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page delete');
|
||||
const newPageDeleteId = page.url().split('/').reverse()[0];
|
||||
const newPageDeleteId = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
const cellDelete = page.getByRole('cell', {
|
||||
name: 'this is a new page delete',
|
||||
@@ -80,13 +81,13 @@ test('page delete -> create new page -> refresh page -> new page should be appea
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page1');
|
||||
await page.waitForTimeout(1000);
|
||||
const newPageId1 = page.url().split('/').reverse()[0];
|
||||
const newPageId1 = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page2');
|
||||
await page.waitForTimeout(1000);
|
||||
const newPageId2 = page.url().split('/').reverse()[0];
|
||||
const newPageId2 = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
await page.reload();
|
||||
await getPageItem(page, newPageId1).click();
|
||||
@@ -109,13 +110,13 @@ test('delete multiple pages -> create multiple pages -> refresh', async ({
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page1');
|
||||
const newPageId1 = page.url().split('/').reverse()[0];
|
||||
const newPageId1 = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
// create 2nd page
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page2');
|
||||
const newPageId2 = page.url().split('/').reverse()[0];
|
||||
const newPageId2 = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
|
||||
// 1st cell to be deleted
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
waitForEditorLoad,
|
||||
waitForEmptyEditor,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
test('Show favorite items in sidebar', async ({ page, workspace }) => {
|
||||
@@ -18,7 +19,7 @@ test('Show favorite items in sidebar', async ({ page, workspace }) => {
|
||||
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];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
const cell = getPageByTitle(page, 'this is a new page to favorite');
|
||||
await expect(cell).toBeVisible();
|
||||
@@ -50,7 +51,7 @@ test('Show favorite reference in sidebar', async ({ page, workspace }) => {
|
||||
|
||||
await createLinkedPage(page, 'Another page');
|
||||
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
|
||||
await clickPageMoreActions(page);
|
||||
|
||||
@@ -89,7 +90,7 @@ test("Deleted page's reference will not be shown in sidebar", async ({
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite');
|
||||
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
|
||||
// goes to main content
|
||||
await page.keyboard.press('Enter', { delay: 50 });
|
||||
@@ -108,7 +109,7 @@ test("Deleted page's reference will not be shown in sidebar", async ({
|
||||
page.locator('.doc-title-container:has-text("Another page")')
|
||||
).toBeVisible();
|
||||
|
||||
const anotherPageId = page.url().split('/').reverse()[0];
|
||||
const anotherPageId = getCurrentDocIdFromUrl(page);
|
||||
|
||||
const favItemTestId = 'explorer-doc-' + newPageId;
|
||||
|
||||
|
||||
@@ -5,14 +5,15 @@ import {
|
||||
getBlockSuiteEditorTitle,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
test('click btn new page', async ({ page, workspace }) => {
|
||||
await openHomePage(page);
|
||||
await waitForEditorLoad(page);
|
||||
const originPageId = page.url().split('/').reverse()[0];
|
||||
const originPageId = getCurrentDocIdFromUrl(page);
|
||||
await clickNewPageButton(page);
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
expect(newPageId).not.toBe(originPageId);
|
||||
const currentWorkspace = await workspace.current();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
getPageOperationButton,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
test('click btn new page and open in tab', async ({ page, workspace }) => {
|
||||
@@ -15,7 +16,7 @@ test('click btn new page and open in tab', async ({ page, workspace }) => {
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page');
|
||||
const newPageUrl = page.url();
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
|
||||
await page.getByTestId('all-pages').click();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
getPageOperationButton,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
test('New a page , then delete it in all pages, restore it', async ({
|
||||
@@ -17,7 +18,7 @@ test('New a page , then delete it in all pages, restore it', async ({
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page to restore');
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
const cell = page.getByRole('cell', {
|
||||
name: 'this is a new page to restore',
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
getPageOperationButton,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
test('New a page ,then open it and show delete modal', async ({
|
||||
@@ -44,7 +45,7 @@ test('New a page ,then go to all pages and show delete modal', async ({
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page to delete');
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
const cell = page.getByRole('cell', {
|
||||
name: 'this is a new page to delete',
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
getPageOperationButton,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { getCurrentDocIdFromUrl } from '@affine-test/kit/utils/url';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
test('New a page , then delete it in all pages, finally find it in trash', async ({
|
||||
@@ -17,7 +18,7 @@ test('New a page , then delete it in all pages, finally find it in trash', async
|
||||
await clickNewPageButton(page);
|
||||
await getBlockSuiteEditorTitle(page).click();
|
||||
await getBlockSuiteEditorTitle(page).fill('this is a new page to delete');
|
||||
const newPageId = page.url().split('/').reverse()[0];
|
||||
const newPageId = getCurrentDocIdFromUrl(page);
|
||||
await page.getByTestId('all-pages').click();
|
||||
const cell = page.getByRole('cell', {
|
||||
name: 'this is a new page to delete',
|
||||
|
||||
@@ -6,9 +6,10 @@ import { expect } from '@playwright/test';
|
||||
test('goto not found page', async ({ page }) => {
|
||||
await openHomePage(page);
|
||||
await waitForEditorLoad(page);
|
||||
const currentUrl = page.url();
|
||||
const invalidUrl = currentUrl.concat('invalid');
|
||||
await page.goto(invalidUrl);
|
||||
const currentUrl = new URL(page.url());
|
||||
const invalidUrl = (currentUrl.pathname =
|
||||
currentUrl.pathname.concat('invalid'));
|
||||
await page.goto(invalidUrl.toString());
|
||||
await expect(page.getByTestId('not-found')).toBeVisible({
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
19
tests/kit/utils/url.ts
Normal file
19
tests/kit/utils/url.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
export function getCurrentDocIdFromUrl(page: Page) {
|
||||
const pathname = new URL(page.url()).pathname;
|
||||
const match = pathname.match(/\/workspace\/([^/]+)\/([^/]+)\/?/);
|
||||
if (match && match[2]) {
|
||||
return match[2];
|
||||
}
|
||||
throw new Error('Failed to get doc id from url');
|
||||
}
|
||||
|
||||
export function getCurrentCollectionIdFromUrl(page: Page) {
|
||||
const pathname = new URL(page.url()).pathname;
|
||||
const match = pathname.match(/\/workspace\/([^/]+)\/collection\/([^/]+)\/?/);
|
||||
if (match && match[2]) {
|
||||
return match[2];
|
||||
}
|
||||
throw new Error('Failed to get collection id from url');
|
||||
}
|
||||
Reference in New Issue
Block a user