disability-person-phone-layout.spec.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import { test, expect } from '../../utils/test-setup';
  2. import { readFileSync } from 'fs';
  3. import { join, dirname } from 'path';
  4. import { fileURLToPath } from 'url';
  5. const __filename = fileURLToPath(import.meta.url);
  6. const __dirname = dirname(__filename);
  7. const testUsers = JSON.parse(readFileSync(join(__dirname, '../../fixtures/test-users.json'), 'utf-8'));
  8. test.describe.serial('残疾人管理 - 电话布局优化 (Story 15.6)', () => {
  9. test.beforeEach(async ({ adminLoginPage, disabilityPersonPage }) => {
  10. await adminLoginPage.goto();
  11. await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
  12. await adminLoginPage.expectLoginSuccess();
  13. await disabilityPersonPage.goto();
  14. });
  15. test('AC1: 联系电话区域布局优化 - 监护人电话和本人电话相邻显示', async ({ disabilityPersonPage, page }) => {
  16. console.debug('\n========== Story 15.6 AC1: 联系电话区域布局优化 ==========');
  17. // 打开新增残疾人对话框
  18. await disabilityPersonPage.openCreateDialog();
  19. console.debug('✓ 对话框已打开');
  20. // 等待对话框完全加载
  21. await page.waitForTimeout(500);
  22. // 查找监护人电话管理区域
  23. const guardianPhoneSection = page.locator('text=监护人电话管理').first();
  24. await expect(guardianPhoneSection).toBeVisible();
  25. console.debug('✓ 监护人电话管理区域可见');
  26. // 查找本人电话管理区域
  27. const personPhoneSection = page.locator('text=本人电话管理').first();
  28. await expect(personPhoneSection).toBeVisible();
  29. console.debug('✓ 本人电话管理区域可见');
  30. // 验证两个区域相邻显示(通过 DOM 结构验证)
  31. // 获取监护人电话区域的父元素
  32. const guardianParent = guardianPhoneSection.locator('xpath=ancestor::div[contains(@class, "col-span-full")][1]');
  33. // 获取本人电话区域的父元素
  34. const personParent = personPhoneSection.locator('xpath=ancestor::div[contains(@class, "col-span-full")][1]');
  35. // 验证它们是兄弟节点(相邻显示)
  36. const guardianParentExists = await guardianParent.count();
  37. const personParentExists = await personParent.count();
  38. expect(guardianParentExists).toBeGreaterThan(0);
  39. expect(personParentExists).toBeGreaterThan(0);
  40. console.debug('✓ 监护人电话和本人电话相邻显示');
  41. // 关闭对话框
  42. await page.locator('button:has-text("取消")').first().click();
  43. });
  44. test('AC2: 本人电话支持动态添加多个号码', async ({ disabilityPersonPage, page }) => {
  45. console.debug('\n========== Story 15.6 AC2: 本人电话支持动态添加 ==========');
  46. const timestamp = Date.now();
  47. const testData = {
  48. name: `电话测试_${timestamp}`,
  49. gender: '男',
  50. idCard: `42010119900101123${timestamp % 10}`,
  51. disabilityId: `5110011990010${timestamp % 10}`,
  52. disabilityType: '视力残疾',
  53. disabilityLevel: '一级',
  54. phone: '13800138001',
  55. idAddress: '湖北省武汉市测试街道1号',
  56. province: '湖北省',
  57. city: '武汉市'
  58. };
  59. // 打开新增残疾人对话框
  60. await disabilityPersonPage.openCreateDialog();
  61. // 填写基本信息
  62. await disabilityPersonPage.fillBasicForm(testData);
  63. // 查找并点击"添加本人电话"按钮
  64. const addPersonPhoneButton = page.locator('button:has-text("添加本人电话")').first();
  65. await expect(addPersonPhoneButton).toBeVisible();
  66. console.debug('✓ 添加本人电话按钮可见');
  67. // 点击添加第一个电话
  68. await addPersonPhoneButton.click();
  69. await page.waitForTimeout(300);
  70. // 验证电话输入框出现
  71. const phoneInput1 = page.locator('input[placeholder*="请输入本人电话"]').first();
  72. await expect(phoneInput1).toBeVisible();
  73. console.debug('✓ 第一个本人电话输入框已出现');
  74. // 填写第一个电话号码
  75. await phoneInput1.fill('13800138001');
  76. console.debug('✓ 第一个本人电话已填写: 13800138001');
  77. // 点击添加第二个电话
  78. await addPersonPhoneButton.click();
  79. await page.waitForTimeout(300);
  80. // 验证第二个电话输入框出现
  81. const phoneInputs = page.locator('input[placeholder*="请输入本人电话"]');
  82. const count = await phoneInputs.count();
  83. expect(count).toBeGreaterThanOrEqual(2);
  84. console.debug(`✓ 第二个本人电话输入框已出现,共 ${count} 个`);
  85. // 填写第二个电话号码
  86. await phoneInputs.nth(1).fill('13800138002');
  87. console.debug('✓ 第二个本人电话已填写: 13800138002');
  88. // 验证最多可添加5个的限制
  89. for (let i = 2; i < 5; i++) {
  90. await addPersonPhoneButton.click();
  91. await page.waitForTimeout(200);
  92. }
  93. const maxPhoneInputs = page.locator('input[placeholder*="请输入本人电话"]');
  94. const maxCount = await maxPhoneInputs.count();
  95. expect(maxCount).toBeLessThanOrEqual(5);
  96. console.debug(`✓ 本人电话数量限制正确: ${maxCount} 个(最多5个)`);
  97. // 取消对话框
  98. await page.locator('button:has-text("取消")').first().click();
  99. });
  100. test('AC3: 监护人电话功能保持正常', async ({ disabilityPersonPage, page }) => {
  101. console.debug('\n========== Story 15.6 AC3: 监护人电话功能保持正常 ==========');
  102. const timestamp = Date.now();
  103. const testData = {
  104. name: `监护人电话测试_${timestamp}`,
  105. gender: '男',
  106. idCard: `42010119900101123${timestamp % 10}`,
  107. disabilityId: `5110011990010${timestamp % 10}`,
  108. disabilityType: '视力残疾',
  109. disabilityLevel: '一级',
  110. phone: '13800138001',
  111. idAddress: '湖北省武汉市测试街道1号',
  112. province: '湖北省',
  113. city: '武汉市'
  114. };
  115. // 打开新增残疾人对话框
  116. await disabilityPersonPage.openCreateDialog();
  117. // 填写基本信息
  118. await disabilityPersonPage.fillBasicForm(testData);
  119. // 查找"添加监护人电话"按钮
  120. const addGuardianPhoneButton = page.locator('button:has-text("添加监护人电话")').first();
  121. await expect(addGuardianPhoneButton).toBeVisible();
  122. console.debug('✓ 添加监护人电话按钮可见');
  123. // 点击添加监护人电话
  124. await addGuardianPhoneButton.click();
  125. await page.waitForTimeout(300);
  126. // 验证监护人电话输入框出现
  127. const guardianPhoneInput = page.locator('input[placeholder*="请输入监护人电话"]').first();
  128. await expect(guardianPhoneInput).toBeVisible();
  129. console.debug('✓ 监护人电话输入框已出现');
  130. // 填写监护人电话
  131. await guardianPhoneInput.fill('13900139001');
  132. console.debug('✓ 监护人电话已填写: 13900139001');
  133. // 验证设置主要联系人选项存在
  134. const primaryCheckbox = page.locator('input[type="checkbox"]').first();
  135. await expect(primaryCheckbox).toBeVisible();
  136. console.debug('✓ 设置主要联系人选项可见');
  137. // 取消对话框
  138. await page.locator('button:has-text("取消")').first().click();
  139. });
  140. test('AC4: 两个电话区域使用相同的 UI 组件和交互方式', async ({ disabilityPersonPage, page }) => {
  141. console.debug('\n========== Story 15.6 AC4: UI 组件一致性 ==========');
  142. // 打开新增残疾人对话框
  143. await disabilityPersonPage.openCreateDialog();
  144. // 验证两个区域有相同的提示文本结构
  145. const guardianHint = page.locator('text=最多可添加 5 个监护人电话');
  146. const personHint = page.locator('text=最多可添加 5 个本人电话');
  147. await expect(guardianHint).toBeVisible();
  148. await expect(personHint).toBeVisible();
  149. console.debug('✓ 两个区域都有相同的提示文本');
  150. // 验证两个区域都有主要联系人提示
  151. const guardianPrimaryHint = page.locator('text=只能设置一个主要联系人');
  152. const personPrimaryHint = page.locator('text=只能设置一个主要联系电话');
  153. await expect(guardianPrimaryHint).toBeVisible();
  154. await expect(personPrimaryHint).toBeVisible();
  155. console.debug('✓ 两个区域都有主要联系人提示');
  156. // 验证按钮样式一致性(都使用相同的按钮结构)
  157. const addButtonPattern = /添加(监护人|本人)电话/;
  158. const addButtons = page.locator('button').filter({ hasText: addButtonPattern });
  159. const buttonCount = await addButtons.count();
  160. expect(buttonCount).toBe(2);
  161. console.debug('✓ 两个区域都有添加按钮');
  162. // 取消对话框
  163. await page.locator('button:has-text("取消")').first().click();
  164. });
  165. });