test(core): test case for dragging from bs editor to sidebar (#9057)
fix AF-1904
This commit is contained in:
@@ -3,14 +3,15 @@ import { test } from '@affine-test/kit/playwright';
|
|||||||
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
||||||
import {
|
import {
|
||||||
clickNewPageButton,
|
clickNewPageButton,
|
||||||
|
createLinkedPage,
|
||||||
dragTo,
|
dragTo,
|
||||||
getBlockSuiteEditorTitle,
|
|
||||||
waitForEditorLoad,
|
waitForEditorLoad,
|
||||||
} from '@affine-test/kit/utils/page-logic';
|
} from '@affine-test/kit/utils/page-logic';
|
||||||
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
|
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
|
||||||
import {
|
import {
|
||||||
getCurrentCollectionIdFromUrl,
|
getCurrentCollectionIdFromUrl,
|
||||||
getCurrentDocIdFromUrl,
|
getCurrentDocIdFromUrl,
|
||||||
|
getDocIdFromUrl,
|
||||||
} from '@affine-test/kit/utils/url';
|
} from '@affine-test/kit/utils/url';
|
||||||
import type { Locator, Page } from '@playwright/test';
|
import type { Locator, Page } from '@playwright/test';
|
||||||
import { expect } from '@playwright/test';
|
import { expect } from '@playwright/test';
|
||||||
@@ -43,8 +44,7 @@ const createCollection = async (page: Page, name: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const createPage = async (page: Page, title: string) => {
|
const createPage = async (page: Page, title: string) => {
|
||||||
await clickNewPageButton(page);
|
await clickNewPageButton(page, title);
|
||||||
await getBlockSuiteEditorTitle(page).fill(title);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const dragToCollection = async (page: Page, dragItem: Locator) => {
|
const dragToCollection = async (page: Page, dragItem: Locator) => {
|
||||||
@@ -212,3 +212,34 @@ test('items in favourites can be reordered by dragging', async ({ page }) => {
|
|||||||
page.getByTestId('explorer-favorites').locator('[draggable]').last()
|
page.getByTestId('explorer-favorites').locator('[draggable]').last()
|
||||||
).toHaveText('test collection');
|
).toHaveText('test collection');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('drag a page link in editor to favourites', async ({ page }) => {
|
||||||
|
await clickNewPageButton(page);
|
||||||
|
await page.waitForTimeout(500);
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
await createLinkedPage(page, 'hi from another page');
|
||||||
|
|
||||||
|
const pageReference = page.locator('a').filter({
|
||||||
|
has: page.locator(
|
||||||
|
'.affine-reference-title:has-text("hi from another page")'
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
const pageLink = await pageReference.evaluate(
|
||||||
|
el => (el as HTMLAnchorElement).href
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(pageLink).toBeTruthy();
|
||||||
|
|
||||||
|
if (!pageLink) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pageId = getDocIdFromUrl(pageLink);
|
||||||
|
|
||||||
|
await dragToFavourites(
|
||||||
|
page,
|
||||||
|
page.locator('.affine-reference-title:has-text("hi from another page")'),
|
||||||
|
pageId
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { Page } from '@playwright/test';
|
import type { Page } from '@playwright/test';
|
||||||
|
|
||||||
export function getCurrentDocIdFromUrl(page: Page) {
|
export function getDocIdFromUrl(url: string) {
|
||||||
const pathname = new URL(page.url()).pathname;
|
const pathname = new URL(url).pathname;
|
||||||
|
|
||||||
const match = pathname.match(/\/workspace\/([^/]+)\/([^/]+)\/?/);
|
const match = pathname.match(/\/workspace\/([^/]+)\/([^/]+)\/?/);
|
||||||
if (match && match[2]) {
|
if (match && match[2]) {
|
||||||
return match[2];
|
return match[2];
|
||||||
@@ -9,6 +10,10 @@ export function getCurrentDocIdFromUrl(page: Page) {
|
|||||||
throw new Error('Failed to get doc id from url');
|
throw new Error('Failed to get doc id from url');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCurrentDocIdFromUrl(page: Page) {
|
||||||
|
return getDocIdFromUrl(page.url());
|
||||||
|
}
|
||||||
|
|
||||||
export function getCurrentCollectionIdFromUrl(page: Page) {
|
export function getCurrentCollectionIdFromUrl(page: Page) {
|
||||||
const pathname = new URL(page.url()).pathname;
|
const pathname = new URL(page.url()).pathname;
|
||||||
const match = pathname.match(/\/workspace\/([^/]+)\/collection\/([^/]+)\/?/);
|
const match = pathname.match(/\/workspace\/([^/]+)\/collection\/([^/]+)\/?/);
|
||||||
|
|||||||
Reference in New Issue
Block a user