- 添加 target/ 到 .gitignore - 从 git 暂存区移除已追踪的 target 目录 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
225 lines
7.2 KiB
TypeScript
225 lines
7.2 KiB
TypeScript
/**
|
|
* 超管端 E2E 测试 - 套餐管理
|
|
*/
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
import { loginAsAdmin, waitForTable, waitForSuccess, waitForModal } from './helpers';
|
|
import { TEST_DATA } from './fixtures';
|
|
|
|
test.describe('套餐管理', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await loginAsAdmin(page);
|
|
// 导航到套餐列表页面
|
|
await page.goto('/admin/packages');
|
|
});
|
|
|
|
test.describe('列表页面', () => {
|
|
test('访问套餐列表页面', async ({ page }) => {
|
|
// 验证页面 URL
|
|
await expect(page).toHaveURL(/\/admin\/packages/);
|
|
});
|
|
|
|
test('验证列表加载', async ({ page }) => {
|
|
// 等待表格加载
|
|
await waitForTable(page);
|
|
|
|
// 验证表格存在
|
|
const table = page.locator('table, .ant-table');
|
|
await expect(table).toBeVisible();
|
|
|
|
// 验证新建按钮存在
|
|
const createButton = page.getByText(/新建套餐 | 创建套餐/);
|
|
await expect(createButton).toBeVisible();
|
|
});
|
|
|
|
test('验证套餐列表数据', async ({ page }) => {
|
|
await waitForTable(page);
|
|
|
|
// 验证表格列头
|
|
const headers = page.locator('table .ant-table-thead th');
|
|
await expect(headers.first()).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test.describe('创建套餐', () => {
|
|
test('点击创建按钮', async ({ page }) => {
|
|
// 点击新建套餐按钮
|
|
const createButton = page.getByText(/新建套餐 | 创建套餐/);
|
|
await createButton.click();
|
|
|
|
// 验证跳转到创建页面
|
|
await page.waitForURL(/\/admin\/packages\/create|\/admin\/packages\/new/);
|
|
});
|
|
|
|
test('填写套餐信息', async ({ page }) => {
|
|
// 导航到创建页面
|
|
await page.goto('/admin/packages/create');
|
|
await page.waitForTimeout(500);
|
|
|
|
// 填写套餐名称
|
|
const nameInput = page.locator('input[placeholder*="套餐名称"]');
|
|
if (await nameInput.isVisible()) {
|
|
await nameInput.fill(TEST_DATA.package.name);
|
|
}
|
|
|
|
// 选择套餐类型
|
|
const typeSelect = page.locator('[placeholder*="套餐类型"]');
|
|
if (await typeSelect.isVisible()) {
|
|
await typeSelect.click();
|
|
await page.getByText('标准版').click();
|
|
}
|
|
|
|
// 填写价格
|
|
const priceInput = page.locator('input[placeholder*="价格"]');
|
|
if (await priceInput.isVisible()) {
|
|
await priceInput.fill(String(TEST_DATA.package.price));
|
|
}
|
|
});
|
|
|
|
test('设置配额', async ({ page }) => {
|
|
// 导航到创建页面
|
|
await page.goto('/admin/packages/create');
|
|
await page.waitForTimeout(500);
|
|
|
|
// 填写套餐名称
|
|
const nameInput = page.locator('input[placeholder*="套餐名称"]');
|
|
if (await nameInput.isVisible()) {
|
|
await nameInput.fill(TEST_DATA.package.name);
|
|
}
|
|
|
|
// 设置教师配额
|
|
const teacherQuotaInput = page.locator('input[placeholder*="教师"]');
|
|
if (await teacherQuotaInput.isVisible()) {
|
|
await teacherQuotaInput.fill(String(TEST_DATA.package.teacherQuota));
|
|
}
|
|
|
|
// 设置学生配额
|
|
const studentQuotaInput = page.locator('input[placeholder*="学生"]');
|
|
if (await studentQuotaInput.isVisible()) {
|
|
await studentQuotaInput.fill(String(TEST_DATA.package.studentQuota));
|
|
}
|
|
});
|
|
|
|
test('保存套餐', async ({ page }) => {
|
|
// 导航到创建页面
|
|
await page.goto('/admin/packages/create');
|
|
await page.waitForTimeout(500);
|
|
|
|
// 填写套餐名称
|
|
const nameInput = page.locator('input[placeholder*="套餐名称"]');
|
|
if (await nameInput.isVisible()) {
|
|
await nameInput.fill(TEST_DATA.package.name);
|
|
}
|
|
|
|
// 选择套餐类型
|
|
const typeSelect = page.locator('[placeholder*="套餐类型"]');
|
|
if (await typeSelect.isVisible()) {
|
|
await typeSelect.click();
|
|
await page.waitForTimeout(200);
|
|
await page.getByText('标准版').click();
|
|
}
|
|
|
|
// 填写价格
|
|
const priceInput = page.locator('input[placeholder*="价格"]');
|
|
if (await priceInput.isVisible()) {
|
|
await priceInput.fill(String(TEST_DATA.package.price));
|
|
}
|
|
|
|
// 设置教师配额
|
|
const teacherQuotaInput = page.locator('input[placeholder*="教师"]');
|
|
if (await teacherQuotaInput.isVisible()) {
|
|
await teacherQuotaInput.fill(String(TEST_DATA.package.teacherQuota));
|
|
}
|
|
|
|
// 设置学生配额
|
|
const studentQuotaInput = page.locator('input[placeholder*="学生"]');
|
|
if (await studentQuotaInput.isVisible()) {
|
|
await studentQuotaInput.fill(String(TEST_DATA.package.studentQuota));
|
|
}
|
|
|
|
// 点击保存按钮
|
|
const saveButton = page.getByText(/保存 | 提交/);
|
|
if (await saveButton.isVisible()) {
|
|
await saveButton.click();
|
|
|
|
// 等待保存成功提示或页面跳转
|
|
await page.waitForTimeout(2000);
|
|
}
|
|
});
|
|
});
|
|
|
|
test.describe('编辑套餐', () => {
|
|
test('点击编辑按钮', async ({ page }) => {
|
|
await waitForTable(page);
|
|
|
|
// 查找第一个套餐的编辑按钮
|
|
const editButton = page.locator('button:has-text("编辑")').first();
|
|
if (await editButton.isVisible()) {
|
|
await editButton.click();
|
|
|
|
// 验证跳转到编辑页面
|
|
await page.waitForURL(/\/admin\/packages\/\d+\/edit|\/admin\/packages\/\d+/);
|
|
}
|
|
});
|
|
|
|
test('修改套餐信息', async ({ page }) => {
|
|
await waitForTable(page);
|
|
|
|
// 查找第一个套餐的编辑按钮
|
|
const editButton = page.locator('button:has-text("编辑")').first();
|
|
if (await editButton.isVisible()) {
|
|
await editButton.click();
|
|
await page.waitForTimeout(1000);
|
|
|
|
// 修改套餐名称
|
|
const nameInput = page.locator('input[placeholder*="套餐名称"]');
|
|
if (await nameInput.isVisible()) {
|
|
const originalName = await nameInput.inputValue();
|
|
await nameInput.fill(`${originalName}_已修改`);
|
|
}
|
|
|
|
// 点击保存按钮
|
|
const saveButton = page.getByText(/保存/);
|
|
if (await saveButton.isVisible()) {
|
|
await saveButton.click();
|
|
|
|
// 等待保存成功提示
|
|
await page.waitForTimeout(1000);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
test.describe('删除套餐', () => {
|
|
test('点击删除按钮', async ({ page }) => {
|
|
await waitForTable(page);
|
|
|
|
// 查找第一个套餐的删除按钮
|
|
const deleteButton = page.locator('button:has-text("删除")').first();
|
|
if (await deleteButton.isVisible()) {
|
|
await expect(deleteButton).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test('确认删除弹窗', async ({ page }) => {
|
|
await waitForTable(page);
|
|
|
|
// 查找第一个套餐的删除按钮
|
|
const deleteButton = page.locator('button:has-text("删除")').first();
|
|
if (await deleteButton.isVisible()) {
|
|
await deleteButton.click();
|
|
|
|
// 等待确认弹窗
|
|
const confirmDialog = page.locator('.ant-modal-confirm');
|
|
await expect(confirmDialog).toBeVisible({ timeout: 5000 });
|
|
|
|
// 点击取消,不实际删除
|
|
const cancelButton = page.locator('.ant-modal-confirm button:has-text("取消")');
|
|
if (await cancelButton.isVisible()) {
|
|
await cancelButton.click();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|