refactor(editor): add native clipboard extension (#9502)

Closes: [BS-2239](https://linear.app/affine-design/issue/BS-2239/不应该通过window注入affine的api)
This commit is contained in:
fundon
2025-01-06 15:36:43 +00:00
parent f778d1a28a
commit 69e73af2a8
9 changed files with 117 additions and 36 deletions

View File

@@ -0,0 +1,52 @@
import { test } from '@affine-test/kit/electron';
import { importImage } from '@affine-test/kit/utils/image';
import { pasteByKeyboard } from '@affine-test/kit/utils/keyboard';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
} from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';
test('should be able to insert SVG images', async ({ page }) => {
await page.waitForTimeout(500);
await clickNewPageButton(page);
const title = getBlockSuiteEditorTitle(page);
await title.focus();
await page.keyboard.press('Enter');
await importImage(page, 'affine.svg');
const svg = page.locator('affine-image').first();
await expect(svg).toBeVisible();
});
test('should paste it as PNG after copying SVG', async ({ page }) => {
await page.waitForTimeout(500);
await clickNewPageButton(page);
const title = getBlockSuiteEditorTitle(page);
await title.focus();
await page.keyboard.press('Enter');
await importImage(page, 'affine.svg');
const svg = page.locator('affine-image').first();
await expect(svg).toBeVisible();
await svg.hover();
await page.waitForTimeout(500);
const imageToolbar = page.locator('affine-image-toolbar');
await expect(imageToolbar).toBeVisible();
await imageToolbar.getByRole('button', { name: 'More' }).click();
const moveMenu = page.locator('.image-more-popup-menu');
await moveMenu.getByRole('button', { name: /^Copy$/ }).click();
await svg.click();
await page.keyboard.press('Enter');
await pasteByKeyboard(page);
const png = page.locator('affine-image').nth(1);
await expect(png).toBeVisible();
});