|
|
@@ -0,0 +1,304 @@
|
|
|
+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'));
|
|
|
+
|
|
|
+// 超时配置
|
|
|
+const TIMEOUTS = {
|
|
|
+ SHORT: 300,
|
|
|
+ MEDIUM: 500,
|
|
|
+ LONG: 1000,
|
|
|
+} as const;
|
|
|
+
|
|
|
+// 用于跟踪已创建的测试数据,便于清理
|
|
|
+const createdTestData: Array<{ name: string; idCard: string }> = [];
|
|
|
+
|
|
|
+/**
|
|
|
+ * 生成唯一的测试数据
|
|
|
+ */
|
|
|
+function generateUniqueTestData(suffix: string) {
|
|
|
+ const randomPart = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
|
|
+ const timestamp = Date.now();
|
|
|
+ return {
|
|
|
+ name: `备注${suffix}_${timestamp}_${randomPart}`,
|
|
|
+ gender: randomPart % 2 === 0 ? '男' : '女',
|
|
|
+ idCard: `42010119900101${String(randomPart % 10000).padStart(4, '0')}`,
|
|
|
+ disabilityId: `511001199001${String(randomPart % 10000).padStart(4, '0')}`,
|
|
|
+ disabilityType: ['视力残疾', '听力残疾', '言语残疾', '肢体残疾', '智力残疾', '精神残疾'][randomPart % 6],
|
|
|
+ disabilityLevel: ['一级', '二级', '三级', '四级'][randomPart % 4],
|
|
|
+ phone: `138${String(randomPart % 100000000).padStart(8, '0')}`,
|
|
|
+ idAddress: `湖北省武汉市测试街道${randomPart % 100}号`,
|
|
|
+ province: '湖北省',
|
|
|
+ city: '武汉市'
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+test.describe.serial('残疾人管理 - 备注管理功能', () => {
|
|
|
+ test.beforeEach(async ({ adminLoginPage, disabilityPersonPage }) => {
|
|
|
+ // 以管理员身份登录后台
|
|
|
+ await adminLoginPage.goto();
|
|
|
+ await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
|
|
|
+ await adminLoginPage.expectLoginSuccess();
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ });
|
|
|
+
|
|
|
+ test.afterEach(async ({ disabilityPersonPage, page }) => {
|
|
|
+ // 清理测试数据
|
|
|
+ for (const data of createdTestData) {
|
|
|
+ try {
|
|
|
+ await disabilityPersonPage.goto();
|
|
|
+ await disabilityPersonPage.searchByName(data.name);
|
|
|
+ const deleteButton = page.getByRole('button', { name: '删除' }).first();
|
|
|
+ if (await deleteButton.count() > 0) {
|
|
|
+ await deleteButton.click();
|
|
|
+ await page.getByRole('button', { name: '确认' }).click().catch(() => {});
|
|
|
+ await page.waitForTimeout(TIMEOUTS.MEDIUM);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.debug(` ⚠ 清理数据失败: ${data.name}`, error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ createdTestData.length = 0;
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该成功添加简单备注', async ({ disabilityPersonPage }) => {
|
|
|
+ const testData = generateUniqueTestData('简单备注');
|
|
|
+ createdTestData.push({ name: testData.name, idCard: testData.idCard });
|
|
|
+
|
|
|
+ console.log('\n========== 添加简单备注测试 ==========');
|
|
|
+
|
|
|
+ // 打开对话框并填写基本信息
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 滚动到备注管理区域
|
|
|
+ await disabilityPersonPage.scrollToSection('备注管理');
|
|
|
+
|
|
|
+ // 添加备注
|
|
|
+ const noteContent = `这是一条测试备注_${testData.name}`;
|
|
|
+ await disabilityPersonPage.addNote(noteContent);
|
|
|
+
|
|
|
+ // 验证备注出现在列表中
|
|
|
+ const noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList).toHaveLength(1);
|
|
|
+ expect(noteList[0]).toContain(noteContent);
|
|
|
+ console.debug(' ✓ 备注已添加');
|
|
|
+
|
|
|
+ console.log('✅ 添加简单备注测试通过');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该成功添加长文本备注', async ({ disabilityPersonPage }) => {
|
|
|
+ const testData = generateUniqueTestData('长文本备注');
|
|
|
+ createdTestData.push({ name: testData.name, idCard: testData.idCard });
|
|
|
+
|
|
|
+ console.log('\n========== 添加长文本备注测试 ==========');
|
|
|
+
|
|
|
+ // 打开对话框并填写基本信息
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 滚动到备注管理区域
|
|
|
+ await disabilityPersonPage.scrollToSection('备注管理');
|
|
|
+
|
|
|
+ // 添加长文本备注
|
|
|
+ const longNote = `这是一条很长的备注内容_${testData.name}`.repeat(10);
|
|
|
+ await disabilityPersonPage.addNote(longNote);
|
|
|
+
|
|
|
+ // 验证备注出现在列表中
|
|
|
+ const noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList).toHaveLength(1);
|
|
|
+ expect(noteList[0]).toContain('这是一条很长的备注内容');
|
|
|
+ console.debug(' ✓ 长文本备注已添加');
|
|
|
+
|
|
|
+ console.log('✅ 添加长文本备注测试通过');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该成功编辑备注', async ({ disabilityPersonPage }) => {
|
|
|
+ const testData = generateUniqueTestData('编辑备注');
|
|
|
+ createdTestData.push({ name: testData.name, idCard: testData.idCard });
|
|
|
+
|
|
|
+ console.log('\n========== 编辑备注测试 ==========');
|
|
|
+
|
|
|
+ // 打开对话框并填写基本信息
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 滚动到备注管理区域
|
|
|
+ await disabilityPersonPage.scrollToSection('备注管理');
|
|
|
+
|
|
|
+ // 添加原始备注
|
|
|
+ const originalNote = `原始备注_${testData.name}`;
|
|
|
+ await disabilityPersonPage.addNote(originalNote);
|
|
|
+
|
|
|
+ // 编辑备注
|
|
|
+ const updatedNote = `更新后的备注_${testData.name}`;
|
|
|
+ await disabilityPersonPage.editNote(0, updatedNote);
|
|
|
+
|
|
|
+ // 验证更新后的内容
|
|
|
+ const noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList[0]).toContain(updatedNote);
|
|
|
+ expect(noteList[0]).not.toContain(originalNote);
|
|
|
+ console.debug(' ✓ 备注已编辑');
|
|
|
+
|
|
|
+ console.log('✅ 编辑备注测试通过');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该成功删除备注', async ({ disabilityPersonPage }) => {
|
|
|
+ const testData = generateUniqueTestData('删除备注');
|
|
|
+ createdTestData.push({ name: testData.name, idCard: testData.idCard });
|
|
|
+
|
|
|
+ console.log('\n========== 删除备注测试 ==========');
|
|
|
+
|
|
|
+ // 打开对话框并填写基本信息
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 滚动到备注管理区域
|
|
|
+ await disabilityPersonPage.scrollToSection('备注管理');
|
|
|
+
|
|
|
+ // 添加备注
|
|
|
+ const noteContent = `待删除备注_${testData.name}`;
|
|
|
+ await disabilityPersonPage.addNote(noteContent);
|
|
|
+
|
|
|
+ // 验证备注存在
|
|
|
+ let noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList).toHaveLength(1);
|
|
|
+ console.debug(' ✓ 备注已添加');
|
|
|
+
|
|
|
+ // 删除备注
|
|
|
+ await disabilityPersonPage.deleteNote(0);
|
|
|
+
|
|
|
+ // 验证备注已被删除
|
|
|
+ noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList).toHaveLength(0);
|
|
|
+ console.debug(' ✓ 备注已删除');
|
|
|
+
|
|
|
+ console.log('✅ 删除备注测试通过');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该支持添加多条备注', async ({ disabilityPersonPage }) => {
|
|
|
+ const testData = generateUniqueTestData('多条备注');
|
|
|
+ createdTestData.push({ name: testData.name, idCard: testData.idCard });
|
|
|
+
|
|
|
+ console.log('\n========== 添加多条备注测试 ==========');
|
|
|
+
|
|
|
+ // 打开对话框并填写基本信息
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 滚动到备注管理区域
|
|
|
+ await disabilityPersonPage.scrollToSection('备注管理');
|
|
|
+
|
|
|
+ // 添加多条备注
|
|
|
+ await disabilityPersonPage.addNote(`备注1_${testData.name}`);
|
|
|
+ await disabilityPersonPage.addNote(`备注2_${testData.name}`);
|
|
|
+ await disabilityPersonPage.addNote(`备注3_${testData.name}`);
|
|
|
+
|
|
|
+ // 验证所有备注都显示
|
|
|
+ const noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList).toHaveLength(3);
|
|
|
+ console.debug(' ✓ 已添加 3 条备注');
|
|
|
+
|
|
|
+ console.log('✅ 添加多条备注测试通过');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该支持标记特殊需求', async ({ disabilityPersonPage }) => {
|
|
|
+ const testData = generateUniqueTestData('特殊需求');
|
|
|
+ createdTestData.push({ name: testData.name, idCard: testData.idCard });
|
|
|
+
|
|
|
+ console.log('\n========== 特殊需求标记测试 ==========');
|
|
|
+
|
|
|
+ // 打开对话框并填写基本信息
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 滚动到备注管理区域
|
|
|
+ await disabilityPersonPage.scrollToSection('备注管理');
|
|
|
+
|
|
|
+ // 添加带特殊需求标记的备注
|
|
|
+ const noteContent = `特殊需求备注_${testData.name}`;
|
|
|
+ await disabilityPersonPage.addNote(noteContent, { isSpecialNeeds: true });
|
|
|
+
|
|
|
+ // 验证特殊需求开关状态
|
|
|
+ const isSpecialNeeds = await disabilityPersonPage.getNoteSpecialNeedsStatus(0);
|
|
|
+ expect(isSpecialNeeds).toBe(true);
|
|
|
+ console.debug(' ✓ 特殊需求已标记');
|
|
|
+
|
|
|
+ console.log('✅ 特殊需求标记测试通过');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('应该限制最多添加10条备注', async ({ disabilityPersonPage }) => {
|
|
|
+ const testData = generateUniqueTestData('备注限制');
|
|
|
+ createdTestData.push({ name: testData.name, idCard: testData.idCard });
|
|
|
+
|
|
|
+ console.log('\n========== 备注数量限制测试 ==========');
|
|
|
+
|
|
|
+ // 打开对话框并填写基本信息
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 滚动到备注管理区域
|
|
|
+ await disabilityPersonPage.scrollToSection('备注管理');
|
|
|
+
|
|
|
+ // 添加10条备注
|
|
|
+ for (let i = 0; i < 10; i++) {
|
|
|
+ await disabilityPersonPage.addNote(`备注${i + 1}_${testData.name}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证有10条备注
|
|
|
+ const noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList).toHaveLength(10);
|
|
|
+ console.debug(' ✓ 已添加 10 条备注');
|
|
|
+
|
|
|
+ // 验证添加按钮被禁用
|
|
|
+ const isDisabled = await disabilityPersonPage.isAddNoteButtonDisabled();
|
|
|
+ expect(isDisabled).toBe(true);
|
|
|
+ console.debug(' ✓ 添加按钮已禁用(达到最大数量)');
|
|
|
+
|
|
|
+ console.log('✅ 备注数量限制测试通过');
|
|
|
+ });
|
|
|
+
|
|
|
+ test('完整流程:添加多条备注、编辑、删除', async ({ disabilityPersonPage }) => {
|
|
|
+ const testData = generateUniqueTestData('完整流程');
|
|
|
+ createdTestData.push({ name: testData.name, idCard: testData.idCard });
|
|
|
+
|
|
|
+ console.log('\n========== 备注完整流程测试 ==========');
|
|
|
+
|
|
|
+ // 打开对话框并填写基本信息
|
|
|
+ await disabilityPersonPage.openCreateDialog();
|
|
|
+ await disabilityPersonPage.fillBasicForm(testData);
|
|
|
+
|
|
|
+ // 滚动到备注管理区域
|
|
|
+ await disabilityPersonPage.scrollToSection('备注管理');
|
|
|
+
|
|
|
+ // 添加多条备注
|
|
|
+ await disabilityPersonPage.addNote(`第一条备注_${testData.name}`, { isSpecialNeeds: true });
|
|
|
+ await disabilityPersonPage.addNote(`第二条备注_${testData.name}`);
|
|
|
+ await disabilityPersonPage.addNote(`第三条备注_${testData.name}`);
|
|
|
+
|
|
|
+ let noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList).toHaveLength(3);
|
|
|
+ console.debug(' ✓ 已添加 3 条备注');
|
|
|
+
|
|
|
+ // 编辑第一条备注
|
|
|
+ await disabilityPersonPage.editNote(0, `编辑后的第一条备注_${testData.name}`);
|
|
|
+ console.debug(' ✓ 第一条备注已编辑');
|
|
|
+
|
|
|
+ // 删除第二条备注
|
|
|
+ await disabilityPersonPage.deleteNote(1);
|
|
|
+ console.debug(' ✓ 第二条备注已删除');
|
|
|
+
|
|
|
+ // 验证最终状态
|
|
|
+ noteList = await disabilityPersonPage.getNoteList();
|
|
|
+ expect(noteList).toHaveLength(2);
|
|
|
+ expect(noteList[0]).toContain('编辑后的第一条备注');
|
|
|
+ expect(noteList[1]).toContain('第三条备注');
|
|
|
+ console.debug(' ✓ 最终状态验证通过');
|
|
|
+
|
|
|
+ console.log('✅ 备注完整流程测试通过');
|
|
|
+ });
|
|
|
+});
|