|
|
@@ -0,0 +1,640 @@
|
|
|
+import { test, expect } from '../../utils/test-setup';
|
|
|
+import { readFileSync } from 'fs';
|
|
|
+import { join, dirname } from 'path';
|
|
|
+import { fileURLToPath } from 'url';
|
|
|
+
|
|
|
+const __filename = fileURLToPath(import.meta.url);
|
|
|
+const __dirname = dirname(__filename);
|
|
|
+const testUsers = JSON.parse(readFileSync(join(__dirname, '../../fixtures/test-users.json'), 'utf-8'));
|
|
|
+
|
|
|
+/**
|
|
|
+ * Story 9.5: 残疾人管理完整 CRUD 流程测试
|
|
|
+ *
|
|
|
+ * 验收标准:
|
|
|
+ * 1. 新增残疾人完整流程(基本信息 + 照片 + 银行卡 + 备注)
|
|
|
+ * 2. 编辑残疾人信息
|
|
|
+ * 3. 删除残疾人
|
|
|
+ * 4. 查看残疾人详情
|
|
|
+ * 5. 列表查询与筛选
|
|
|
+ * 6. 数据导出(如功能可用)
|
|
|
+ */
|
|
|
+
|
|
|
+test.describe.serial('残疾人管理 - 完整 CRUD 流程测试', () => {
|
|
|
+ const TIMESTAMP = Date.now();
|
|
|
+ const UNIQUE_ID = `test_crud_${TIMESTAMP}`;
|
|
|
+
|
|
|
+ // 测试数据生成函数
|
|
|
+ const generateTestPerson = (suffix: string) => ({
|
|
|
+ name: `${UNIQUE_ID}_${suffix}`,
|
|
|
+ gender: '男',
|
|
|
+ idCard: `42010119900101${String(TIMESTAMP + suffix.length).slice(-4)}`,
|
|
|
+ disabilityId: `1234567890${TIMESTAMP + suffix.length}`,
|
|
|
+ disabilityType: '肢体残疾',
|
|
|
+ disabilityLevel: '一级',
|
|
|
+ phone: `138${String(TIMESTAMP + suffix.length).slice(-8).padStart(8, '0')}`,
|
|
|
+ idAddress: `湖北省武汉市测试街道${suffix}号`,
|
|
|
+ province: '湖北省',
|
|
|
+ city: '武汉市',
|
|
|
+ });
|
|
|
+
|
|
|
+ test.beforeEach(async ({ adminLoginPage, disabilityPersonPage }) => {
|
|
|
+ await adminLoginPage.goto();
|
|
|
+ await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
|
|
|
+ await adminLoginPage.expectLoginSuccess();
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ });
|
|
|
+
|
|
|
+ test.describe('AC1: 新增残疾人完整流程', () => {
|
|
|
+ test('应该成功完成新增残疾人完整流程(基本信息)', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('create');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:新增残疾人完整流程 ==========');
|
|
|
+
|
|
|
+ // 1. 打开新增对话框
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ console.log('✓ 对话框已打开');
|
|
|
+
|
|
|
+ // 2. 填写基本信息
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ console.log('✓ 基本信息已填写');
|
|
|
+
|
|
|
+ // 3. 提交表单
|
|
|
+ const result = await disabilityPersonPage.submitForm();
|
|
|
+
|
|
|
+ // 4. 验证提交结果
|
|
|
+ console.log('提交结果:', { hasSuccess: result.hasSuccess, hasError: result.hasError });
|
|
|
+
|
|
|
+ if (result.hasError) {
|
|
|
+ console.log('错误消息:', result.errorMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 等待对话框关闭
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ // 6. 刷新页面并搜索新创建的记录
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 7. 验证记录创建成功
|
|
|
+ const personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+
|
|
|
+ console.log('========== 验证结果 ==========');
|
|
|
+ console.log('数据创建成功:', personExists);
|
|
|
+
|
|
|
+ expect(personExists).toBe(true);
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该成功完成新增残疾人完整流程(含备注)', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('with_note');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:新增残疾人(含备注) ==========');
|
|
|
+
|
|
|
+ // 1. 打开新增对话框
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+
|
|
|
+ // 2. 填写基本信息
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 3. 添加备注
|
|
|
+ await disabilityPersonPage.scrollToSection('备注');
|
|
|
+ await disabilityPersonPage.addNote(`测试备注_${UNIQUE_ID}`);
|
|
|
+ console.log('✓ 备注已添加');
|
|
|
+
|
|
|
+ // 4. 提交表单
|
|
|
+ const result = await disabilityPersonPage.submitForm();
|
|
|
+
|
|
|
+ // 5. 验证结果
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ const personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+
|
|
|
+ expect(personExists).toBe(true);
|
|
|
+ console.log('✓ 含备注的残疾人创建成功');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ test.describe('AC2: 编辑残疾人信息', () => {
|
|
|
+ test('应该成功编辑残疾人基本信息', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('edit');
|
|
|
+ const newName = `${UNIQUE_ID}_edited`;
|
|
|
+
|
|
|
+ console.log('\n========== 测试:编辑残疾人信息 ==========');
|
|
|
+
|
|
|
+ // 1. 先创建一条记录
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ // 刷新并搜索
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 验证记录存在
|
|
|
+ let personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+ expect(personExists).toBe(true);
|
|
|
+ console.log('✓ 原始记录已创建');
|
|
|
+
|
|
|
+ // 2. 打开编辑对话框
|
|
|
+ await disabilityPersonPage.openEditDialog(testData.name);
|
|
|
+ console.log('✓ 编辑对话框已打开');
|
|
|
+
|
|
|
+ // 3. 修改姓名(使用编辑表单)
|
|
|
+ const form = page.locator('form#update-form');
|
|
|
+ await form.waitFor({ state: 'visible', timeout: 5000 });
|
|
|
+
|
|
|
+ const nameInput = form.getByLabel('姓名 *');
|
|
|
+ await nameInput.clear();
|
|
|
+ await nameInput.fill(newName);
|
|
|
+ console.log('✓ 姓名已修改为:', newName);
|
|
|
+
|
|
|
+ // 4. 提交更新
|
|
|
+ const submitButton = page.getByRole('button', { name: '更新' });
|
|
|
+ await submitButton.click();
|
|
|
+ await page.waitForLoadState('networkidle', { timeout: 10000 });
|
|
|
+ await page.waitForTimeout(2000);
|
|
|
+ console.log('✓ 更新已提交');
|
|
|
+
|
|
|
+ // 5. 验证更新后的记录
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(newName);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ const updatedExists = await disabilityPersonPage.personExists(newName);
|
|
|
+ expect(updatedExists).toBe(true);
|
|
|
+ console.log('✓ 编辑成功:新姓名显示在列表中');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该成功编辑并添加备注', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('edit_note');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:编辑并添加备注 ==========');
|
|
|
+
|
|
|
+ // 1. 先创建一条记录
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 2. 打开编辑对话框
|
|
|
+ await disabilityPersonPage.openEditDialog(testData.name);
|
|
|
+
|
|
|
+ // 3. 添加备注
|
|
|
+ await disabilityPersonPage.scrollToSection('银行卡');
|
|
|
+ await page.waitForTimeout(300);
|
|
|
+ await disabilityPersonPage.scrollToSection('备注');
|
|
|
+ await disabilityPersonPage.addNote(`编辑时添加的备注_${UNIQUE_ID}`);
|
|
|
+ console.log('✓ 编辑时添加了备注');
|
|
|
+
|
|
|
+ // 4. 提交更新
|
|
|
+ const submitButton = page.getByRole('button', { name: '更新' });
|
|
|
+ await submitButton.click();
|
|
|
+ await page.waitForLoadState('networkidle', { timeout: 10000 });
|
|
|
+ await page.waitForTimeout(2000);
|
|
|
+
|
|
|
+ // 5. 验证更新成功
|
|
|
+ const stillExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+ expect(stillExists).toBe(true);
|
|
|
+ console.log('✓ 编辑时添加备注成功');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ test.describe('AC3: 删除残疾人', () => {
|
|
|
+ test('应该成功删除残疾人记录', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('delete');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:删除残疾人记录 ==========');
|
|
|
+
|
|
|
+ // 1. 先创建一条记录
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+
|
|
|
+ // 2. 获取初始列表数量
|
|
|
+ const initialCount = await disabilityPersonPage.getListCount();
|
|
|
+ console.log('初始记录数:', initialCount);
|
|
|
+
|
|
|
+ // 搜索并验证记录存在
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ let personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+ expect(personExists).toBe(true);
|
|
|
+ console.log('✓ 记录已创建,准备删除');
|
|
|
+
|
|
|
+ // 3. 删除记录
|
|
|
+ await disabilityPersonPage.deleteDisabilityPerson(testData.name);
|
|
|
+ console.log('✓ 删除操作已执行');
|
|
|
+
|
|
|
+ // 4. 验证删除后列表数量减少
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ const finalCount = await disabilityPersonPage.getListCount();
|
|
|
+ console.log('删除后记录数:', finalCount);
|
|
|
+
|
|
|
+ expect(finalCount).toBeLessThanOrEqual(initialCount);
|
|
|
+
|
|
|
+ // 5. 验证记录不再显示
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+ expect(personExists).toBe(false);
|
|
|
+ console.log('✓ 记录已成功删除,不再显示在列表中');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该正确处理删除确认对话框', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('delete_confirm');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:删除确认对话框 ==========');
|
|
|
+
|
|
|
+ // 1. 创建记录
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 2. 点击删除按钮(但不确认)
|
|
|
+ const row = disabilityPersonPage.personTable.locator('tbody tr').filter({ hasText: testData.name }).first();
|
|
|
+ const deleteButton = row.locator('[data-testid^="delete-person-"]').first();
|
|
|
+ await deleteButton.click();
|
|
|
+
|
|
|
+ // 3. 验证确认对话框出现
|
|
|
+ const confirmDialog = page.locator('[data-testid="delete-confirmation-dialog-title"]');
|
|
|
+ await expect(confirmDialog).toBeVisible({ timeout: 3000 });
|
|
|
+ console.log('✓ 删除确认对话框已显示');
|
|
|
+
|
|
|
+ // 4. 验证对话框内容
|
|
|
+ const dialogText = await page.locator('[role="dialog"]').textContent();
|
|
|
+ expect(dialogText).toContain('确定要删除');
|
|
|
+ expect(dialogText).toContain('此操作不可恢复');
|
|
|
+ console.log('✓ 对话框文案正确');
|
|
|
+
|
|
|
+ // 5. 点击取消
|
|
|
+ const cancelButton = page.getByRole('button', { name: '取消' });
|
|
|
+ await cancelButton.click();
|
|
|
+ await page.waitForTimeout(500);
|
|
|
+
|
|
|
+ // 6. 验证记录仍在列表中
|
|
|
+ const personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+ expect(personExists).toBe(true);
|
|
|
+ console.log('✓ 取消删除后记录仍存在');
|
|
|
+
|
|
|
+ // 7. 实际删除以清理测试数据
|
|
|
+ await disabilityPersonPage.deleteDisabilityPerson(testData.name);
|
|
|
+ console.log('✓ 测试数据已清理');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ test.describe('AC4: 查看残疾人详情', () => {
|
|
|
+ test('应该正确显示残疾人详情', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('detail');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:查看残疾人详情 ==========');
|
|
|
+
|
|
|
+ // 1. 创建一条记录
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 2. 打开详情对话框
|
|
|
+ await disabilityPersonPage.openDetailDialog(testData.name);
|
|
|
+ console.log('✓ 详情对话框已打开');
|
|
|
+
|
|
|
+ // 3. 验证详情对话框显示基本信息
|
|
|
+ const dialog = page.locator('[role="dialog"]').filter({ hasText: '残疾人详情' });
|
|
|
+ await expect(dialog).toBeVisible({ timeout: 5000 });
|
|
|
+
|
|
|
+ // 验证基本信息显示
|
|
|
+ const dialogText = await dialog.textContent();
|
|
|
+ expect(dialogText).toContain(testData.name);
|
|
|
+ expect(dialogText).toContain(testData.idCard);
|
|
|
+ expect(dialogText).toContain(testData.disabilityType);
|
|
|
+ expect(dialogText).toContain(testData.disabilityLevel);
|
|
|
+ expect(dialogText).toContain(testData.phone);
|
|
|
+
|
|
|
+ console.log('✓ 基本信息显示正确');
|
|
|
+ console.log(' - 姓名:', testData.name);
|
|
|
+ console.log(' - 身份证号:', testData.idCard);
|
|
|
+ console.log(' - 残疾类型:', testData.disabilityType);
|
|
|
+ console.log(' - 残疾等级:', testData.disabilityLevel);
|
|
|
+
|
|
|
+ // 4. 关闭详情对话框
|
|
|
+ const closeButton = page.getByRole('button', { name: '关闭' });
|
|
|
+ await closeButton.click();
|
|
|
+ await disabilityPersonPage.waitForDetailDialogClosed();
|
|
|
+ console.log('✓ 详情对话框已关闭');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该能在详情中查看完整信息', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('full_detail');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:查看完整详情信息 ==========');
|
|
|
+
|
|
|
+ // 1. 创建带备注的记录
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.scrollToSection('备注');
|
|
|
+ await disabilityPersonPage.addNote(`测试备注_${UNIQUE_ID}`);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 2. 打开详情
|
|
|
+ await disabilityPersonPage.openDetailDialog(testData.name);
|
|
|
+
|
|
|
+ // 3. 验证详情显示完整
|
|
|
+ const dialog = page.locator('[role="dialog"]').filter({ hasText: '残疾人详情' });
|
|
|
+ const dialogText = await dialog.textContent();
|
|
|
+
|
|
|
+ // 验证关键字段存在
|
|
|
+ expect(dialogText).toContain('姓名');
|
|
|
+ expect(dialogText).toContain('性别');
|
|
|
+ expect(dialogText).toContain('身份证号');
|
|
|
+ expect(dialogText).toContain('残疾证号');
|
|
|
+ expect(dialogText).toContain('联系电话');
|
|
|
+
|
|
|
+ console.log('✓ 详情对话框显示所有基本字段');
|
|
|
+
|
|
|
+ // 4. 关闭对话框
|
|
|
+ await page.getByRole('button', { name: '关闭' }).click();
|
|
|
+ await disabilityPersonPage.waitForDetailDialogClosed();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ test.describe('AC5: 列表查询与筛选', () => {
|
|
|
+ test('应该支持按姓名搜索残疾人', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('search');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:按姓名搜索 ==========');
|
|
|
+
|
|
|
+ // 1. 创建记录
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+
|
|
|
+ // 2. 获取搜索前的列表数量
|
|
|
+ const countBeforeSearch = await disabilityPersonPage.getListCount();
|
|
|
+ console.log('搜索前记录数:', countBeforeSearch);
|
|
|
+
|
|
|
+ // 3. 执行搜索
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 4. 验证搜索结果
|
|
|
+ const personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+ expect(personExists).toBe(true);
|
|
|
+ console.log('✓ 搜索成功:找到目标记录');
|
|
|
+
|
|
|
+ // 5. 验证搜索结果中只有目标记录
|
|
|
+ const searchResults = await disabilityPersonPage.getListData();
|
|
|
+ const matchingResults = searchResults.filter(r => r.name.includes(testData.name));
|
|
|
+ expect(matchingResults.length).toBeGreaterThan(0);
|
|
|
+ console.log(`✓ 搜索结果数量: ${matchingResults.length}`);
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该支持按残疾类型筛选', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('filter');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:按残疾类型筛选 ==========');
|
|
|
+
|
|
|
+ // 1. 创建记录(使用肢体残疾)
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm({
|
|
|
+ ...testData,
|
|
|
+ disabilityType: '肢体残疾',
|
|
|
+ });
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+
|
|
|
+ // 2. 获取筛选前的列表数量
|
|
|
+ await disabilityPersonPage.resetFilters();
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+ const countBeforeFilter = await disabilityPersonPage.getListCount();
|
|
|
+ console.log('筛选前记录数:', countBeforeFilter);
|
|
|
+
|
|
|
+ // 3. 应用筛选(肢体残疾)
|
|
|
+ await disabilityPersonPage.filterByDisabilityType('肢体残疾');
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 4. 验证筛选结果
|
|
|
+ const listData = await disabilityPersonPage.getListCount();
|
|
|
+ console.log('筛选后记录数:', listData);
|
|
|
+
|
|
|
+ // 验证结果中包含我们创建的记录
|
|
|
+ const personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+ expect(personExists).toBe(true);
|
|
|
+ console.log('✓ 筛选成功:找到目标记录');
|
|
|
+
|
|
|
+ // 5. 重置筛选
|
|
|
+ await disabilityPersonPage.resetFilters();
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ const countAfterReset = await disabilityPersonPage.getListCount();
|
|
|
+ console.log('重置后记录数:', countAfterReset);
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该支持重置筛选条件', async ({ disabilityPersonPage, page }) => {
|
|
|
+ console.log('\n========== 测试:重置筛选条件 ==========');
|
|
|
+
|
|
|
+ // 1. 应用筛选
|
|
|
+ await disabilityPersonPage.filterByDisabilityType('肢体残疾');
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ const countAfterFilter = await disabilityPersonPage.getListCount();
|
|
|
+ console.log('应用筛选后记录数:', countAfterFilter);
|
|
|
+
|
|
|
+ // 2. 重置筛选
|
|
|
+ await disabilityPersonPage.resetFilters();
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ // 3. 验证重置后显示所有记录
|
|
|
+ const countAfterReset = await disabilityPersonPage.getListCount();
|
|
|
+ console.log('重置后记录数:', countAfterReset);
|
|
|
+
|
|
|
+ // 重置后数量应该恢复(或至少不减少)
|
|
|
+ expect(countAfterReset).toBeGreaterThanOrEqual(countAfterFilter);
|
|
|
+ console.log('✓ 重置筛选成功');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该正确获取列表数据', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('list_data');
|
|
|
+
|
|
|
+ console.log('\n========== 测试:获取列表数据 ==========');
|
|
|
+
|
|
|
+ // 1. 创建记录
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+
|
|
|
+ // 2. 获取列表数据
|
|
|
+ const listData = await disabilityPersonPage.getListData();
|
|
|
+
|
|
|
+ console.log('列表记录数:', listData.length);
|
|
|
+
|
|
|
+ if (listData.length > 0) {
|
|
|
+ console.log('第一条记录:');
|
|
|
+ console.log(' - 姓名:', listData[0].name);
|
|
|
+ console.log(' - 残疾类型:', listData[0].disabilityType);
|
|
|
+ console.log(' - 残疾等级:', listData[0].disabilityLevel);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 验证数据结构
|
|
|
+ expect(listData).toBeInstanceOf(Array);
|
|
|
+ if (listData.length > 0) {
|
|
|
+ expect(listData[0]).toHaveProperty('name');
|
|
|
+ expect(listData[0]).toHaveProperty('idCard');
|
|
|
+ expect(listData[0]).toHaveProperty('disabilityType');
|
|
|
+ expect(listData[0]).toHaveProperty('disabilityLevel');
|
|
|
+ expect(listData[0]).toHaveProperty('phone');
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('✓ 列表数据结构正确');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ test.describe('AC6: 数据导出', () => {
|
|
|
+ test('应该支持数据导出功能(功能可用性验证)', async ({ disabilityPersonPage, page }) => {
|
|
|
+ console.log('\n========== 测试:数据导出功能 ==========');
|
|
|
+
|
|
|
+ // 检查是否存在导出按钮
|
|
|
+ const exportButton = page.getByRole('button', { name: /导出|下载|Export/i });
|
|
|
+ const exportExists = await exportButton.count() > 0;
|
|
|
+
|
|
|
+ if (exportExists) {
|
|
|
+ console.log('✓ 找到导出按钮');
|
|
|
+ // 注意:实际测试导出功能需要处理下载文件,这里只验证按钮存在
|
|
|
+ expect(exportButton).toBeVisible();
|
|
|
+ } else {
|
|
|
+ console.log('ℹ️ 未找到导出按钮,可能该功能未实现或使用其他方式');
|
|
|
+ // 这不是错误,只是功能可能未实现
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ test.describe('综合测试:完整 CRUD 流程', () => {
|
|
|
+ test('应该完成完整的 CRUD 生命周期', async ({ disabilityPersonPage, page }) => {
|
|
|
+ const testData = generateTestPerson('lifecycle');
|
|
|
+ const updatedName = `${UNIQUE_ID}_lifecycle_updated`;
|
|
|
+
|
|
|
+ console.log('\n========== 测试:完整 CRUD 生命周期 ==========');
|
|
|
+
|
|
|
+ // CREATE: 创建记录
|
|
|
+ console.log('\n[CREATE] 创建残疾人记录...');
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+ await disabilityPersonPage.submitForm();
|
|
|
+ await disabilityPersonPage.waitForDialogClosed();
|
|
|
+ await page.reload();
|
|
|
+ await page.waitForLoadState('networkidle');
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(testData.name);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ let personExists = await disabilityPersonPage.personExists(testData.name);
|
|
|
+ expect(personExists).toBe(true);
|
|
|
+ console.log('✓ CREATE 成功');
|
|
|
+
|
|
|
+ // READ: 查看详情
|
|
|
+ console.log('\n[READ] 查看残疾人详情...');
|
|
|
+ await disabilityPersonPage.openDetailDialog(testData.name);
|
|
|
+ const dialog = page.locator('[role="dialog"]').filter({ hasText: '残疾人详情' });
|
|
|
+ await expect(dialog).toBeVisible();
|
|
|
+ const dialogText = await dialog.textContent();
|
|
|
+ expect(dialogText).toContain(testData.name);
|
|
|
+ await page.getByRole('button', { name: '关闭' }).click();
|
|
|
+ await disabilityPersonPage.waitForDetailDialogClosed();
|
|
|
+ console.log('✓ READ 成功');
|
|
|
+
|
|
|
+ // UPDATE: 更新记录
|
|
|
+ console.log('\n[UPDATE] 更新残疾人记录...');
|
|
|
+ await disabilityPersonPage.openEditDialog(testData.name);
|
|
|
+ const form = page.locator('form#update-form');
|
|
|
+ await form.waitFor({ state: 'visible', timeout: 5000 });
|
|
|
+
|
|
|
+ const nameInput = form.getByLabel('姓名 *');
|
|
|
+ await nameInput.clear();
|
|
|
+ await nameInput.fill(updatedName);
|
|
|
+
|
|
|
+ const submitButton = page.getByRole('button', { name: '更新' });
|
|
|
+ await submitButton.click();
|
|
|
+ await page.waitForLoadState('networkidle', { timeout: 10000 });
|
|
|
+ await page.waitForTimeout(2000);
|
|
|
+
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(updatedName);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ const updatedExists = await disabilityPersonPage.personExists(updatedName);
|
|
|
+ expect(updatedExists).toBe(true);
|
|
|
+ console.log('✓ UPDATE 成功');
|
|
|
+
|
|
|
+ // DELETE: 删除记录
|
|
|
+ console.log('\n[DELETE] 删除残疾人记录...');
|
|
|
+ await disabilityPersonPage.deleteDisabilityPerson(updatedName);
|
|
|
+ await page.waitForTimeout(1000);
|
|
|
+
|
|
|
+ const deletedExists = await disabilityPersonPage.personExists(updatedName);
|
|
|
+ expect(deletedExists).toBe(false);
|
|
|
+ console.log('✓ DELETE 成功');
|
|
|
+
|
|
|
+ console.log('\n========== 完整 CRUD 生命周期测试完成 ==========');
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|