feat: add rich text editor E2E tests
This commit is contained in:
@@ -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 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user