2
0

order-complete.spec.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. import { TIMEOUTS } from '../../utils/timeouts';
  2. import { test, expect } from '../../utils/test-setup';
  3. import { readFileSync } from 'fs';
  4. import { join, dirname } from 'path';
  5. import { fileURLToPath } from 'url';
  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. // 获取认证 token
  10. async function getAuthToken(request: Parameters<typeof test>[0]['request']): Promise<string | null> {
  11. const loginResponse = await request.post('http://localhost:8080/api/v1/auth/login', {
  12. data: {
  13. username: testUsers.admin.username,
  14. password: testUsers.admin.password
  15. }
  16. });
  17. if (!loginResponse.ok()) {
  18. console.debug('API 登录失败:', await loginResponse.text());
  19. return null;
  20. }
  21. const loginData = await loginResponse.json();
  22. return loginData.data?.token || loginData.token || null;
  23. }
  24. // API 调用辅助函数 - 使用 API 直接创建残疾人数据
  25. async function createDisabledPersonViaAPI(
  26. request: Parameters<typeof test>[0]['request'],
  27. personData: {
  28. name: string;
  29. gender: string;
  30. idCard: string;
  31. disabilityId: string;
  32. disabilityType: string;
  33. disabilityLevel: string;
  34. idAddress: string;
  35. phone: string;
  36. province: string;
  37. city: string;
  38. }
  39. ): Promise<{ id: number; name: string } | null> {
  40. try {
  41. const token = await getAuthToken(request);
  42. if (!token) return null;
  43. const createResponse = await request.post('http://localhost:8080/api/v1/disability/createDisabledPerson', {
  44. headers: {
  45. 'Authorization': `Bearer ${token}`,
  46. 'Content-Type': 'application/json'
  47. },
  48. data: personData
  49. });
  50. if (!createResponse.ok()) {
  51. const errorText = await createResponse.text();
  52. console.debug('API 创建残疾人失败:', createResponse.status(), errorText);
  53. return null;
  54. }
  55. const result = await createResponse.json();
  56. console.debug('API 创建残疾人成功:', result.name);
  57. return { id: result.id, name: result.name };
  58. } catch (error) {
  59. console.debug('API 调用出错:', error);
  60. return null;
  61. }
  62. }
  63. // 创建测试平台
  64. async function createPlatformViaAPI(
  65. request: Parameters<typeof test>[0]['request']
  66. ): Promise<{ id: number; name: string } | null> {
  67. try {
  68. const token = await getAuthToken(request);
  69. if (!token) return null;
  70. const timestamp = Date.now();
  71. const platformData = {
  72. platformName: `测试平台_${timestamp}`,
  73. contactPerson: '测试联系人',
  74. contactPhone: '13800138000',
  75. contactEmail: 'test@example.com'
  76. };
  77. const createResponse = await request.post('http://localhost:8080/api/v1/platform/createPlatform', {
  78. headers: {
  79. 'Authorization': `Bearer ${token}`,
  80. 'Content-Type': 'application/json'
  81. },
  82. data: platformData
  83. });
  84. if (!createResponse.ok()) {
  85. const errorText = await createResponse.text();
  86. console.debug('API 创建平台失败:', createResponse.status(), errorText);
  87. return null;
  88. }
  89. const result = await createResponse.json();
  90. console.debug('API 创建平台成功:', result.id, result.platformName);
  91. return { id: result.id, name: result.platformName };
  92. } catch (error) {
  93. console.debug('创建平台 API 调用出错:', error);
  94. return null;
  95. }
  96. }
  97. // 创建测试公司
  98. async function createCompanyViaAPI(
  99. request: Parameters<typeof test>[0]['request'],
  100. platformId: number
  101. ): Promise<{ id: number; name: string } | null> {
  102. try {
  103. const token = await getAuthToken(request);
  104. if (!token) return null;
  105. const timestamp = Date.now();
  106. const companyName = `测试公司_${timestamp}`;
  107. const companyData = {
  108. companyName: companyName,
  109. platformId: platformId,
  110. contactPerson: '测试联系人',
  111. contactPhone: '13900139000',
  112. contactEmail: 'company@example.com'
  113. };
  114. const createResponse = await request.post('http://localhost:8080/api/v1/company/createCompany', {
  115. headers: {
  116. 'Authorization': `Bearer ${token}`,
  117. 'Content-Type': 'application/json'
  118. },
  119. data: companyData
  120. });
  121. if (!createResponse.ok()) {
  122. const errorText = await createResponse.text();
  123. console.debug('API 创建公司失败:', createResponse.status(), errorText);
  124. return null;
  125. }
  126. const createResult = await createResponse.json();
  127. if (!createResult.success) {
  128. console.debug('API 创建公司返回 success=false');
  129. return null;
  130. }
  131. // 创建成功后,通过平台ID查询公司列表来获取公司ID
  132. const listResponse = await request.get(`http://localhost:8080/api/v1/company/getCompaniesByPlatform/${platformId}`, {
  133. headers: {
  134. 'Authorization': `Bearer ${token}`
  135. }
  136. });
  137. if (!listResponse.ok()) {
  138. console.debug('API 获取公司列表失败');
  139. return null;
  140. }
  141. const companies = await listResponse.json();
  142. const createdCompany = companies.find((c: { companyName: string }) => c.companyName === companyName);
  143. if (createdCompany) {
  144. console.debug('API 创建公司成功:', createdCompany.id, createdCompany.companyName);
  145. return { id: createdCompany.id, name: createdCompany.companyName };
  146. }
  147. console.debug('未找到创建的公司');
  148. return null;
  149. } catch (error) {
  150. console.debug('创建公司 API 调用出错:', error);
  151. return null;
  152. }
  153. }
  154. async function selectDisabledPersonInAddDialog(
  155. page: Parameters<typeof test>[0]['page'],
  156. personName?: string
  157. ): Promise<boolean> {
  158. const selectPersonButton = page.getByRole('button', { name: '选择残疾人' });
  159. await selectPersonButton.click();
  160. // 使用唯一的 test ID 精确定位残疾人选择对话框
  161. const dialog = page.getByTestId('disabled-person-selector-dialog');
  162. if (personName) {
  163. // 查找包含指定姓名的残疾人行
  164. console.debug('选择残疾人:', personName);
  165. const personRow = dialog.locator('tbody tr').filter({ hasText: personName });
  166. const rowCount = await personRow.count();
  167. if (rowCount === 0) {
  168. console.debug('未找到残疾人:', personName);
  169. // 关闭对话框
  170. const cancelButton = dialog.getByRole('button', { name: '取消' }).first();
  171. await cancelButton.click().catch(() => {});
  172. return false;
  173. }
  174. // 点击该行的复选框
  175. const checkbox = personRow.locator('input[type="checkbox"]').first();
  176. await checkbox.check();
  177. console.debug('已选择残疾人:', personName);
  178. } else {
  179. // 测试环境:如果未指定姓名,组件会自动选中第一个残疾人
  180. console.debug('未指定残疾人姓名,等待自动选择第一个残疾人...');
  181. }
  182. // 点击确认按钮
  183. const confirmButton = dialog.getByRole('button', { name: /^(确认|确定)$/ });
  184. const buttonCount = await confirmButton.count();
  185. if (buttonCount > 0) {
  186. await confirmButton.first().click();
  187. console.debug('已点击确认按钮');
  188. }
  189. // 等待对话框关闭
  190. await dialog.waitFor({ state: 'hidden', timeout: TIMEOUTS.TABLE_LOAD });
  191. console.debug('残疾人选择器对话框已关闭');
  192. // 等待一下让状态同步
  193. await page.waitForTimeout(TIMEOUTS.MEDIUM);
  194. return true;
  195. }
  196. // 全局计数器,确保每个测试生成唯一的数据
  197. let testDataCounter = 0;
  198. // 生成随机身份证号,确保唯一性
  199. function generateUniqueIdCard(): string {
  200. // 地区码(6位)
  201. const areaCode = '110101';
  202. // 出生日期(8位)- 使用 1980-01-01 到 2005-12-31 之间的随机日期
  203. const startYear = 1980;
  204. const endYear = 2005;
  205. const year = startYear + Math.floor(Math.random() * (endYear - startYear + 1));
  206. const month = String(Math.floor(Math.random() * 12) + 1).padStart(2, '0');
  207. const day = String(Math.floor(Math.random() * 28) + 1).padStart(2, '0');
  208. const birthDate = `${year}${month}${day}`;
  209. // 顺序码(3位)- 使用时间戳后3位
  210. const sequence = String(Date.now()).slice(-3).padStart(3, '0');
  211. // 校验码(1位)- 随机数字
  212. const checkCode = String(Math.floor(Math.random() * 10));
  213. return areaCode + birthDate + sequence + checkCode;
  214. }
  215. function generateUniqueTestData() {
  216. const timestamp = Date.now();
  217. const counter = ++testDataCounter;
  218. const random = Math.floor(Math.random() * 10000);
  219. const idCard = generateUniqueIdCard();
  220. // 生成动态日期(当前日期 + 7 天)
  221. const today = new Date();
  222. const futureDate = new Date(today);
  223. futureDate.setDate(today.getDate() + 7);
  224. const hireDate = futureDate.toISOString().split('T')[0]; // 格式: YYYY-MM-DD
  225. // 生成18位身份证号
  226. return {
  227. orderName: '测试订单_' + timestamp + '_' + counter + '_' + random,
  228. personName: '测试残疾人_' + timestamp + '_' + counter + '_' + random,
  229. personName2: '测试残疾人2_' + timestamp + '_' + counter + '_' + random,
  230. idCard,
  231. idCard2: generateUniqueIdCard(),
  232. phone: '138' + String(counter).padStart(4, '0') + String(random).padStart(4, '0'),
  233. phone2: '139' + String(counter).padStart(4, '0') + String(random).padStart(4, '0'),
  234. gender: '男',
  235. disabilityType: '视力残疾',
  236. disabilityLevel: '一级',
  237. disabilityId: '残疾证' + String(timestamp).slice(-6) + String(random).padStart(4, '0'),
  238. idAddress: '北京市东城区测试地址' + timestamp + '_' + counter,
  239. province: '北京市',
  240. city: '北京市',
  241. hireDate,
  242. salary: 5000,
  243. platformName: `测试平台_${timestamp}_${counter}_${random}`,
  244. companyName: `测试公司_${timestamp}_${counter}_${random}`,
  245. channelName: `测试渠道_${timestamp}_${counter}_${random}`,
  246. };
  247. }
  248. // 等待订单行出现在表格中
  249. async function waitForOrderRow(page: Parameters<typeof test>[0]['page'], orderName: string, timeout = 15000) {
  250. const startTime = Date.now();
  251. while (Date.now() - startTime < timeout) {
  252. const table = page.locator('table');
  253. const orderRow = table.locator('tbody tr').filter({ hasText: orderName });
  254. const count = await orderRow.count();
  255. if (count > 0) {
  256. console.debug('找到订单行:', orderName);
  257. return true;
  258. }
  259. await page.waitForTimeout(TIMEOUTS.MEDIUM);
  260. }
  261. console.debug('等待订单行超时:', orderName);
  262. return false;
  263. }
  264. test.describe('订单完整流程测试', () => {
  265. test.describe('新增订单完整流程', () => {
  266. test('应该能完成新增订单的完整流程:创建订单 → 添加人员 → 添加附件 → 激活订单', async ({
  267. adminLoginPage,
  268. orderManagementPage,
  269. request,
  270. page
  271. }) => {
  272. // 登录
  273. await adminLoginPage.goto();
  274. await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
  275. await adminLoginPage.expectLoginSuccess();
  276. await orderManagementPage.goto();
  277. // 使用 API 创建平台和公司测试数据
  278. const createdPlatform = await createPlatformViaAPI(request);
  279. if (!createdPlatform) {
  280. test.skip(true, '无法创建平台数据');
  281. return;
  282. }
  283. const createdCompany = await createCompanyViaAPI(request, createdPlatform.id);
  284. if (!createdCompany) {
  285. test.skip(true, '无法创建公司数据');
  286. return;
  287. }
  288. // 生成唯一测试数据
  289. const testData = generateUniqueTestData();
  290. // 使用 API 创建残疾人测试数据
  291. const personData = {
  292. name: testData.personName,
  293. gender: testData.gender,
  294. idCard: testData.idCard,
  295. disabilityId: testData.disabilityId,
  296. disabilityType: testData.disabilityType,
  297. disabilityLevel: testData.disabilityLevel,
  298. idAddress: testData.idAddress,
  299. phone: testData.phone,
  300. province: testData.province,
  301. city: testData.city,
  302. };
  303. const createdPerson = await createDisabledPersonViaAPI(request, personData);
  304. if (!createdPerson) {
  305. test.skip(true, '无法创建残疾人数据');
  306. return;
  307. }
  308. console.debug('已创建残疾人:', createdPerson.name, 'ID:', createdPerson.id);
  309. // 步骤 1: 创建订单(填写所有字段)
  310. await orderManagementPage.openCreateDialog();
  311. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  312. // 选择平台(使用 API 创建的平台名称)
  313. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  314. if (await platformTrigger.count() > 0) {
  315. await platformTrigger.click();
  316. await page.waitForTimeout(TIMEOUTS.MEDIUM_LONG);
  317. const platformOption = page.getByRole('option', { name: createdPlatform.name });
  318. const platformCount = await platformOption.count();
  319. if (platformCount > 0) {
  320. await platformOption.click();
  321. }
  322. await page.waitForTimeout(TIMEOUTS.VERY_SHORT);
  323. }
  324. // 选择公司(使用 API 创建的公司名称)
  325. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  326. if (await companyTrigger.count() > 0) {
  327. await companyTrigger.click();
  328. await page.waitForTimeout(TIMEOUTS.MEDIUM_LONG);
  329. const companyOption = page.getByRole('option', { name: createdCompany.name });
  330. const companyCount = await companyOption.count();
  331. if (companyCount > 0) {
  332. await companyOption.click();
  333. }
  334. await page.waitForTimeout(TIMEOUTS.VERY_SHORT);
  335. }
  336. // 填写预计开始日期
  337. await page.getByLabel(/预计开始日期|开始日期/).fill(testData.hireDate);
  338. // 选择残疾人
  339. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPerson.name);
  340. if (!hasPerson) {
  341. await orderManagementPage.cancelDialog();
  342. test.skip(true, '没有可用的残疾人数据');
  343. return;
  344. }
  345. // 提交订单
  346. await page.waitForTimeout(TIMEOUTS.VERY_LONG);
  347. await orderManagementPage.submitForm();
  348. await orderManagementPage.waitForDialogClosed();
  349. // 验证订单创建成功
  350. await page.waitForTimeout(TIMEOUTS.LONG);
  351. const successToast = page.locator('[data-sonner-toast][data-type="success"]');
  352. const hasSuccess = await successToast.count() > 0;
  353. expect(hasSuccess).toBe(true);
  354. // 等待订单行出现在表格中
  355. const orderFound = await waitForOrderRow(page, testData.orderName);
  356. expect(orderFound).toBe(true);
  357. // 步骤 2: 打开订单详情并验证人员已添加
  358. await orderManagementPage.openDetailDialog(testData.orderName);
  359. // 获取人员列表
  360. const personList = await orderManagementPage.getPersonListFromDetail();
  361. console.debug('订单人员列表:', personList);
  362. expect(personList.length).toBeGreaterThan(0);
  363. // 步骤 3: 为人员添加附件
  364. try {
  365. await orderManagementPage.openAddAttachmentDialog();
  366. const fileName = 'images/photo.jpg';
  367. await orderManagementPage.uploadAttachment(personList[0].name || createdPerson.name, fileName, 'image/jpeg', '其他');
  368. await page.waitForTimeout(TIMEOUTS.LONG);
  369. await orderManagementPage.closeUploadDialog();
  370. // 验证附件上传成功
  371. const attachmentList = await orderManagementPage.getAttachmentListFromDetail();
  372. console.debug('附件列表:', attachmentList);
  373. } catch (error) {
  374. console.debug('附件上传出错(非关键功能,继续测试):', error);
  375. // 确保对话框关闭
  376. await page.keyboard.press('Escape').catch(() => {});
  377. await page.waitForTimeout(TIMEOUTS.SHORT);
  378. }
  379. // 关闭订单详情对话框
  380. await orderManagementPage.closeDetailDialog();
  381. // 步骤 4: 激活订单(草稿 → 进行中)
  382. const activated = await orderManagementPage.activateOrder(testData.orderName);
  383. expect(activated).toBe(true);
  384. // 步骤 5: 验证订单状态(激活后变为已确认)
  385. await orderManagementPage.expectOrderStatus(testData.orderName, 'confirmed');
  386. console.debug('新增订单完整流程测试通过');
  387. });
  388. });
  389. test.describe('编辑订单完整流程', () => {
  390. test('应该能完成编辑订单的完整流程:打开订单 → 修改信息 → 添加人员 → 关闭订单', async ({
  391. adminLoginPage,
  392. orderManagementPage,
  393. request,
  394. page
  395. }) => {
  396. // 登录
  397. await adminLoginPage.goto();
  398. await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
  399. await adminLoginPage.expectLoginSuccess();
  400. await orderManagementPage.goto();
  401. // 使用 API 创建平台和公司测试数据
  402. const createdPlatform = await createPlatformViaAPI(request);
  403. if (!createdPlatform) {
  404. test.skip(true, '无法创建平台数据');
  405. return;
  406. }
  407. const createdCompany = await createCompanyViaAPI(request, createdPlatform.id);
  408. if (!createdCompany) {
  409. test.skip(true, '无法创建公司数据');
  410. return;
  411. }
  412. // 生成唯一测试数据
  413. const testData = generateUniqueTestData();
  414. // 使用 API 创建两个残疾人测试数据
  415. const personData = {
  416. name: testData.personName,
  417. gender: testData.gender,
  418. idCard: testData.idCard,
  419. disabilityId: testData.disabilityId,
  420. disabilityType: testData.disabilityType,
  421. disabilityLevel: testData.disabilityLevel,
  422. idAddress: testData.idAddress,
  423. phone: testData.phone,
  424. province: testData.province,
  425. city: testData.city,
  426. };
  427. const personData2 = {
  428. name: testData.personName2,
  429. gender: testData.gender,
  430. idCard: testData.idCard2,
  431. disabilityId: '残疾证' + String(Date.now()).slice(-6) + String(Math.floor(Math.random() * 10000)).padStart(4, '0'),
  432. disabilityType: testData.disabilityType,
  433. disabilityLevel: testData.disabilityLevel,
  434. idAddress: testData.idAddress,
  435. phone: testData.phone2,
  436. province: testData.province,
  437. city: testData.city,
  438. };
  439. const createdPerson = await createDisabledPersonViaAPI(request, personData);
  440. if (!createdPerson) {
  441. test.skip(true, '无法创建残疾人数据');
  442. return;
  443. }
  444. console.debug('已创建残疾人1:', createdPerson.name, 'ID:', createdPerson.id);
  445. const createdPerson2 = await createDisabledPersonViaAPI(request, personData2);
  446. if (!createdPerson2) {
  447. test.skip(true, '无法创建残疾人数据2');
  448. return;
  449. }
  450. console.debug('已创建残疾人2:', createdPerson2.name, 'ID:', createdPerson2.id);
  451. // 步骤 1: 创建初始订单
  452. await orderManagementPage.openCreateDialog();
  453. await page.getByLabel(/订单名称|名称/).fill(testData.orderName);
  454. // 选择平台(使用 API 创建的平台名称)
  455. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  456. if (await platformTrigger.count() > 0) {
  457. await platformTrigger.click();
  458. await page.waitForTimeout(TIMEOUTS.MEDIUM_LONG);
  459. const platformOption = page.getByRole('option', { name: createdPlatform.name });
  460. const platformCount = await platformOption.count();
  461. if (platformCount > 0) {
  462. await platformOption.click();
  463. }
  464. await page.waitForTimeout(TIMEOUTS.VERY_SHORT);
  465. }
  466. // 选择公司(使用 API 创建的公司名称)
  467. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  468. if (await companyTrigger.count() > 0) {
  469. await companyTrigger.click();
  470. await page.waitForTimeout(TIMEOUTS.MEDIUM_LONG);
  471. const companyOption = page.getByRole('option', { name: createdCompany.name });
  472. const companyCount = await companyOption.count();
  473. if (companyCount > 0) {
  474. await companyOption.click();
  475. }
  476. await page.waitForTimeout(TIMEOUTS.VERY_SHORT);
  477. }
  478. await page.getByLabel(/预计开始日期|开始日期/).fill(testData.hireDate);
  479. const hasPerson = await selectDisabledPersonInAddDialog(page, createdPerson.name);
  480. if (!hasPerson) {
  481. await orderManagementPage.cancelDialog();
  482. test.skip(true, '没有可用的残疾人数据');
  483. return;
  484. }
  485. await page.waitForTimeout(TIMEOUTS.VERY_LONG);
  486. await orderManagementPage.submitForm();
  487. await orderManagementPage.waitForDialogClosed();
  488. // 验证订单创建成功
  489. await page.waitForTimeout(TIMEOUTS.LONG);
  490. const successToast = page.locator('[data-sonner-toast][data-type="success"]');
  491. const hasSuccess = await successToast.count() > 0;
  492. expect(hasSuccess).toBe(true);
  493. const orderFound = await waitForOrderRow(page, testData.orderName);
  494. expect(orderFound).toBe(true);
  495. // 步骤 2: 修改订单信息
  496. const newOrderName = testData.orderName + '_已修改';
  497. const editResult = await orderManagementPage.editOrder(testData.orderName, {
  498. name: newOrderName,
  499. });
  500. // 验证编辑成功
  501. expect(editResult.hasSuccess).toBe(true);
  502. // 步骤 2.5: 验证订单名称已更新
  503. const editedOrderFound = await waitForOrderRow(page, newOrderName);
  504. expect(editedOrderFound).toBe(true);
  505. console.debug('订单名称已更新为:', newOrderName);
  506. // 步骤 3: 激活订单(使其可以进行状态流转)
  507. const activated = await orderManagementPage.activateOrder(newOrderName);
  508. expect(activated).toBe(true);
  509. // 步骤 4: 打开订单详情对话框(使用新的订单名称)
  510. await orderManagementPage.openDetailDialog(newOrderName);
  511. // 步骤 3.5: 确认待添加的人员(创建订单时选择的人员在待添加列表中)
  512. // 检查是否有待添加人员
  513. const confirmAddButton = page.getByTestId('confirm-add-persons-button');
  514. const confirmButtonCount = await confirmAddButton.count();
  515. if (confirmButtonCount > 0) {
  516. console.debug('发现待添加人员,点击确认添加按钮');
  517. await confirmAddButton.click();
  518. // 等待成功 toast
  519. await page.waitForTimeout(TIMEOUTS.LONG);
  520. const addSuccessToast = page.locator('[data-sonner-toast][data-type="success"]');
  521. const hasAddSuccess = await addSuccessToast.count() > 0;
  522. if (hasAddSuccess) {
  523. console.debug('待添加人员已确认添加');
  524. }
  525. }
  526. // 验证人员列表包含已确认的人员
  527. const personListAfter = await orderManagementPage.getPersonListFromDetail();
  528. console.debug('人员列表:', personListAfter);
  529. expect(personListAfter.length).toBeGreaterThan(0); // 至少有1个人
  530. // 步骤 4: 关闭订单(已确认 → 已完成)
  531. await orderManagementPage.closeDetailDialog();
  532. const closed = await orderManagementPage.closeOrder(newOrderName);
  533. expect(closed).toBe(true);
  534. // 步骤 6: 验证订单状态为已完成
  535. await orderManagementPage.expectOrderStatus(newOrderName, 'completed');
  536. console.debug('编辑订单完整流程测试通过');
  537. });
  538. });
  539. });