order-person.spec.ts 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  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. import type { Page } from '@playwright/test';
  6. const __filename = fileURLToPath(import.meta.url);
  7. const __dirname = dirname(__filename);
  8. const testUsers = JSON.parse(readFileSync(join(__dirname, '../../fixtures/test-users.json'), 'utf-8'));
  9. // 存储 API 创建的测试数据
  10. let createdPersonName: string | null = null;
  11. let createdPlatformName: string | null = null;
  12. let createdCompanyName: string | null = null;
  13. // 获取认证 token
  14. async function getAuthToken(request: Parameters<typeof test>[0]['request']): Promise<string | null> {
  15. const loginResponse = await request.post('http://localhost:8080/api/v1/auth/login', {
  16. data: {
  17. username: testUsers.admin.username,
  18. password: testUsers.admin.password
  19. }
  20. });
  21. if (!loginResponse.ok()) {
  22. console.debug('API 登录失败:', await loginResponse.text());
  23. return null;
  24. }
  25. const loginData = await loginResponse.json();
  26. return loginData.data?.token || loginData.token || null;
  27. }
  28. // API 调用辅助函数 - 使用 API 直接创建残疾人数据
  29. async function createDisabledPersonViaAPI(
  30. request: Parameters<typeof test>[0]['request'],
  31. personData: {
  32. name: string;
  33. gender: string;
  34. idCard: string;
  35. disabilityId: string;
  36. disabilityType: string;
  37. disabilityLevel: string;
  38. idAddress: string;
  39. phone: string;
  40. province: string;
  41. city: string;
  42. }
  43. ): Promise<{ id: number; name: string } | null> {
  44. try {
  45. const token = await getAuthToken(request);
  46. if (!token) return null;
  47. const createResponse = await request.post('http://localhost:8080/api/v1/disability/createDisabledPerson', {
  48. headers: {
  49. 'Authorization': `Bearer ${token}`,
  50. 'Content-Type': 'application/json'
  51. },
  52. data: personData
  53. });
  54. if (!createResponse.ok()) {
  55. const errorText = await createResponse.text();
  56. console.debug('API 创建残疾人失败:', createResponse.status(), errorText);
  57. return null;
  58. }
  59. const result = await createResponse.json();
  60. console.debug('API 创建残疾人成功:', result.name);
  61. return { id: result.id, name: result.name };
  62. } catch (error) {
  63. console.debug('API 调用出错:', error);
  64. return null;
  65. }
  66. }
  67. // 创建测试平台
  68. async function createPlatformViaAPI(
  69. request: Parameters<typeof test>[0]['request']
  70. ): Promise<{ id: number; name: string } | null> {
  71. try {
  72. const token = await getAuthToken(request);
  73. if (!token) return null;
  74. const timestamp = Date.now();
  75. const platformData = {
  76. platformName: `测试平台_${timestamp}`,
  77. contactPerson: '测试联系人',
  78. contactPhone: '13800138000',
  79. contactEmail: 'test@example.com'
  80. };
  81. const createResponse = await request.post('http://localhost:8080/api/v1/platform/createPlatform', {
  82. headers: {
  83. 'Authorization': `Bearer ${token}`,
  84. 'Content-Type': 'application/json'
  85. },
  86. data: platformData
  87. });
  88. if (!createResponse.ok()) {
  89. const errorText = await createResponse.text();
  90. console.debug('API 创建平台失败:', createResponse.status(), errorText);
  91. return null;
  92. }
  93. const result = await createResponse.json();
  94. console.debug('API 创建平台成功:', result.id, result.platformName);
  95. return { id: result.id, name: result.platformName };
  96. } catch (error) {
  97. console.debug('创建平台 API 调用出错:', error);
  98. return null;
  99. }
  100. }
  101. // 创建测试公司
  102. async function createCompanyViaAPI(
  103. request: Parameters<typeof test>[0]['request'],
  104. platformId: number
  105. ): Promise<{ id: number; name: string } | null> {
  106. try {
  107. const token = await getAuthToken(request);
  108. if (!token) return null;
  109. const timestamp = Date.now();
  110. const companyName = `测试公司_${timestamp}`;
  111. const companyData = {
  112. companyName: companyName,
  113. platformId: platformId,
  114. contactPerson: '测试联系人',
  115. contactPhone: '13900139000',
  116. contactEmail: 'company@example.com'
  117. };
  118. const createResponse = await request.post('http://localhost:8080/api/v1/company/createCompany', {
  119. headers: {
  120. 'Authorization': `Bearer ${token}`,
  121. 'Content-Type': 'application/json'
  122. },
  123. data: companyData
  124. });
  125. if (!createResponse.ok()) {
  126. const errorText = await createResponse.text();
  127. console.debug('API 创建公司失败:', createResponse.status(), errorText);
  128. return null;
  129. }
  130. const createResult = await createResponse.json();
  131. if (!createResult.success) {
  132. console.debug('API 创建公司返回 success=false');
  133. return null;
  134. }
  135. // 创建成功后,通过平台ID查询公司列表来获取公司ID
  136. const listResponse = await request.get(`http://localhost:8080/api/v1/company/getCompaniesByPlatform/${platformId}`, {
  137. headers: {
  138. 'Authorization': `Bearer ${token}`
  139. }
  140. });
  141. if (!listResponse.ok()) {
  142. console.debug('API 获取公司列表失败');
  143. return null;
  144. }
  145. const companies = await listResponse.json();
  146. const createdCompany = companies.find((c: any) => c.companyName === companyName);
  147. if (createdCompany) {
  148. console.debug('API 创建公司成功:', createdCompany.id, createdCompany.companyName);
  149. return { id: createdCompany.id, name: createdCompany.companyName };
  150. }
  151. console.debug('未找到创建的公司');
  152. return null;
  153. } catch (error) {
  154. console.debug('创建公司 API 调用出错:', error);
  155. return null;
  156. }
  157. }
  158. async function selectDisabledPersonInAddDialog(
  159. page: Page,
  160. personName?: string
  161. ): Promise<boolean> {
  162. // 监听控制台消息
  163. page.on('console', msg => {
  164. console.log('[浏览器控制台]', msg.text());
  165. });
  166. const selectPersonButton = page.getByRole('button', { name: '选择残疾人' });
  167. await selectPersonButton.click();
  168. // 检查测试标志是否设置
  169. const testFlag = await page.evaluate(() => (window as any).__PLAYWRIGHT_TEST__);
  170. console.log('测试标志 __PLAYWRIGHT_TEST__:', testFlag);
  171. // 使用唯一的 test ID 精确定位残疾人选择对话框
  172. const dialog = page.getByTestId('disabled-person-selector-dialog');
  173. // 测试环境:组件会自动选中第一个残疾人并确认,只需等待对话框关闭
  174. console.log('等待残疾人选择器对话框自动关闭...');
  175. // 等待对话框消失(自动选择后会关闭)
  176. await dialog.waitFor({ state: 'hidden', timeout: 10000 });
  177. console.log('残疾人选择器对话框已关闭');
  178. // 等待一下让状态同步
  179. await page.waitForTimeout(500);
  180. return true;
  181. }
  182. // 全局计数器,确保每个测试生成唯一的数据
  183. let testDataCounter = 0;
  184. function generateUniqueTestData() {
  185. const timestamp = Date.now();
  186. const counter = ++testDataCounter;
  187. const random = Math.floor(Math.random() * 10000);
  188. // 生成18位身份证号:110101(地区码6位) + 19900101(出生日期8位) + XXX(顺序码3位) + X(校验码1位)
  189. // 使用计数器和随机数作为顺序码,确保唯一性
  190. const sequenceCode = String(counter).padStart(2, '0') + String(random).slice(0, 1);
  191. const idCard = '110101' + '19900101' + sequenceCode + '1'; // 6+8+3+1=18位
  192. return {
  193. orderName: '测试订单_' + timestamp + '_' + counter + '_' + random,
  194. personName: '测试残疾人_' + timestamp + '_' + counter + '_' + random,
  195. // 18位身份证号
  196. idCard,
  197. phone: '138' + String(counter).padStart(4, '0') + String(random).padStart(4, '0'),
  198. gender: '男',
  199. disabilityType: '视力残疾',
  200. disabilityLevel: '一级',
  201. disabilityId: '残疾证' + sequenceCode + String(timestamp).slice(-6),
  202. idAddress: '北京市东城区测试地址' + timestamp + '_' + counter,
  203. province: '北京市',
  204. city: '北京市',
  205. hireDate: '2025-01-15',
  206. salary: 5000,
  207. };
  208. }
  209. // 等待订单行出现在表格中
  210. async function waitForOrderRow(page: Page, orderName: string, timeout = 15000) {
  211. const startTime = Date.now();
  212. while (Date.now() - startTime < timeout) {
  213. const table = page.locator('table');
  214. const orderRow = table.locator('tbody tr').filter({ hasText: orderName });
  215. const count = await orderRow.count();
  216. if (count > 0) {
  217. console.debug('找到订单行:', orderName);
  218. return true;
  219. }
  220. await page.waitForTimeout(500);
  221. }
  222. console.debug('等待订单行超时:', orderName);
  223. return false;
  224. }
  225. test.describe('订单人员关联测试', () => {
  226. test.beforeAll(async ({}) => {
  227. // 注意:beforeAll 中无法访问 page,所以通过 playwright.config.ts 的 initScripts 设置
  228. // 这里只是文档说明
  229. });
  230. test.beforeEach(async ({ adminLoginPage, orderManagementPage, request, page }) => {
  231. // 登录
  232. await adminLoginPage.goto();
  233. await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
  234. await adminLoginPage.expectLoginSuccess();
  235. await orderManagementPage.goto();
  236. // 使用 API 创建平台和公司测试数据
  237. const createdPlatform = await createPlatformViaAPI(request);
  238. if (!createdPlatform) {
  239. console.debug('无法创建平台数据,测试可能被跳过');
  240. createdPlatformName = null;
  241. } else {
  242. createdPlatformName = createdPlatform.name;
  243. }
  244. if (createdPlatform) {
  245. const createdCompany = await createCompanyViaAPI(request, createdPlatform.id);
  246. if (!createdCompany) {
  247. console.debug('无法创建公司数据,测试可能被跳过');
  248. createdCompanyName = null;
  249. } else {
  250. createdCompanyName = createdCompany.name;
  251. }
  252. }
  253. // 使用 API 创建残疾人测试数据
  254. const timestamp = Date.now();
  255. const random = Math.floor(Math.random() * 10000);
  256. const personName = `测试残疾人_${timestamp}_${random}`;
  257. const personData = {
  258. name: personName,
  259. gender: '男',
  260. idCard: `110101199001011${String(random).padStart(4, '0')}`,
  261. disabilityId: `CJZ${timestamp}${random}`,
  262. disabilityType: '视力残疾',
  263. disabilityLevel: '一级',
  264. idAddress: '北京市东城区测试地址',
  265. phone: `138${String(random).padStart(8, '0')}`,
  266. province: '北京市',
  267. city: '北京市'
  268. };
  269. const createdPerson = await createDisabledPersonViaAPI(request, personData);
  270. if (!createdPerson) {
  271. console.debug('无法创建残疾人数据,测试可能被跳过');
  272. createdPersonName = null;
  273. } else {
  274. createdPersonName = createdPerson.name;
  275. console.debug('已创建残疾人:', createdPersonName, 'ID:', createdPerson.id);
  276. }
  277. });
  278. test.describe('添加人员到订单', () => {
  279. test('应该能打开订单人员管理对话框', async ({ orderManagementPage }) => {
  280. if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
  281. test.skip(true, '缺少测试数据(残疾人、平台或公司)');
  282. return;
  283. }
  284. const testData = generateUniqueTestData();
  285. await orderManagementPage.openCreateDialog();
  286. await orderManagementPage.page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  287. // 选择平台
  288. const platformTrigger = orderManagementPage.page.locator('[data-testid="platform-selector-create"]');
  289. if (await platformTrigger.count() > 0) {
  290. await platformTrigger.click();
  291. await orderManagementPage.page.waitForTimeout(800);
  292. const allOptions = orderManagementPage.page.getByRole('option');
  293. const count = await allOptions.count();
  294. console.debug(`平台选项数量: ${count}`);
  295. if (count > 0) {
  296. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  297. const optionCount = await platformOption.count();
  298. if (optionCount > 0) {
  299. await platformOption.click();
  300. } else {
  301. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  302. await allOptions.first().click();
  303. }
  304. } else {
  305. console.debug('平台选项列表为空');
  306. }
  307. await orderManagementPage.page.waitForTimeout(200);
  308. } else {
  309. console.debug('平台选择器未找到,跳过平台选择');
  310. }
  311. // 选择公司
  312. const companyTrigger = orderManagementPage.page.locator('[data-testid="company-selector-create"]');
  313. if (await companyTrigger.count() > 0) {
  314. await companyTrigger.click();
  315. await orderManagementPage.page.waitForTimeout(800);
  316. const allCompanyOptions = orderManagementPage.page.getByRole('option');
  317. const companyCount = await allCompanyOptions.count();
  318. console.debug(`公司选项数量: ${companyCount}`);
  319. if (companyCount > 0) {
  320. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  321. const optionCount = await companyOption.count();
  322. if (optionCount > 0) {
  323. await companyOption.click();
  324. } else {
  325. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  326. await allCompanyOptions.first().click();
  327. }
  328. } else {
  329. console.debug('公司选项列表为空');
  330. }
  331. await orderManagementPage.page.waitForTimeout(200);
  332. } else {
  333. console.debug('公司选择器未找到,跳过公司选择');
  334. }
  335. await orderManagementPage.page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  336. const hasPerson = await selectDisabledPersonInAddDialog(orderManagementPage.page, createdPersonName);
  337. if (!hasPerson) {
  338. await orderManagementPage.cancelDialog();
  339. test.skip(true, '没有可用的残疾人数据');
  340. return;
  341. }
  342. // 等待残疾人选择对话框关闭,检查是否显示了已选人员
  343. // 状态更新是异步的,需要等待更长时间
  344. await orderManagementPage.page.waitForTimeout(2000);
  345. // 尝试多种方式定位徽章
  346. const selectedPersonsBadges = orderManagementPage.page.locator('[class*="badge"]').filter({ hasText: createdPersonName });
  347. const badgeCount = await selectedPersonsBadges.count();
  348. console.debug('已选人员徽章数量:', badgeCount);
  349. // 如果徽章数量为 0,尝试检查文本内容
  350. if (badgeCount === 0) {
  351. const allText = await orderManagementPage.page.locator('.w-full.overflow-y-auto').textContent();
  352. console.debug('对话框内容包含姓名:', allText?.includes(createdPersonName));
  353. }
  354. // 检查提交按钮是否存在且可点击
  355. const submitButton = orderManagementPage.page.getByRole('button', { name: /^(创建|更新|保存)$/ });
  356. const submitButtonCount = await submitButton.count();
  357. console.debug('提交按钮数量:', submitButtonCount);
  358. if (submitButtonCount === 0) {
  359. console.debug('提交按钮未找到,尝试查找所有按钮');
  360. const allButtons = orderManagementPage.page.locator('button').all();
  361. console.debug('页面按钮总数:', await orderManagementPage.page.locator('button').count());
  362. }
  363. await orderManagementPage.submitForm();
  364. await orderManagementPage.waitForDialogClosed();
  365. // 检查是否有错误或成功 Toast
  366. await orderManagementPage.page.waitForTimeout(1000);
  367. const errorToast = orderManagementPage.page.locator('[data-sonner-toast][data-type="error"]');
  368. const successToast = orderManagementPage.page.locator('[data-sonner-toast][data-type="success"]');
  369. const hasError = await errorToast.count() > 0;
  370. const hasSuccess = await successToast.count() > 0;
  371. if (hasError) {
  372. const errorMsg = await errorToast.first().textContent();
  373. console.debug('表单提交错误:', errorMsg);
  374. test.skip(true, '订单创建失败: ' + errorMsg);
  375. return;
  376. }
  377. if (!hasSuccess) {
  378. console.debug('没有成功 Toast,订单可能未创建');
  379. } else {
  380. const successMsg = await successToast.first().textContent();
  381. console.debug('订单创建成功:', successMsg);
  382. }
  383. // 等待订单行出现在表格中
  384. const orderFound = await waitForOrderRow(orderManagementPage.page, testData.orderName);
  385. if (!orderFound) {
  386. test.skip(true, '订单未创建成功,无法继续测试');
  387. return;
  388. }
  389. // 第一个测试只验证订单创建成功,人员管理功能在其他测试中验证
  390. // 订单列表中没有"人员"按钮,需要先打开订单详情
  391. });
  392. test('应该能添加残疾人到订单', async ({ orderManagementPage, page }) => {
  393. if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
  394. test.skip(true, '缺少测试数据(残疾人、平台或公司)');
  395. return;
  396. }
  397. const testData = generateUniqueTestData();
  398. await orderManagementPage.openCreateDialog();
  399. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  400. // 选择平台
  401. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  402. if (await platformTrigger.count() > 0) {
  403. await platformTrigger.click();
  404. // 等待选项列表加载,可能需要时间因为新创建的数据需要刷新
  405. await page.waitForTimeout(800);
  406. // 使用更宽松的选择方式 - 先查找所有选项,再筛选
  407. const allOptions = page.getByRole('option');
  408. const count = await allOptions.count();
  409. console.debug(`平台选项数量: ${count}`);
  410. if (count > 0) {
  411. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  412. const optionCount = await platformOption.count();
  413. if (optionCount > 0) {
  414. await platformOption.click();
  415. } else {
  416. // 如果找不到特定平台,选择第一个可用的
  417. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  418. await allOptions.first().click();
  419. }
  420. } else {
  421. console.debug('平台选项列表为空');
  422. }
  423. await page.waitForTimeout(200);
  424. } else {
  425. console.debug('平台选择器未找到,跳过平台选择');
  426. }
  427. // 选择公司
  428. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  429. if (await companyTrigger.count() > 0) {
  430. await companyTrigger.click();
  431. await page.waitForTimeout(800);
  432. const allCompanyOptions = page.getByRole('option');
  433. const companyCount = await allCompanyOptions.count();
  434. console.debug(`公司选项数量: ${companyCount}`);
  435. if (companyCount > 0) {
  436. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  437. const optionCount = await companyOption.count();
  438. if (optionCount > 0) {
  439. await companyOption.click();
  440. } else {
  441. // 如果找不到特定公司,选择第一个可用的
  442. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  443. await allCompanyOptions.first().click();
  444. }
  445. } else {
  446. console.debug('公司选项列表为空');
  447. }
  448. await page.waitForTimeout(200);
  449. } else {
  450. console.debug('公司选择器未找到,跳过公司选择');
  451. }
  452. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  453. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPersonName);
  454. if (!hasPerson) {
  455. await orderManagementPage.cancelDialog();
  456. test.skip(true, '没有可用的残疾人数据');
  457. return;
  458. }
  459. await orderManagementPage.submitForm();
  460. await orderManagementPage.waitForDialogClosed();
  461. await orderManagementPage.openPersonManagementDialog(testData.orderName);
  462. // 使用 first() 因为有两个"添加人员"按钮(卡片中+底部)
  463. const addButton = page.getByRole('button', { name: /添加人员|新增人员/ }).first();
  464. await addButton.click();
  465. await page.waitForTimeout(300);
  466. // 等待残疾人选择对话框打开
  467. const dialog = page.getByTestId('disabled-person-selector-dialog');
  468. await dialog.waitFor({ state: 'visible', timeout: 5000 });
  469. // 等待自动选择完成(通过检查待添加人员数量)
  470. // 使用 test-id 检查待添加人员列表
  471. const pendingPersonsDebug = page.getByTestId('pending-persons-debug');
  472. await pendingPersonsDebug.waitFor({ state: 'attached', timeout: 10000 });
  473. // 检查待添加人员数量
  474. const pendingData = await pendingPersonsDebug.textContent();
  475. console.log('待添加人员数据:', pendingData);
  476. // 关闭残疾人选择对话框
  477. await page.keyboard.press('Escape');
  478. await dialog.waitFor({ state: 'hidden', timeout: 5000 });
  479. // 点击"确认添加"按钮批量添加人员
  480. const confirmButton = page.getByTestId('confirm-add-persons-button');
  481. await confirmButton.click();
  482. // 等待成功 toast
  483. await page.waitForTimeout(1000);
  484. const successToast = page.locator('[data-sonner-toast][data-type="success"]');
  485. const hasSuccess = await successToast.count() > 0;
  486. expect(hasSuccess).toBe(true);
  487. await orderManagementPage.closeDetailDialog();
  488. });
  489. test('添加的人员应该出现在订单详情中', async ({ orderManagementPage, page }) => {
  490. if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
  491. test.skip(true, '缺少测试数据(残疾人、平台或公司)');
  492. return;
  493. }
  494. const testData = generateUniqueTestData();
  495. await orderManagementPage.openCreateDialog();
  496. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  497. // 选择平台
  498. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  499. if (await platformTrigger.count() > 0) {
  500. await platformTrigger.click();
  501. // 等待选项列表加载,可能需要时间因为新创建的数据需要刷新
  502. await page.waitForTimeout(800);
  503. // 使用更宽松的选择方式 - 先查找所有选项,再筛选
  504. const allOptions = page.getByRole('option');
  505. const count = await allOptions.count();
  506. console.debug(`平台选项数量: ${count}`);
  507. if (count > 0) {
  508. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  509. const optionCount = await platformOption.count();
  510. if (optionCount > 0) {
  511. await platformOption.click();
  512. } else {
  513. // 如果找不到特定平台,选择第一个可用的
  514. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  515. await allOptions.first().click();
  516. }
  517. } else {
  518. console.debug('平台选项列表为空');
  519. }
  520. await page.waitForTimeout(200);
  521. } else {
  522. console.debug('平台选择器未找到,跳过平台选择');
  523. }
  524. // 选择公司
  525. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  526. if (await companyTrigger.count() > 0) {
  527. await companyTrigger.click();
  528. await page.waitForTimeout(800);
  529. const allCompanyOptions = page.getByRole('option');
  530. const companyCount = await allCompanyOptions.count();
  531. console.debug(`公司选项数量: ${companyCount}`);
  532. if (companyCount > 0) {
  533. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  534. const optionCount = await companyOption.count();
  535. if (optionCount > 0) {
  536. await companyOption.click();
  537. } else {
  538. // 如果找不到特定公司,选择第一个可用的
  539. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  540. await allCompanyOptions.first().click();
  541. }
  542. } else {
  543. console.debug('公司选项列表为空');
  544. }
  545. await page.waitForTimeout(200);
  546. } else {
  547. console.debug('公司选择器未找到,跳过公司选择');
  548. }
  549. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  550. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPersonName);
  551. if (!hasPerson) {
  552. await orderManagementPage.cancelDialog();
  553. test.skip(true, '没有可用的残疾人数据');
  554. return;
  555. }
  556. await orderManagementPage.submitForm();
  557. await orderManagementPage.waitForDialogClosed();
  558. await orderManagementPage.openDetailDialog(testData.orderName);
  559. const personList = await orderManagementPage.getPersonListFromDetail();
  560. expect(personList.length).toBeGreaterThan(0);
  561. await orderManagementPage.closeDetailDialog();
  562. });
  563. });
  564. test.describe('管理工作状态', () => {
  565. test('应该能修改人员工作状态:未就业 → 待就业', async ({ orderManagementPage, page, request }) => {
  566. if (!createdPlatformName || !createdCompanyName) {
  567. test.skip(true, '缺少测试数据(平台或公司)');
  568. return;
  569. }
  570. // 为此测试创建唯一的残疾人数据
  571. const testData = generateUniqueTestData();
  572. const personData = {
  573. name: testData.personName,
  574. gender: testData.gender,
  575. idCard: testData.idCard,
  576. disabilityId: testData.disabilityId,
  577. disabilityType: testData.disabilityType,
  578. disabilityLevel: testData.disabilityLevel,
  579. idAddress: testData.idAddress,
  580. phone: testData.phone,
  581. province: testData.province,
  582. city: testData.city,
  583. };
  584. const createdPerson = await createDisabledPersonViaAPI(request, personData);
  585. if (!createdPerson) {
  586. test.skip(true, '无法创建残疾人数据');
  587. return;
  588. }
  589. console.debug('已创建残疾人:', createdPerson.name, 'ID:', createdPerson.id);
  590. await orderManagementPage.openCreateDialog();
  591. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  592. // 选择平台
  593. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  594. if (await platformTrigger.count() > 0) {
  595. await platformTrigger.click();
  596. // 等待选项列表加载,可能需要时间因为新创建的数据需要刷新
  597. await page.waitForTimeout(800);
  598. // 使用更宽松的选择方式 - 先查找所有选项,再筛选
  599. const allOptions = page.getByRole('option');
  600. const count = await allOptions.count();
  601. console.debug(`平台选项数量: ${count}`);
  602. if (count > 0) {
  603. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  604. const optionCount = await platformOption.count();
  605. if (optionCount > 0) {
  606. await platformOption.click();
  607. } else {
  608. // 如果找不到特定平台,选择第一个可用的
  609. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  610. await allOptions.first().click();
  611. }
  612. } else {
  613. console.debug('平台选项列表为空');
  614. }
  615. await page.waitForTimeout(200);
  616. } else {
  617. console.debug('平台选择器未找到,跳过平台选择');
  618. }
  619. // 选择公司
  620. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  621. if (await companyTrigger.count() > 0) {
  622. await companyTrigger.click();
  623. await page.waitForTimeout(800);
  624. const allCompanyOptions = page.getByRole('option');
  625. const companyCount = await allCompanyOptions.count();
  626. console.debug(`公司选项数量: ${companyCount}`);
  627. if (companyCount > 0) {
  628. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  629. const optionCount = await companyOption.count();
  630. if (optionCount > 0) {
  631. await companyOption.click();
  632. } else {
  633. // 如果找不到特定公司,选择第一个可用的
  634. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  635. await allCompanyOptions.first().click();
  636. }
  637. } else {
  638. console.debug('公司选项列表为空');
  639. }
  640. await page.waitForTimeout(200);
  641. } else {
  642. console.debug('公司选择器未找到,跳过公司选择');
  643. }
  644. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  645. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPerson.name);
  646. if (!hasPerson) {
  647. await orderManagementPage.cancelDialog();
  648. test.skip(true, '没有可用的残疾人数据');
  649. return;
  650. }
  651. await orderManagementPage.submitForm();
  652. await orderManagementPage.waitForDialogClosed();
  653. await orderManagementPage.openPersonManagementDialog(testData.orderName);
  654. // 等待订单详情对话框加载完成
  655. await page.waitForTimeout(500);
  656. // 监听网络响应以捕获 400 错误的详细信息
  657. const apiResponses: any[] = [];
  658. page.on('response', async (response) => {
  659. if (response.status() === 400) {
  660. const url = response.url();
  661. const contentType = response.headers()['content-type'];
  662. if (contentType && contentType.includes('application/json')) {
  663. try {
  664. const body = await response.json();
  665. apiResponses.push({ url, status: response.status(), body });
  666. console.debug('API 400 错误详情:', JSON.stringify(body, null, 2));
  667. } catch (e) {
  668. const text = await response.text();
  669. apiResponses.push({ url, status: response.status(), body: text });
  670. console.debug('API 400 错误详情:', text);
  671. }
  672. }
  673. }
  674. });
  675. // 获取实际绑定的人员列表,使用第一个人员的名称
  676. const personList = await orderManagementPage.getPersonListFromDetail();
  677. await orderManagementPage.updatePersonWorkStatus(personList[0].name, 'pre_working');
  678. // 如果有 400 错误,打印详细信息
  679. if (apiResponses.length > 0) {
  680. console.debug('捕获到的 API 错误:', JSON.stringify(apiResponses, null, 2));
  681. }
  682. const successToast = page.locator('[data-sonner-toast][data-type="success"]');
  683. const hasSuccess = await successToast.count() > 0;
  684. expect(hasSuccess).toBe(true);
  685. await orderManagementPage.closeDetailDialog();
  686. });
  687. test('应该能修改人员工作状态:待就业 → 已就业', async ({ orderManagementPage, page, request }) => {
  688. if (!createdPlatformName || !createdCompanyName) {
  689. test.skip(true, '缺少测试数据(平台或公司)');
  690. return;
  691. }
  692. // 为此测试创建唯一的残疾人数据
  693. const testData = generateUniqueTestData();
  694. const personData = {
  695. name: testData.personName,
  696. gender: testData.gender,
  697. idCard: testData.idCard,
  698. disabilityId: testData.disabilityId,
  699. disabilityType: testData.disabilityType,
  700. disabilityLevel: testData.disabilityLevel,
  701. idAddress: testData.idAddress,
  702. phone: testData.phone,
  703. province: testData.province,
  704. city: testData.city,
  705. };
  706. const createdPerson = await createDisabledPersonViaAPI(request, personData);
  707. if (!createdPerson) {
  708. test.skip(true, '无法创建残疾人数据');
  709. return;
  710. }
  711. console.debug('已创建残疾人:', createdPerson.name, 'ID:', createdPerson.id);
  712. await orderManagementPage.openCreateDialog();
  713. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  714. // 选择平台
  715. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  716. if (await platformTrigger.count() > 0) {
  717. await platformTrigger.click();
  718. // 等待选项列表加载,可能需要时间因为新创建的数据需要刷新
  719. await page.waitForTimeout(800);
  720. // 使用更宽松的选择方式 - 先查找所有选项,再筛选
  721. const allOptions = page.getByRole('option');
  722. const count = await allOptions.count();
  723. console.debug(`平台选项数量: ${count}`);
  724. if (count > 0) {
  725. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  726. const optionCount = await platformOption.count();
  727. if (optionCount > 0) {
  728. await platformOption.click();
  729. } else {
  730. // 如果找不到特定平台,选择第一个可用的
  731. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  732. await allOptions.first().click();
  733. }
  734. } else {
  735. console.debug('平台选项列表为空');
  736. }
  737. await page.waitForTimeout(200);
  738. } else {
  739. console.debug('平台选择器未找到,跳过平台选择');
  740. }
  741. // 选择公司
  742. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  743. if (await companyTrigger.count() > 0) {
  744. await companyTrigger.click();
  745. await page.waitForTimeout(800);
  746. const allCompanyOptions = page.getByRole('option');
  747. const companyCount = await allCompanyOptions.count();
  748. console.debug(`公司选项数量: ${companyCount}`);
  749. if (companyCount > 0) {
  750. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  751. const optionCount = await companyOption.count();
  752. if (optionCount > 0) {
  753. await companyOption.click();
  754. } else {
  755. // 如果找不到特定公司,选择第一个可用的
  756. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  757. await allCompanyOptions.first().click();
  758. }
  759. } else {
  760. console.debug('公司选项列表为空');
  761. }
  762. await page.waitForTimeout(200);
  763. } else {
  764. console.debug('公司选择器未找到,跳过公司选择');
  765. }
  766. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  767. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPerson.name);
  768. if (!hasPerson) {
  769. await orderManagementPage.cancelDialog();
  770. test.skip(true, '没有可用的残疾人数据');
  771. return;
  772. }
  773. await orderManagementPage.submitForm();
  774. await orderManagementPage.waitForDialogClosed();
  775. await orderManagementPage.openPersonManagementDialog(testData.orderName);
  776. const personList = await orderManagementPage.getPersonListFromDetail();
  777. await orderManagementPage.updatePersonWorkStatus(personList[0].name, 'working');
  778. const successToast = page.locator('[data-sonner-toast][data-type="success"]');
  779. const hasSuccess = await successToast.count() > 0;
  780. expect(hasSuccess).toBe(true);
  781. await orderManagementPage.closeDetailDialog();
  782. });
  783. test('应该能修改人员工作状态:已就业 → 已离职', async ({ orderManagementPage, page, request }) => {
  784. if (!createdPlatformName || !createdCompanyName) {
  785. test.skip(true, '缺少测试数据(平台或公司)');
  786. return;
  787. }
  788. // 为此测试创建唯一的残疾人数据
  789. const testData = generateUniqueTestData();
  790. const personData = {
  791. name: testData.personName,
  792. gender: testData.gender,
  793. idCard: testData.idCard,
  794. disabilityId: testData.disabilityId,
  795. disabilityType: testData.disabilityType,
  796. disabilityLevel: testData.disabilityLevel,
  797. idAddress: testData.idAddress,
  798. phone: testData.phone,
  799. province: testData.province,
  800. city: testData.city,
  801. };
  802. const createdPerson = await createDisabledPersonViaAPI(request, personData);
  803. if (!createdPerson) {
  804. test.skip(true, '无法创建残疾人数据');
  805. return;
  806. }
  807. console.debug('已创建残疾人:', createdPerson.name, 'ID:', createdPerson.id);
  808. await orderManagementPage.openCreateDialog();
  809. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  810. // 选择平台
  811. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  812. if (await platformTrigger.count() > 0) {
  813. await platformTrigger.click();
  814. // 等待选项列表加载,可能需要时间因为新创建的数据需要刷新
  815. await page.waitForTimeout(800);
  816. // 使用更宽松的选择方式 - 先查找所有选项,再筛选
  817. const allOptions = page.getByRole('option');
  818. const count = await allOptions.count();
  819. console.debug(`平台选项数量: ${count}`);
  820. if (count > 0) {
  821. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  822. const optionCount = await platformOption.count();
  823. if (optionCount > 0) {
  824. await platformOption.click();
  825. } else {
  826. // 如果找不到特定平台,选择第一个可用的
  827. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  828. await allOptions.first().click();
  829. }
  830. } else {
  831. console.debug('平台选项列表为空');
  832. }
  833. await page.waitForTimeout(200);
  834. } else {
  835. console.debug('平台选择器未找到,跳过平台选择');
  836. }
  837. // 选择公司
  838. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  839. if (await companyTrigger.count() > 0) {
  840. await companyTrigger.click();
  841. await page.waitForTimeout(800);
  842. const allCompanyOptions = page.getByRole('option');
  843. const companyCount = await allCompanyOptions.count();
  844. console.debug(`公司选项数量: ${companyCount}`);
  845. if (companyCount > 0) {
  846. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  847. const optionCount = await companyOption.count();
  848. if (optionCount > 0) {
  849. await companyOption.click();
  850. } else {
  851. // 如果找不到特定公司,选择第一个可用的
  852. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  853. await allCompanyOptions.first().click();
  854. }
  855. } else {
  856. console.debug('公司选项列表为空');
  857. }
  858. await page.waitForTimeout(200);
  859. } else {
  860. console.debug('公司选择器未找到,跳过公司选择');
  861. }
  862. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  863. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPerson.name);
  864. if (!hasPerson) {
  865. await orderManagementPage.cancelDialog();
  866. test.skip(true, '没有可用的残疾人数据');
  867. return;
  868. }
  869. await orderManagementPage.submitForm();
  870. await orderManagementPage.waitForDialogClosed();
  871. await orderManagementPage.openPersonManagementDialog(testData.orderName);
  872. const personList = await orderManagementPage.getPersonListFromDetail();
  873. await orderManagementPage.updatePersonWorkStatus(personList[0].name, 'resigned');
  874. const successToast = page.locator('[data-sonner-toast][data-type="success"]');
  875. const hasSuccess = await successToast.count() > 0;
  876. expect(hasSuccess).toBe(true);
  877. await orderManagementPage.closeDetailDialog();
  878. });
  879. });
  880. test.describe('设置实际入职日期', () => {
  881. test('应该能设置人员的实际入职日期', async ({ orderManagementPage, page }) => {
  882. if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
  883. test.skip(true, '缺少测试数据(残疾人、平台或公司)');
  884. return;
  885. }
  886. const testData = generateUniqueTestData();
  887. const actualHireDate = '2025-02-01';
  888. await orderManagementPage.openCreateDialog();
  889. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  890. // 选择平台
  891. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  892. if (await platformTrigger.count() > 0) {
  893. await platformTrigger.click();
  894. // 等待选项列表加载,可能需要时间因为新创建的数据需要刷新
  895. await page.waitForTimeout(800);
  896. // 使用更宽松的选择方式 - 先查找所有选项,再筛选
  897. const allOptions = page.getByRole('option');
  898. const count = await allOptions.count();
  899. console.debug(`平台选项数量: ${count}`);
  900. if (count > 0) {
  901. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  902. const optionCount = await platformOption.count();
  903. if (optionCount > 0) {
  904. await platformOption.click();
  905. } else {
  906. // 如果找不到特定平台,选择第一个可用的
  907. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  908. await allOptions.first().click();
  909. }
  910. } else {
  911. console.debug('平台选项列表为空');
  912. }
  913. await page.waitForTimeout(200);
  914. } else {
  915. console.debug('平台选择器未找到,跳过平台选择');
  916. }
  917. // 选择公司
  918. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  919. if (await companyTrigger.count() > 0) {
  920. await companyTrigger.click();
  921. await page.waitForTimeout(800);
  922. const allCompanyOptions = page.getByRole('option');
  923. const companyCount = await allCompanyOptions.count();
  924. console.debug(`公司选项数量: ${companyCount}`);
  925. if (companyCount > 0) {
  926. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  927. const optionCount = await companyOption.count();
  928. if (optionCount > 0) {
  929. await companyOption.click();
  930. } else {
  931. // 如果找不到特定公司,选择第一个可用的
  932. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  933. await allCompanyOptions.first().click();
  934. }
  935. } else {
  936. console.debug('公司选项列表为空');
  937. }
  938. await page.waitForTimeout(200);
  939. } else {
  940. console.debug('公司选择器未找到,跳过公司选择');
  941. }
  942. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  943. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPersonName);
  944. if (!hasPerson) {
  945. await orderManagementPage.cancelDialog();
  946. test.skip(true, '没有可用的残疾人数据');
  947. return;
  948. }
  949. await orderManagementPage.submitForm();
  950. await orderManagementPage.waitForDialogClosed();
  951. await orderManagementPage.openPersonManagementDialog(testData.orderName);
  952. const personList = await orderManagementPage.getPersonListFromDetail();
  953. const personRow = page.locator('[role="dialog"]').locator('table tbody tr').filter({ hasText: personList[0].name }).first();
  954. const editButton = personRow.getByRole('button', { name: /编辑|修改/ });
  955. await editButton.click();
  956. await page.waitForTimeout(300);
  957. const actualHireDateInput = page.getByLabel(/实际入职日期/);
  958. await actualHireDateInput.fill(actualHireDate);
  959. const submitButton = page.getByRole('button', { name: /^(更新|保存|确定)$/ });
  960. await submitButton.click();
  961. await page.waitForLoadState('domcontentloaded')
  962. .catch(() => console.debug('domcontentloaded 超时,继续检查 Toast 消息'));
  963. await page.waitForTimeout(1000);
  964. const successToast = page.locator('[data-sonner-toast][data-type="success"]');
  965. const hasSuccess = await successToast.count() > 0;
  966. expect(hasSuccess).toBe(true);
  967. await orderManagementPage.closeDetailDialog();
  968. });
  969. });
  970. test.describe('人员离职', () => {
  971. test('应该能设置人员为已离职状态并设置离职日期', async ({ orderManagementPage, page }) => {
  972. if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
  973. test.skip(true, '缺少测试数据(残疾人、平台或公司)');
  974. return;
  975. }
  976. const testData = generateUniqueTestData();
  977. const resignDate = '2025-03-15';
  978. await orderManagementPage.openCreateDialog();
  979. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  980. // 选择平台
  981. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  982. if (await platformTrigger.count() > 0) {
  983. await platformTrigger.click();
  984. // 等待选项列表加载,可能需要时间因为新创建的数据需要刷新
  985. await page.waitForTimeout(800);
  986. // 使用更宽松的选择方式 - 先查找所有选项,再筛选
  987. const allOptions = page.getByRole('option');
  988. const count = await allOptions.count();
  989. console.debug(`平台选项数量: ${count}`);
  990. if (count > 0) {
  991. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  992. const optionCount = await platformOption.count();
  993. if (optionCount > 0) {
  994. await platformOption.click();
  995. } else {
  996. // 如果找不到特定平台,选择第一个可用的
  997. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  998. await allOptions.first().click();
  999. }
  1000. } else {
  1001. console.debug('平台选项列表为空');
  1002. }
  1003. await page.waitForTimeout(200);
  1004. } else {
  1005. console.debug('平台选择器未找到,跳过平台选择');
  1006. }
  1007. // 选择公司
  1008. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  1009. if (await companyTrigger.count() > 0) {
  1010. await companyTrigger.click();
  1011. await page.waitForTimeout(800);
  1012. const allCompanyOptions = page.getByRole('option');
  1013. const companyCount = await allCompanyOptions.count();
  1014. console.debug(`公司选项数量: ${companyCount}`);
  1015. if (companyCount > 0) {
  1016. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  1017. const optionCount = await companyOption.count();
  1018. if (optionCount > 0) {
  1019. await companyOption.click();
  1020. } else {
  1021. // 如果找不到特定公司,选择第一个可用的
  1022. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  1023. await allCompanyOptions.first().click();
  1024. }
  1025. } else {
  1026. console.debug('公司选项列表为空');
  1027. }
  1028. await page.waitForTimeout(200);
  1029. } else {
  1030. console.debug('公司选择器未找到,跳过公司选择');
  1031. }
  1032. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  1033. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPersonName);
  1034. if (!hasPerson) {
  1035. await orderManagementPage.cancelDialog();
  1036. test.skip(true, '没有可用的残疾人数据');
  1037. return;
  1038. }
  1039. await orderManagementPage.submitForm();
  1040. await orderManagementPage.waitForDialogClosed();
  1041. await orderManagementPage.openPersonManagementDialog(testData.orderName);
  1042. const personList = await orderManagementPage.getPersonListFromDetail();
  1043. const personRow = page.locator('[role="dialog"]').locator('table tbody tr').filter({ hasText: personList[0].name }).first();
  1044. const editButton = personRow.getByRole('button', { name: /编辑|修改/ });
  1045. await editButton.click();
  1046. await page.waitForTimeout(300);
  1047. await page.getByLabel(/工作状态/).click();
  1048. await page.getByRole('option', { name: '已离职' }).click();
  1049. const resignDateInput = page.getByLabel(/离职日期/);
  1050. await resignDateInput.fill(resignDate);
  1051. const submitButton = page.getByRole('button', { name: /^(更新|保存|确定)$/ });
  1052. await submitButton.click();
  1053. await page.waitForLoadState('domcontentloaded')
  1054. .catch(() => console.debug('domcontentloaded 超时,继续检查 Toast 消息'));
  1055. await page.waitForTimeout(1000);
  1056. const successToast = page.locator('[data-sonner-toast][data-type="success"]');
  1057. const hasSuccess = await successToast.count() > 0;
  1058. expect(hasSuccess).toBe(true);
  1059. await orderManagementPage.closeDetailDialog();
  1060. });
  1061. test('离职后人员状态应显示为已离职', async ({ orderManagementPage, page }) => {
  1062. if (!createdPersonName || !createdPlatformName || !createdCompanyName) {
  1063. test.skip(true, '缺少测试数据(残疾人、平台或公司)');
  1064. return;
  1065. }
  1066. const testData = generateUniqueTestData();
  1067. await orderManagementPage.openCreateDialog();
  1068. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  1069. // 选择平台
  1070. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  1071. if (await platformTrigger.count() > 0) {
  1072. await platformTrigger.click();
  1073. // 等待选项列表加载,可能需要时间因为新创建的数据需要刷新
  1074. await page.waitForTimeout(800);
  1075. // 使用更宽松的选择方式 - 先查找所有选项,再筛选
  1076. const allOptions = page.getByRole('option');
  1077. const count = await allOptions.count();
  1078. console.debug(`平台选项数量: ${count}`);
  1079. if (count > 0) {
  1080. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  1081. const optionCount = await platformOption.count();
  1082. if (optionCount > 0) {
  1083. await platformOption.click();
  1084. } else {
  1085. // 如果找不到特定平台,选择第一个可用的
  1086. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  1087. await allOptions.first().click();
  1088. }
  1089. } else {
  1090. console.debug('平台选项列表为空');
  1091. }
  1092. await page.waitForTimeout(200);
  1093. } else {
  1094. console.debug('平台选择器未找到,跳过平台选择');
  1095. }
  1096. // 选择公司
  1097. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  1098. if (await companyTrigger.count() > 0) {
  1099. await companyTrigger.click();
  1100. await page.waitForTimeout(800);
  1101. const allCompanyOptions = page.getByRole('option');
  1102. const companyCount = await allCompanyOptions.count();
  1103. console.debug(`公司选项数量: ${companyCount}`);
  1104. if (companyCount > 0) {
  1105. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  1106. const optionCount = await companyOption.count();
  1107. if (optionCount > 0) {
  1108. await companyOption.click();
  1109. } else {
  1110. // 如果找不到特定公司,选择第一个可用的
  1111. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  1112. await allCompanyOptions.first().click();
  1113. }
  1114. } else {
  1115. console.debug('公司选项列表为空');
  1116. }
  1117. await page.waitForTimeout(200);
  1118. } else {
  1119. console.debug('公司选择器未找到,跳过公司选择');
  1120. }
  1121. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  1122. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPersonName);
  1123. if (!hasPerson) {
  1124. await orderManagementPage.cancelDialog();
  1125. test.skip(true, '没有可用的残疾人数据');
  1126. return;
  1127. }
  1128. await orderManagementPage.submitForm();
  1129. await orderManagementPage.waitForDialogClosed();
  1130. await orderManagementPage.openPersonManagementDialog(testData.orderName);
  1131. const personList = await orderManagementPage.getPersonListFromDetail();
  1132. const personRow = page.locator('[role="dialog"]').locator('table tbody tr').filter({ hasText: personList[0].name }).first();
  1133. const editButton = personRow.getByRole('button', { name: /编辑|修改/ });
  1134. await editButton.click();
  1135. await page.waitForTimeout(300);
  1136. await page.getByLabel(/工作状态/).click();
  1137. await page.getByRole('option', { name: '已离职' }).click();
  1138. const submitButton = page.getByRole('button', { name: /^(更新|保存|确定)$/ });
  1139. await submitButton.click();
  1140. await page.waitForLoadState('domcontentloaded')
  1141. .catch(() => console.debug('domcontentloaded 超时,继续检查 Toast 消息'));
  1142. await page.waitForTimeout(1000);
  1143. const updatedPersonList = await orderManagementPage.getPersonListFromDetail();
  1144. const resignedPerson = updatedPersonList.find(p => p.name === personList[0].name);
  1145. expect(resignedPerson).toBeDefined();
  1146. expect(resignedPerson?.workStatus).toBe('已离职');
  1147. await orderManagementPage.closeDetailDialog();
  1148. });
  1149. });
  1150. });