disability-person.page.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. import { Page, Locator } from '@playwright/test';
  2. import { selectRadixOption, selectProvinceCity } from '@d8d/e2e-test-utils';
  3. // 超时配置常量
  4. const TIMEOUTS = {
  5. SHORT: 300,
  6. MEDIUM: 500,
  7. LONG: 1000,
  8. VERY_SHORT: 200,
  9. } as const;
  10. // 注意:@d8d/e2e-test-utils 包已安装,将在后续 story (2.2, 2.3) 中实际使用
  11. export class DisabilityPersonManagementPage {
  12. readonly page: Page;
  13. readonly pageTitle: Locator;
  14. readonly addPersonButton: Locator;
  15. readonly keywordSearchInput: Locator;
  16. readonly searchButton: Locator;
  17. readonly personTable: Locator;
  18. constructor(page: Page) {
  19. this.page = page;
  20. this.pageTitle = page.getByText('残疾人个人管理');
  21. this.addPersonButton = page.getByRole('button', { name: '新增残疾人' });
  22. this.keywordSearchInput = page.getByPlaceholder('搜索姓名或身份证号');
  23. this.searchButton = page.getByRole('button', { name: '搜索' });
  24. this.personTable = page.locator('table');
  25. }
  26. async goto() {
  27. await this.page.goto('/admin/disabilities');
  28. await this.page.waitForLoadState('domcontentloaded');
  29. // 等待页面标题出现
  30. await this.pageTitle.waitFor({ state: 'visible', timeout: 15000 });
  31. // 等待表格数据加载
  32. await this.page.waitForSelector('table tbody tr', { state: 'visible', timeout: 20000 });
  33. await this.expectToBeVisible();
  34. }
  35. async expectToBeVisible() {
  36. await this.pageTitle.waitFor({ state: 'visible', timeout: 15000 });
  37. await this.addPersonButton.waitFor({ state: 'visible', timeout: 10000 });
  38. }
  39. async openCreateDialog() {
  40. // 监听网络请求
  41. const responses: any[] = [];
  42. this.page.on('response', async (response) => {
  43. if (response.url().includes('disabled-person') || response.url().includes('aggregated')) {
  44. try {
  45. const responseData = await response.json().catch(() => ({ status: response.status() }));
  46. responses.push({
  47. url: response.url(),
  48. status: response.status(),
  49. data: responseData
  50. });
  51. } catch (e) {
  52. responses.push({
  53. url: response.url(),
  54. status: response.status(),
  55. error: e
  56. });
  57. }
  58. }
  59. });
  60. await this.addPersonButton.click();
  61. await this.page.waitForSelector('[data-testid="create-disabled-person-dialog-title"]', { state: 'visible', timeout: 5000 });
  62. return responses;
  63. }
  64. async fillBasicForm(data: {
  65. name: string;
  66. gender: string;
  67. idCard: string;
  68. disabilityId: string;
  69. disabilityType: string;
  70. disabilityLevel: string;
  71. phone: string;
  72. idAddress: string;
  73. province: string;
  74. city: string;
  75. }) {
  76. // 等待表单出现
  77. const form = this.page.locator('form#create-form');
  78. await form.waitFor({ state: 'visible', timeout: 5000 });
  79. console.debug('开始填写表单...');
  80. // 填写基本信息 - 使用 form locator 确保只在对话框内查找
  81. await form.getByLabel('姓名 *').fill(data.name);
  82. console.debug('✓ 姓名已填写:', data.name);
  83. // 性别 - 使用 data-testid
  84. const genderTrigger = this.page.locator('[data-testid="gender-select"]');
  85. await genderTrigger.click();
  86. await this.page.getByRole('option', { name: data.gender }).click();
  87. console.debug('✓ 性别已选择:', data.gender);
  88. await form.getByLabel('身份证号 *').fill(data.idCard);
  89. console.debug('✓ 身份证号已填写');
  90. await form.getByLabel('残疾证号 *').fill(data.disabilityId);
  91. console.debug('✓ 残疾证号已填写');
  92. // 残疾类型 - 使用 data-testid
  93. const disabilityTypeTrigger = this.page.locator('[data-testid="disability-type-select"]');
  94. await disabilityTypeTrigger.scrollIntoViewIfNeeded();
  95. await this.page.waitForTimeout(200);
  96. await disabilityTypeTrigger.click();
  97. await this.page.getByRole('option', { name: data.disabilityType }).click();
  98. console.debug('✓ 残疾类型已选择:', data.disabilityType);
  99. // 残疾等级 - 使用 data-testid
  100. const disabilityLevelTrigger = this.page.locator('[data-testid="disability-level-select"]');
  101. await disabilityLevelTrigger.scrollIntoViewIfNeeded();
  102. await this.page.waitForTimeout(200);
  103. await disabilityLevelTrigger.click();
  104. await this.page.getByRole('option', { name: data.disabilityLevel }).click();
  105. console.debug('✓ 残疾等级已选择:', data.disabilityLevel);
  106. await form.getByLabel('联系电话 *').fill(data.phone);
  107. console.debug('✓ 联系电话已填写');
  108. await form.getByLabel('身份证地址 *').fill(data.idAddress);
  109. console.debug('✓ 身份证地址已填写');
  110. // 居住地址 - 省市区级联选择
  111. // AreaSelectForm 使用 data-testid="area-select-province" 等属性
  112. const provinceTrigger = this.page.locator('[data-testid="area-select-province"]');
  113. await provinceTrigger.scrollIntoViewIfNeeded();
  114. await provinceTrigger.click();
  115. await this.page.getByRole('option', { name: data.province }).click();
  116. console.debug('✓ 省份已选择:', data.province);
  117. const cityTrigger = this.page.locator('[data-testid="area-select-city"]');
  118. await cityTrigger.click();
  119. await this.page.getByRole('option', { name: data.city }).click();
  120. console.debug('✓ 城市已选择:', data.city);
  121. console.debug('表单填写完成');
  122. }
  123. async submitForm() {
  124. // 收集网络响应
  125. const responses: any[] = [];
  126. // 监听所有网络请求
  127. this.page.on('response', async (response) => {
  128. const url = response.url();
  129. if (url.includes('disabled-person') || url.includes('aggregated')) {
  130. const requestBody = response.request()?.postData();
  131. const responseBody = await response.text().catch(() => '');
  132. let jsonBody = null;
  133. try {
  134. jsonBody = JSON.parse(responseBody);
  135. } catch (e) {
  136. // 不是 JSON
  137. }
  138. responses.push({
  139. url,
  140. method: response.request()?.method(),
  141. status: response.status(),
  142. ok: response.ok(),
  143. requestHeaders: await response.allHeaders().catch(() => ({})),
  144. responseHeaders: await response.allHeaders().catch(() => ({})),
  145. requestBody: requestBody ? JSON.parse(requestBody) : null,
  146. responseBody: jsonBody || responseBody,
  147. statusText: response.statusText()
  148. });
  149. }
  150. });
  151. // 点击创建按钮
  152. const submitButton = this.page.getByRole('button', { name: '创建' });
  153. await submitButton.click();
  154. // 等待网络请求完成
  155. await this.page.waitForLoadState('networkidle', { timeout: 10000 });
  156. // 等待一段时间让 Toast 消息显示
  157. await this.page.waitForTimeout(2000);
  158. // 检查是否有错误提示
  159. const errorToast = this.page.locator('[data-sonner-toast][data-type="error"]');
  160. const successToast = this.page.locator('[data-sonner-toast][data-type="success"]');
  161. const hasError = await errorToast.count() > 0;
  162. const hasSuccess = await successToast.count() > 0;
  163. let errorMessage = null;
  164. let successMessage = null;
  165. if (hasError) {
  166. errorMessage = await errorToast.first().textContent();
  167. }
  168. if (hasSuccess) {
  169. successMessage = await successToast.first().textContent();
  170. }
  171. return {
  172. responses,
  173. hasError,
  174. hasSuccess,
  175. errorMessage,
  176. successMessage
  177. };
  178. }
  179. async searchByName(name: string) {
  180. await this.keywordSearchInput.fill(name);
  181. await this.searchButton.click();
  182. await this.page.waitForLoadState('networkidle');
  183. await this.page.waitForTimeout(1000);
  184. }
  185. async personExists(name: string): Promise<boolean> {
  186. const personRow = this.personTable.locator('tbody tr').filter({ hasText: name }).first();
  187. return (await personRow.count()) > 0;
  188. }
  189. /**
  190. * 上传照片
  191. * @param photoType 照片类型(身份证照片、残疾证照片、个人照片、其他照片)
  192. * @param fileName 文件名
  193. */
  194. async uploadPhoto(photoType: string, fileName: string) {
  195. // 找到对应照片类型的上传按钮区域
  196. const photoSection = this.page.locator('text=' + photoType).first();
  197. await photoSection.scrollIntoViewIfNeeded();
  198. // 查找该类型照片区域的"上传"按钮
  199. const uploadButton = photoSection.locator('xpath=ancestor::div[contains(@class, "space-y-")]').first()
  200. .getByRole('button', { name: /上传/ }).first();
  201. // 创建测试文件
  202. const fileInput = await uploadButton.evaluateHandle((el: any) => {
  203. const input = el.querySelector('input[type="file"]');
  204. return input;
  205. });
  206. // 使用临时文件上传
  207. const file = {
  208. name: fileName,
  209. mimeType: 'image/jpeg',
  210. buffer: Buffer.from('fake image content')
  211. };
  212. await fileInput.uploadFile(file as any);
  213. await this.page.waitForTimeout(500); // 等待上传处理
  214. console.log(` ✓ 上传照片: ${photoType} - ${fileName}`);
  215. }
  216. /**
  217. * 添加银行卡(内联表单模式)
  218. * @param bankCard 银行卡信息
  219. */
  220. async addBankCard(bankCard: {
  221. bankName: string;
  222. subBankName: string;
  223. cardNumber: string;
  224. cardholderName: string;
  225. cardType?: string;
  226. isDefault?: boolean;
  227. }) {
  228. // 滚动到银行卡管理区域
  229. const bankCardLabel = this.page.getByText('银行卡管理');
  230. await bankCardLabel.scrollIntoViewIfNeeded();
  231. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  232. // 获取当前银行卡数量
  233. const currentCardCount = await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  234. // 点击"添加银行卡"按钮
  235. const addButton = this.page.locator('[data-testid="add-bank-card-button"]');
  236. await addButton.click();
  237. await this.page.waitForTimeout(500);
  238. // 等待新的银行卡卡片出现
  239. const newCardCount = await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  240. if (newCardCount !== currentCardCount + 1) {
  241. throw new Error(`添加银行卡失败:预期 ${currentCardCount + 1} 张,实际 ${newCardCount} 张`);
  242. }
  243. // 新添加的银行卡索引
  244. const cardIndex = currentCardCount;
  245. // 1. 选择银行名称
  246. const bankSelectTrigger = this.page.locator(`[data-testid="bank-select-${cardIndex}"]`);
  247. await bankSelectTrigger.click();
  248. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  249. await this.page.getByRole('option', { name: bankCard.bankName }).click();
  250. // 2. 填写发卡支行
  251. const subBankInput = this.page.locator(`[data-testid="sub-bank-name-input-${cardIndex}"]`);
  252. await subBankInput.fill(bankCard.subBankName);
  253. // 3. 填写银行卡号
  254. const cardNumberInput = this.page.locator(`[data-testid="card-number-input-${cardIndex}"]`);
  255. await cardNumberInput.fill(bankCard.cardNumber);
  256. // 4. 填写持卡人姓名
  257. const cardholderInput = this.page.locator(`[data-testid="cardholder-name-input-${cardIndex}"]`);
  258. await cardholderInput.fill(bankCard.cardholderName);
  259. // 5. 选择银行卡类型(可选)
  260. if (bankCard.cardType) {
  261. const cardTypeTrigger = this.page.locator(`[data-testid="card-type-select-${cardIndex}"]`);
  262. await cardTypeTrigger.click();
  263. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  264. await this.page.getByRole('option', { name: bankCard.cardType }).click();
  265. }
  266. // 6. 设置默认银行卡(可选)
  267. if (bankCard.isDefault) {
  268. const defaultSwitch = this.page.locator(`[data-testid="default-card-switch-${cardIndex}"]`);
  269. const isChecked = await defaultSwitch.isChecked();
  270. if (!isChecked) {
  271. await defaultSwitch.click();
  272. }
  273. }
  274. console.log(` ✓ 添加银行卡: ${bankCard.bankName} - ${bankCard.cardNumber}`);
  275. return cardIndex;
  276. }
  277. /**
  278. * 编辑指定索引的银行卡
  279. * @param cardIndex 银行卡索引(从0开始)
  280. * @param updatedData 更新的银行卡数据
  281. */
  282. async editBankCard(cardIndex: number, updatedData: {
  283. bankName?: string;
  284. subBankName?: string;
  285. cardNumber?: string;
  286. cardholderName?: string;
  287. cardType?: string;
  288. isDefault?: boolean;
  289. }) {
  290. console.debug(` 编辑银行卡 ${cardIndex}`);
  291. // 编辑银行名称
  292. if (updatedData.bankName !== undefined) {
  293. const bankSelectTrigger = this.page.locator(`[data-testid="bank-select-${cardIndex}"]`);
  294. await bankSelectTrigger.click();
  295. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  296. await this.page.getByRole('option', { name: updatedData.bankName }).click();
  297. console.debug(` ✓ 更新银行名称: ${updatedData.bankName}`);
  298. }
  299. // 编辑发卡支行
  300. if (updatedData.subBankName !== undefined) {
  301. const subBankInput = this.page.locator(`[data-testid="sub-bank-name-input-${cardIndex}"]`);
  302. await subBankInput.clear();
  303. await subBankInput.fill(updatedData.subBankName);
  304. console.debug(` ✓ 更新发卡支行: ${updatedData.subBankName}`);
  305. }
  306. // 编辑银行卡号
  307. if (updatedData.cardNumber !== undefined) {
  308. const cardNumberInput = this.page.locator(`[data-testid="card-number-input-${cardIndex}"]`);
  309. await cardNumberInput.clear();
  310. await cardNumberInput.fill(updatedData.cardNumber);
  311. console.debug(` ✓ 更新银行卡号: ${updatedData.cardNumber}`);
  312. }
  313. // 编辑持卡人姓名
  314. if (updatedData.cardholderName !== undefined) {
  315. const cardholderInput = this.page.locator(`[data-testid="cardholder-name-input-${cardIndex}"]`);
  316. await cardholderInput.clear();
  317. await cardholderInput.fill(updatedData.cardholderName);
  318. console.debug(` ✓ 更新持卡人姓名: ${updatedData.cardholderName}`);
  319. }
  320. // 编辑银行卡类型
  321. if (updatedData.cardType !== undefined) {
  322. const cardTypeTrigger = this.page.locator(`[data-testid="card-type-select-${cardIndex}"]`);
  323. await cardTypeTrigger.click();
  324. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  325. await this.page.getByRole('option', { name: updatedData.cardType }).click();
  326. console.debug(` ✓ 更新银行卡类型: ${updatedData.cardType}`);
  327. }
  328. // 设置默认银行卡
  329. if (updatedData.isDefault !== undefined) {
  330. const defaultSwitch = this.page.locator(`[data-testid="default-card-switch-${cardIndex}"]`);
  331. const isChecked = await defaultSwitch.isChecked();
  332. if (isChecked !== updatedData.isDefault) {
  333. await defaultSwitch.click();
  334. console.debug(` ✓ 设置默认银行卡: ${updatedData.isDefault}`);
  335. }
  336. }
  337. console.debug(` ✓ 银行卡 ${cardIndex} 编辑完成`);
  338. }
  339. /**
  340. * 删除指定索引的银行卡
  341. * @param cardIndex 银行卡索引(从0开始)
  342. */
  343. async deleteBankCard(cardIndex: number) {
  344. console.debug(` 删除银行卡 ${cardIndex}`);
  345. const removeButton = this.page.locator(`[data-testid="remove-bank-card-${cardIndex}"]`);
  346. await removeButton.click();
  347. await this.page.waitForTimeout(500);
  348. console.debug(` ✓ 银行卡 ${cardIndex} 已删除`);
  349. }
  350. /**
  351. * 获取银行卡列表
  352. * @returns 银行卡号数组
  353. */
  354. async getBankCardList(): Promise<string[]> {
  355. const cards: string[] = [];
  356. const cardCount = await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  357. for (let i = 0; i < cardCount; i++) {
  358. const cardNumberInput = this.page.locator(`[data-testid="card-number-input-${i}"]`);
  359. const cardNumber = await cardNumberInput.inputValue();
  360. cards.push(cardNumber);
  361. }
  362. return cards;
  363. }
  364. /**
  365. * 获取默认银行卡的索引
  366. * @returns 默认银行卡的索引,如果没有则返回 null
  367. */
  368. async getDefaultBankCardIndex(): Promise<number | null> {
  369. const cardCount = await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  370. for (let i = 0; i < cardCount; i++) {
  371. const defaultSwitch = this.page.locator(`[data-testid="default-card-switch-${i}"]`);
  372. const isChecked = await defaultSwitch.isChecked();
  373. if (isChecked) {
  374. return i;
  375. }
  376. }
  377. return null;
  378. }
  379. /**
  380. * 获取当前银行卡数量
  381. * @returns 银行卡数量
  382. */
  383. async getBankCardCount(): Promise<number> {
  384. return await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  385. }
  386. /**
  387. * 检查添加银行卡按钮是否被禁用
  388. * @returns 是否禁用
  389. */
  390. async isAddBankCardButtonDisabled(): Promise<boolean> {
  391. const addButton = this.page.locator('[data-testid="add-bank-card-button"]');
  392. return await addButton.isDisabled();
  393. }
  394. /**
  395. * 添加回访记录
  396. * @param visit 回访信息
  397. */
  398. async addVisit(visit: {
  399. visitDate: string;
  400. visitType: string;
  401. visitContent: string;
  402. visitResult?: string;
  403. nextVisitDate?: string;
  404. }) {
  405. // 点击"添加回访"按钮
  406. const addVisitButton = this.page.getByRole('button', { name: /添加回访/ });
  407. await addVisitButton.click();
  408. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  409. // 填写回访信息
  410. await this.page.getByLabel(/回访日期/).fill(visit.visitDate);
  411. await selectRadixOption(this.page, '回访类型', visit.visitType);
  412. // 查找回访内容输入框(可能有多个,使用最后一个)
  413. const visitContentTextarea = this.page.locator('textarea').filter({ hasText: '' }).last();
  414. await visitContentTextarea.fill(visit.visitContent);
  415. // 填写回访结果(可选)
  416. if (visit.visitResult) {
  417. const resultTextareas = this.page.locator('textarea');
  418. const count = await resultTextareas.count();
  419. if (count > 0) {
  420. await resultTextareas.nth(count - 1).fill(visit.visitResult);
  421. }
  422. }
  423. // 填写下一次回访日期(可选)
  424. if (visit.nextVisitDate) {
  425. const nextDateInput = this.page.getByLabel(/下次回访日期/);
  426. await nextDateInput.fill(visit.nextVisitDate);
  427. }
  428. console.log(` ✓ 添加回访: ${visit.visitType} - ${visit.visitDate}`);
  429. }
  430. /**
  431. * 滚动表单到指定区域
  432. * @param sectionName 区域名称
  433. */
  434. async scrollToSection(sectionName: string) {
  435. const section = this.page.locator(`text=${sectionName}`).first();
  436. await section.scrollIntoViewIfNeeded();
  437. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  438. }
  439. /**
  440. * 等待对话框关闭
  441. */
  442. async waitForDialogClosed() {
  443. const dialog = this.page.locator('[role="dialog"]');
  444. await dialog.waitFor({ state: 'hidden', timeout: 5000 }).catch(() => {});
  445. await this.page.waitForTimeout(500);
  446. }
  447. /**
  448. * 取消对话框
  449. */
  450. async cancelDialog() {
  451. const cancelButton = this.page.getByRole('button', { name: '取消' });
  452. await cancelButton.click();
  453. await this.waitForDialogClosed();
  454. }
  455. /**
  456. * 添加备注(内联表单模式)
  457. * @param content 备注内容
  458. * @param options 选项
  459. */
  460. async addNote(content: string, options?: { isSpecialNeeds?: boolean }): Promise<number> {
  461. // 点击"添加备注"按钮
  462. const addButton = this.page.locator('[data-testid="add-remark-button"]');
  463. await addButton.click();
  464. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  465. // 获取当前备注数量
  466. const noteCount = await this.getNoteCount();
  467. const noteIndex = noteCount > 0 ? noteCount - 1 : 0;
  468. // 填写备注内容
  469. const textarea = this.page.locator(`[data-testid="remark-content-textarea-${noteIndex}"]`);
  470. await textarea.fill(content);
  471. // 标记特殊需求(如果需要)
  472. if (options?.isSpecialNeeds) {
  473. const switchControl = this.page.locator(`[data-testid="special-needs-switch-${noteIndex}"]`);
  474. const isChecked = await switchControl.isChecked();
  475. if (!isChecked) {
  476. await switchControl.click();
  477. }
  478. }
  479. console.debug(` ✓ 添加备注: ${content.substring(0, 30)}...`);
  480. return noteIndex;
  481. }
  482. /**
  483. * 编辑指定索引的备注
  484. * @param index 备注索引(从0开始)
  485. * @param content 更新的备注内容
  486. */
  487. async editNote(index: number, content: string): Promise<void> {
  488. console.debug(` 编辑备注 ${index}`);
  489. const textarea = this.page.locator(`[data-testid="remark-content-textarea-${index}"]`);
  490. await textarea.clear();
  491. await textarea.fill(content);
  492. console.debug(` ✓ 备注 ${index} 编辑完成`);
  493. }
  494. /**
  495. * 删除指定索引的备注
  496. * @param index 备注索引(从0开始)
  497. */
  498. async deleteNote(index: number): Promise<void> {
  499. console.debug(` 删除备注 ${index}`);
  500. const removeButton = this.page.locator(`[data-testid="remove-remark-${index}"]`);
  501. await removeButton.click();
  502. await this.page.waitForTimeout(TIMEOUTS.SHORT);
  503. console.debug(` ✓ 备注 ${index} 已删除`);
  504. }
  505. /**
  506. * 获取备注列表
  507. * @returns 备注内容数组
  508. */
  509. async getNoteList(): Promise<string[]> {
  510. const notes: string[] = [];
  511. const noteCount = await this.page.locator('[data-testid^="remark-content-textarea-"]').count();
  512. for (let i = 0; i < noteCount; i++) {
  513. const textarea = this.page.locator(`[data-testid="remark-content-textarea-${i}"]`);
  514. const content = await textarea.inputValue();
  515. notes.push(content);
  516. }
  517. return notes;
  518. }
  519. /**
  520. * 获取备注数量
  521. * @returns 备注数量
  522. */
  523. async getNoteCount(): Promise<number> {
  524. return await this.page.locator('[data-testid^="remark-content-textarea-"]').count();
  525. }
  526. /**
  527. * 获取指定备注的特殊需求状态
  528. * @param index 备注索引(从0开始)
  529. * @returns 是否标记为特殊需求
  530. */
  531. async getNoteSpecialNeedsStatus(index: number): Promise<boolean> {
  532. const switchControl = this.page.locator(`[data-testid="special-needs-switch-${index}"]`);
  533. return await switchControl.isChecked();
  534. }
  535. /**
  536. * 检查添加备注按钮是否被禁用
  537. * @returns 是否禁用
  538. */
  539. async isAddNoteButtonDisabled(): Promise<boolean> {
  540. const addButton = this.page.locator('[data-testid="add-remark-button"]');
  541. return await addButton.isDisabled();
  542. }
  543. }