From b7a03fa5905564800e66711de38c52e5e543dad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 12 Mar 2026 22:10:14 +0800 Subject: [PATCH] feat: add rich text editor E2E tests --- e2e/src/tests/admin/rich-text-editor.spec.ts | 96 ++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 e2e/src/tests/admin/rich-text-editor.spec.ts diff --git a/e2e/src/tests/admin/rich-text-editor.spec.ts b/e2e/src/tests/admin/rich-text-editor.spec.ts new file mode 100644 index 0000000..6851274 --- /dev/null +++ b/e2e/src/tests/admin/rich-text-editor.spec.ts @@ -0,0 +1,96 @@ +import { test, expect } from '../../fixtures/base.fixture'; +import { AdminLoginPage } from '../../pages/AdminPage'; +import { adminTestData } from '../../data/admin-test-data'; + +test.describe('富文本编辑器E2E测试', () => { + test.beforeEach(async ({ page }) => { + const loginPage = new AdminLoginPage(page); + await loginPage.goto(); + await loginPage.login(adminTestData.users.admin.email, adminTestData.users.admin.password); + + await expect(async () => { + await page.waitForURL(/\/admin/, { timeout: 10000 }); + }).toPass({ timeout: 15000 }); + }); + + test('应该能够输入文本内容', async ({ page }) => { + await page.goto('/admin/content/new'); + await page.locator('select[name="type"]').selectOption('news'); + await page.locator('input[name="title"]').fill('富文本测试'); + await page.locator('input[name="slug"]').fill('rich-text-test'); + + const editor = page.locator('.ProseMirror'); + await editor.waitFor({ state: 'visible', timeout: 10000 }); + await editor.click(); + await editor.fill('这是富文本编辑器内容'); + + await page.getByRole('button', { name: /保存/i }).click(); + + await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); + }); + + test('应该能够使用格式化工具', async ({ page }) => { + await page.goto('/admin/content/new'); + await page.locator('select[name="type"]').selectOption('news'); + await page.locator('input[name="title"]').fill('格式化测试'); + await page.locator('input[name="slug"]').fill('formatting-test'); + + const editor = page.locator('.ProseMirror'); + await editor.waitFor({ state: 'visible', timeout: 10000 }); + await editor.click(); + await editor.fill('普通文本'); + + await page.keyboard.selectText('普通文本'); + await page.getByRole('button', { name: '粗体' }).click(); + + await page.getByRole('button', { name: /保存/i }).click(); + + await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); + }); + + test('应该能够添加链接', async ({ page }) => { + await page.goto('/admin/content/new'); + await page.locator('select[name="type"]').selectOption('news'); + await page.locator('input[name="title"]').fill('链接测试'); + await page.locator('input[name="slug"]').fill('link-test'); + + const editor = page.locator('.ProseMirror'); + await editor.waitFor({ state: 'visible', timeout: 10000 }); + await editor.click(); + await editor.fill('测试链接'); + + await page.keyboard.selectText('测试链接'); + await page.getByRole('button', { name: '链接' }).click(); + + const linkInput = page.locator('input[type="url"]'); + await expect(linkInput).toBeVisible(); + await linkInput.fill('https://example.com'); + + await page.getByRole('button', { name: '确认' }).click(); + + await page.getByRole('button', { name: /保存/i }).click(); + + await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); + }); + + test('应该能够添加列表', async ({ page }) => { + await page.goto('/admin/content/new'); + await page.locator('select[name="type"]').selectOption('news'); + await page.locator('input[name="title"]').fill('列表测试'); + await page.locator('input[name="slug"]').fill('list-test'); + + const editor = page.locator('.ProseMirror'); + await editor.waitFor({ state: 'visible', timeout: 10000 }); + await editor.click(); + + await editor.fill('列表项1'); + await page.keyboard.press('Enter'); + await editor.type('列表项2'); + await page.keyboard.press('Enter'); + await editor.type('列表项3'); + + await page.getByRole('button', { name: /保存/i }).click(); + + await expect(page.locator('text=保存成功')).toBeVisible({ timeout: 5000 }); + }); +});