Files
novalon-manage-system/novalon-manage-web/e2e/pages/DictionaryManagementPage.ts
T
张翔 bd21e2d1f7 test: E2E 测试用例更新与新增
- 更新 Page Object 模型适配新字段名
- 新增 UAT 测试套件与 journey 测试用例
- 优化测试辅助工具与数据工厂
- 更新 playwright 认证状态
2026-05-06 14:17:51 +08:00

111 lines
5.0 KiB
TypeScript

import { Page, Locator, expect } from '@playwright/test';
export class DictionaryManagementPage {
readonly page: Page;
readonly typeTable: Locator;
readonly dataTable: Locator;
readonly addTypeButton: Locator;
readonly addDataButton: Locator;
readonly successMessage: Locator;
readonly errorMessage: Locator;
constructor(page: Page) {
this.page = page;
this.typeTable = page.locator('.ant-card').filter({ hasText: '字典类型' }).locator('.ant-table').first();
this.dataTable = page.locator('.ant-card').filter({ hasText: '字典数据' }).locator('.ant-table').first();
this.addTypeButton = page.locator('.ant-card').filter({ hasText: '字典类型' }).getByRole('button', { name: '新增' });
this.addDataButton = page.locator('.ant-card').filter({ hasText: '字典数据' }).getByRole('button', { name: '新增' });
this.successMessage = page.locator('.ant-message-success');
this.errorMessage = page.locator('.ant-message-error');
}
async goto() {
await this.page.goto('/dict');
await this.page.waitForLoadState('networkidle');
await this.typeTable.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
await expect(this.page).toHaveURL(/.*dict/);
}
async createDictType(dictName: string, dictType: string, status: number = 1, remark?: string) {
await this.addTypeButton.click();
await this.page.waitForTimeout(500);
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增字典类型|编辑字典类型/ });
await modal.locator('.ant-form-item').filter({ hasText: '字典名称' }).locator('input').fill(dictName);
await modal.locator('.ant-form-item').filter({ hasText: '字典类型' }).locator('input').fill(dictType);
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
await statusSelect.click();
await this.page.waitForTimeout(300);
const statusText = status === 1 ? '正常' : '停用';
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
if (remark) {
await modal.locator('.ant-form-item').filter({ hasText: '备注' }).locator('textarea').fill(remark);
}
await modal.getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
async editDictType(dictName: string, newDictName: string) {
const row = this.typeTable.locator('tbody tr').filter({ hasText: dictName }).first();
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
await this.page.waitForTimeout(500);
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增字典类型|编辑字典类型/ });
const nameInput = modal.locator('.ant-form-item').filter({ hasText: '字典名称' }).locator('input');
await nameInput.clear();
await nameInput.fill(newDictName);
await modal.getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
async deleteDictType(dictName: string) {
const row = this.typeTable.locator('tbody tr').filter({ hasText: dictName }).first();
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
await this.page.waitForTimeout(300);
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
async selectDictType(dictType: string) {
const link = this.typeTable.locator('a').filter({ hasText: dictType });
await link.click();
await this.page.waitForTimeout(500);
}
async createDictData(dictLabel: string, dictValue: string, sort: number = 0, status: number = 1) {
await this.addDataButton.click();
await this.page.waitForTimeout(500);
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增字典数据|编辑字典数据/ });
await modal.locator('.ant-form-item').filter({ hasText: '字典标签' }).locator('input').fill(dictLabel);
await modal.locator('.ant-form-item').filter({ hasText: '字典值' }).locator('input').fill(dictValue);
if (sort > 0) {
const sortInput = modal.locator('.ant-form-item').filter({ hasText: '排序' }).locator('.ant-input-number input');
await sortInput.clear();
await sortInput.fill(String(sort));
}
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
await statusSelect.click();
await this.page.waitForTimeout(300);
const statusText = status === 1 ? '正常' : '停用';
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
await modal.getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
async typeContainsText(text: string): Promise<boolean> {
return this.typeTable.getByText(text).count() > 0;
}
async dataContainsText(text: string): Promise<boolean> {
return this.dataTable.getByText(text).count() > 0;
}
}