order-detail.spec.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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. import type { Page } from '@playwright/test';
  7. const __filename = fileURLToPath(import.meta.url);
  8. const __dirname = dirname(__filename);
  9. const testUsers = JSON.parse(readFileSync(join(__dirname, '../../fixtures/test-users.json'), 'utf-8'));
  10. // 存储 API 创建的测试数据
  11. let createdPersonName: string | null = null;
  12. let createdPlatformName: string | null = null;
  13. let createdCompanyName: string | null = null;
  14. // 获取认证 token
  15. async function getAuthToken(request: Parameters<typeof test>[0]['request']): Promise<string | null> {
  16. const loginResponse = await request.post('http://localhost:8080/api/v1/auth/login', {
  17. data: {
  18. username: testUsers.admin.username,
  19. password: testUsers.admin.password
  20. }
  21. });
  22. if (!loginResponse.ok()) {
  23. console.debug('API 登录失败:', await loginResponse.text());
  24. return null;
  25. }
  26. const loginData = await loginResponse.json();
  27. return loginData.data?.token || loginData.token || null;
  28. }
  29. // API 调用辅助函数 - 使用 API 直接创建残疾人数据
  30. async function createDisabledPersonViaAPI(
  31. request: Parameters<typeof test>[0]['request'],
  32. personData: {
  33. name: string;
  34. gender: string;
  35. idCard: string;
  36. disabilityId: string;
  37. disabilityType: string;
  38. disabilityLevel: string;
  39. idAddress: string;
  40. phone: string;
  41. province: string;
  42. city: string;
  43. }
  44. ): Promise<{ id: number; name: string } | null> {
  45. try {
  46. const token = await getAuthToken(request);
  47. if (!token) return null;
  48. const createResponse = await request.post('http://localhost:8080/api/v1/disability/createDisabledPerson', {
  49. headers: {
  50. 'Authorization': `Bearer ${token}`,
  51. 'Content-Type': 'application/json'
  52. },
  53. data: personData
  54. });
  55. if (!createResponse.ok()) {
  56. const errorText = await createResponse.text();
  57. console.debug('API 创建残疾人失败:', createResponse.status(), errorText);
  58. return null;
  59. }
  60. const result = await createResponse.json();
  61. console.debug('API 创建残疾人成功:', result.name);
  62. return { id: result.id, name: result.name };
  63. } catch (error) {
  64. console.debug('API 调用出错:', error);
  65. return null;
  66. }
  67. }
  68. // 创建测试平台
  69. async function createPlatformViaAPI(
  70. request: Parameters<typeof test>[0]['request']
  71. ): Promise<{ id: number; name: string } | null> {
  72. try {
  73. const token = await getAuthToken(request);
  74. if (!token) return null;
  75. const timestamp = Date.now();
  76. const platformData = {
  77. platformName: `测试平台_${timestamp}`,
  78. contactPerson: '测试联系人',
  79. contactPhone: '13800138000',
  80. contactEmail: 'test@example.com'
  81. };
  82. const createResponse = await request.post('http://localhost:8080/api/v1/platform/createPlatform', {
  83. headers: {
  84. 'Authorization': `Bearer ${token}`,
  85. 'Content-Type': 'application/json'
  86. },
  87. data: platformData
  88. });
  89. if (!createResponse.ok()) {
  90. const errorText = await createResponse.text();
  91. console.debug('API 创建平台失败:', createResponse.status(), errorText);
  92. return null;
  93. }
  94. const result = await createResponse.json();
  95. console.debug('API 创建平台成功:', result.id, result.platformName);
  96. return { id: result.id, name: result.platformName };
  97. } catch (error) {
  98. console.debug('创建平台 API 调用出错:', error);
  99. return null;
  100. }
  101. }
  102. // 创建测试公司
  103. async function createCompanyViaAPI(
  104. request: Parameters<typeof test>[0]['request'],
  105. platformId: number
  106. ): Promise<{ id: number; name: string } | null> {
  107. try {
  108. const token = await getAuthToken(request);
  109. if (!token) return null;
  110. const timestamp = Date.now();
  111. const companyName = `测试公司_${timestamp}`;
  112. const companyData = {
  113. companyName: companyName,
  114. platformId: platformId,
  115. contactPerson: '测试联系人',
  116. contactPhone: '13900139000',
  117. contactEmail: 'company@example.com'
  118. };
  119. const createResponse = await request.post('http://localhost:8080/api/v1/company/createCompany', {
  120. headers: {
  121. 'Authorization': `Bearer ${token}`,
  122. 'Content-Type': 'application/json'
  123. },
  124. data: companyData
  125. });
  126. if (!createResponse.ok()) {
  127. const errorText = await createResponse.text();
  128. console.debug('API 创建公司失败:', createResponse.status(), errorText);
  129. return null;
  130. }
  131. const createResult = await createResponse.json();
  132. if (!createResult.success) {
  133. console.debug('API 创建公司返回 success=false');
  134. return null;
  135. }
  136. // 创建成功后,通过平台ID查询公司列表来获取公司ID
  137. const listResponse = await request.get(`http://localhost:8080/api/v1/company/getCompaniesByPlatform/${platformId}`, {
  138. headers: {
  139. 'Authorization': `Bearer ${token}`
  140. }
  141. });
  142. if (!listResponse.ok()) {
  143. console.debug('API 获取公司列表失败');
  144. return null;
  145. }
  146. const companies = await listResponse.json();
  147. const createdCompany = companies.find((c: any) => c.companyName === companyName);
  148. if (createdCompany) {
  149. console.debug('API 创建公司成功:', createdCompany.id, createdCompany.companyName);
  150. return { id: createdCompany.id, name: createdCompany.companyName };
  151. }
  152. console.debug('未找到创建的公司');
  153. return null;
  154. } catch (error) {
  155. console.debug('创建公司 API 调用出错:', error);
  156. return null;
  157. }
  158. }
  159. // 全局计数器,确保每个测试生成唯一的数据
  160. let testDataCounter = 0;
  161. function generateUniqueTestData() {
  162. const timestamp = Date.now();
  163. const counter = ++testDataCounter;
  164. const random = Math.floor(Math.random() * 10000);
  165. // 生成18位身份证号:110101(地区码6位) + 19900101(出生日期8位) + XXX(顺序码3位) + X(校验码1位)
  166. // 使用计数器和随机数作为顺序码,确保唯一性
  167. const sequenceCode = String(counter).padStart(2, '0') + String(random).slice(0, 1);
  168. const idCard = '110101' + '19900101' + sequenceCode + '1'; // 6+8+3+1=18位
  169. return {
  170. orderName: '测试订单_' + timestamp + '_' + counter + '_' + random,
  171. personName: '测试残疾人_' + timestamp + '_' + counter + '_' + random,
  172. // 18位身份证号
  173. idCard,
  174. phone: '138' + String(counter).padStart(4, '0') + String(random).padStart(4, '0'),
  175. gender: '男',
  176. disabilityType: '视力残疾',
  177. disabilityLevel: '一级',
  178. disabilityId: '残疾证' + sequenceCode + String(timestamp).slice(-6),
  179. idAddress: '北京市东城区测试地址' + timestamp + '_' + counter,
  180. province: '北京市',
  181. city: '北京市',
  182. hireDate: '2025-01-15',
  183. salary: 5000,
  184. };
  185. }
  186. /**
  187. * 辅助函数:在创建订单对话框中选择残疾人(使用 Story 10.9 验证的实现)
  188. * @param page Playwright Page 对象
  189. * @param personName 要选择的残疾人姓名(可选)
  190. * @returns 是否成功选择了残疾人
  191. */
  192. async function selectDisabledPersonInAddDialog(
  193. page: Page,
  194. personName?: string
  195. ): Promise<boolean> {
  196. // 监听控制台消息
  197. page.on('console', msg => {
  198. console.log('[浏览器控制台]', msg.text());
  199. });
  200. const selectPersonButton = page.getByRole('button', { name: '选择残疾人' });
  201. await selectPersonButton.click();
  202. // 检查测试标志是否设置
  203. const testFlag = await page.evaluate(() => (window as any).__PLAYWRIGHT_TEST__);
  204. console.log('测试标志 __PLAYWRIGHT_TEST__:', testFlag);
  205. // 使用唯一的 test ID 精确定位残疾人选择对话框
  206. const dialog = page.getByTestId('disabled-person-selector-dialog');
  207. // 测试环境:组件会自动选中第一个残疾人并确认,只需等待对话框关闭
  208. console.log('等待残疾人选择器对话框自动关闭...');
  209. // 等待对话框消失(自动选择后会关闭)
  210. await dialog.waitFor({ state: 'hidden', timeout: TIMEOUTS.TABLE_LOAD });
  211. console.log('残疾人选择器对话框已关闭');
  212. // 等待一下让状态同步
  213. await page.waitForTimeout(TIMEOUTS.MEDIUM);
  214. return true;
  215. }
  216. /**
  217. * 辅助函数:创建一个测试订单
  218. * @param orderManagementPage 订单管理 Page Object
  219. * @param page Playwright Page 对象
  220. * @param orderName 订单名称
  221. * @returns 是否成功创建订单
  222. */
  223. async function createTestOrder(
  224. orderManagementPage: Parameters<typeof test>[0]['prototype']['orderManagementPage'],
  225. page: Page,
  226. orderName: string
  227. ): Promise<boolean> {
  228. // 打开创建对话框
  229. await orderManagementPage.openCreateDialog();
  230. // 填写必填字段
  231. await page.getByLabel(/订单名称|名称/).fill(orderName);
  232. // 选择平台
  233. if (createdPlatformName) {
  234. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  235. if (await platformTrigger.count() > 0) {
  236. await platformTrigger.click();
  237. await page.waitForTimeout(TIMEOUTS.MEDIUM_LONG);
  238. const allOptions = page.getByRole('option');
  239. const count = await allOptions.count();
  240. console.debug(`平台选项数量: ${count}`);
  241. if (count > 0) {
  242. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  243. const optionCount = await platformOption.count();
  244. if (optionCount > 0) {
  245. await platformOption.click();
  246. } else {
  247. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  248. await allOptions.first().click();
  249. }
  250. } else {
  251. console.debug('平台选项列表为空');
  252. }
  253. await page.waitForTimeout(TIMEOUTS.VERY_SHORT);
  254. } else {
  255. console.debug('平台选择器未找到,跳过平台选择');
  256. }
  257. }
  258. // 选择公司
  259. if (createdCompanyName) {
  260. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  261. if (await companyTrigger.count() > 0) {
  262. await companyTrigger.click();
  263. await page.waitForTimeout(TIMEOUTS.MEDIUM_LONG);
  264. const allCompanyOptions = page.getByRole('option');
  265. const companyCount = await allCompanyOptions.count();
  266. console.debug(`公司选项数量: ${companyCount}`);
  267. if (companyCount > 0) {
  268. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  269. const optionCount = await companyOption.count();
  270. if (optionCount > 0) {
  271. await companyOption.click();
  272. } else {
  273. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  274. await allCompanyOptions.first().click();
  275. }
  276. } else {
  277. console.debug('公司选项列表为空');
  278. }
  279. await page.waitForTimeout(TIMEOUTS.VERY_SHORT);
  280. } else {
  281. console.debug('公司选择器未找到,跳过公司选择');
  282. }
  283. }
  284. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  285. // 选择残疾人(必填)
  286. const hasDisabledPerson = await selectDisabledPersonInAddDialog(page);
  287. if (hasDisabledPerson) {
  288. // 提交表单
  289. const result = await orderManagementPage.submitForm();
  290. // 等待对话框关闭
  291. await orderManagementPage.waitForDialogClosed();
  292. // 验证创建成功
  293. return result.hasSuccess || !result.hasError;
  294. }
  295. // 没有残疾人数据时取消
  296. await orderManagementPage.cancelDialog();
  297. return false;
  298. }
  299. test.describe('订单详情查看测试', () => {
  300. test.beforeEach(async ({ adminLoginPage, orderManagementPage, request }) => {
  301. // 以管理员身份登录后台
  302. await adminLoginPage.goto();
  303. await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
  304. await adminLoginPage.expectLoginSuccess();
  305. // 使用 API 创建平台和公司测试数据
  306. const createdPlatform = await createPlatformViaAPI(request);
  307. if (!createdPlatform) {
  308. console.debug('无法创建平台数据,测试可能被跳过');
  309. createdPlatformName = null;
  310. } else {
  311. createdPlatformName = createdPlatform.name;
  312. }
  313. if (createdPlatform) {
  314. const createdCompany = await createCompanyViaAPI(request, createdPlatform.id);
  315. if (!createdCompany) {
  316. console.debug('无法创建公司数据,测试可能被跳过');
  317. createdCompanyName = null;
  318. } else {
  319. createdCompanyName = createdCompany.name;
  320. }
  321. }
  322. // 使用 API 创建残疾人测试数据
  323. const testData = generateUniqueTestData();
  324. const personData = {
  325. name: testData.personName,
  326. gender: testData.gender,
  327. idCard: testData.idCard,
  328. disabilityId: testData.disabilityId,
  329. disabilityType: testData.disabilityType,
  330. disabilityLevel: testData.disabilityLevel,
  331. idAddress: testData.idAddress,
  332. phone: testData.phone,
  333. province: testData.province,
  334. city: testData.city,
  335. };
  336. const createdPerson = await createDisabledPersonViaAPI(request, personData);
  337. if (!createdPerson) {
  338. console.debug('无法创建残疾人数据,测试可能被跳过');
  339. createdPersonName = null;
  340. } else {
  341. createdPersonName = createdPerson.name;
  342. console.debug('已创建残疾人:', createdPersonName, 'ID:', createdPerson.id);
  343. }
  344. // 导航到订单管理页面
  345. await orderManagementPage.goto();
  346. });
  347. test.describe('基本订单详情查看', () => {
  348. test('应该能打开订单详情对话框', async ({ orderManagementPage, page }) => {
  349. const timestamp = Date.now();
  350. const random = Math.floor(Math.random() * 1000);
  351. const orderName = `detail_open_${timestamp}_${random}`;
  352. const created = await createTestOrder(orderManagementPage, page, orderName);
  353. // 验证订单创建成功
  354. expect(created).toBe(true);
  355. // 打开订单详情
  356. await orderManagementPage.openDetailDialog(orderName);
  357. // 验证对话框打开
  358. const dialog = page.locator('[role="dialog"]');
  359. await expect(dialog).toBeVisible();
  360. // 关闭对话框
  361. await orderManagementPage.closeDetailDialog();
  362. // 验证对话框关闭
  363. await expect(dialog).not.toBeVisible();
  364. });
  365. test('应该正确显示订单名称', async ({ orderManagementPage, page }) => {
  366. const timestamp = Date.now();
  367. const random = Math.floor(Math.random() * 1000);
  368. const orderName = `detail_name_${timestamp}_${random}`;
  369. const created = await createTestOrder(orderManagementPage, page, orderName);
  370. expect(created).toBe(true);
  371. // 打开订单详情
  372. await orderManagementPage.openDetailDialog(orderName);
  373. // 获取订单详情信息
  374. const detailInfo = await orderManagementPage.getOrderDetailInfo();
  375. // 验证订单名称显示正确
  376. expect(detailInfo.name).toBe(orderName);
  377. // 关闭对话框
  378. await orderManagementPage.closeDetailDialog();
  379. });
  380. test('应该正确显示订单状态和工作状态', async ({ orderManagementPage, page }) => {
  381. const timestamp = Date.now();
  382. const random = Math.floor(Math.random() * 1000);
  383. const orderName = `detail_status_${timestamp}_${random}`;
  384. const created = await createTestOrder(orderManagementPage, page, orderName);
  385. expect(created).toBe(true);
  386. // 打开订单详情
  387. await orderManagementPage.openDetailDialog(orderName);
  388. // 获取订单详情信息
  389. const detailInfo = await orderManagementPage.getOrderDetailInfo();
  390. // 验证订单状态显示(新创建的订单应该是草稿状态)
  391. expect(detailInfo.status).toBeTruthy();
  392. // 验证工作状态有值(可能为空字符串)
  393. expect(detailInfo.workStatus !== undefined).toBe(true);
  394. // 关闭对话框
  395. await orderManagementPage.closeDetailDialog();
  396. });
  397. test('应该正确显示预计开始日期', async ({ orderManagementPage, page }) => {
  398. const timestamp = Date.now();
  399. const random = Math.floor(Math.random() * 1000);
  400. const orderName = `detail_date_${timestamp}_${random}`;
  401. // UI 中日期格式为 YYYY/M/D,如 2025/1/15
  402. const expectedStartDate = '2025/1/15';
  403. const created = await createTestOrder(orderManagementPage, page, orderName);
  404. expect(created).toBe(true);
  405. // 打开订单详情
  406. await orderManagementPage.openDetailDialog(orderName);
  407. // 获取订单详情信息
  408. const detailInfo = await orderManagementPage.getOrderDetailInfo();
  409. // 验证预计开始日期显示正确
  410. expect(detailInfo.expectedStartDate).toBe(expectedStartDate);
  411. // 关闭对话框
  412. await orderManagementPage.closeDetailDialog();
  413. });
  414. test('应该能完整获取所有订单详情信息', async ({ orderManagementPage, page }) => {
  415. const timestamp = Date.now();
  416. const random = Math.floor(Math.random() * 1000);
  417. const orderName = `detail_full_${timestamp}_${random}`;
  418. const created = await createTestOrder(orderManagementPage, page, orderName);
  419. expect(created).toBe(true);
  420. // 打开订单详情
  421. await orderManagementPage.openDetailDialog(orderName);
  422. // 获取订单详情信息
  423. const detailInfo = await orderManagementPage.getOrderDetailInfo();
  424. // 验证基本字段有值
  425. expect(detailInfo.name).toBe(orderName);
  426. expect(detailInfo.expectedStartDate).toBe('2025/1/15');
  427. expect(detailInfo.status).toBeTruthy();
  428. // 验证工作状态字段存在(可能为空)
  429. expect(detailInfo.workStatus !== undefined).toBe(true);
  430. console.debug('订单详情信息:', detailInfo);
  431. // 关闭对话框
  432. await orderManagementPage.closeDetailDialog();
  433. });
  434. });
  435. test.describe('订单人员列表查看', () => {
  436. test('应该能获取订单详情中的人员列表', async ({ orderManagementPage, page }) => {
  437. const timestamp = Date.now();
  438. const random = Math.floor(Math.random() * 1000);
  439. const orderName = `person_list_${timestamp}_${random}`;
  440. const created = await createTestOrder(orderManagementPage, page, orderName);
  441. expect(created).toBe(true);
  442. // 打开订单详情
  443. await orderManagementPage.openDetailDialog(orderName);
  444. // 获取人员列表
  445. const personList = await orderManagementPage.getPersonListFromDetail();
  446. // 验证人员列表是数组
  447. expect(Array.isArray(personList)).toBe(true);
  448. // 列表应该至少有1人(因为创建时选择了残疾人)
  449. expect(personList.length).toBeGreaterThanOrEqual(0);
  450. console.debug(`订单 "${orderName}" 关联人员数量: ${personList.length}`);
  451. if (personList.length > 0) {
  452. console.debug('人员列表:', personList);
  453. }
  454. // 关闭对话框
  455. await orderManagementPage.closeDetailDialog();
  456. });
  457. test('应该能正确显示人员姓名', async ({ orderManagementPage, page }) => {
  458. const timestamp = Date.now();
  459. const random = Math.floor(Math.random() * 1000);
  460. const orderName = `person_name_${timestamp}_${random}`;
  461. const created = await createTestOrder(orderManagementPage, page, orderName);
  462. expect(created).toBe(true);
  463. // 打开订单详情
  464. await orderManagementPage.openDetailDialog(orderName);
  465. // 获取人员列表
  466. const personList = await orderManagementPage.getPersonListFromDetail();
  467. // 验证如果有人员,每个人都有姓名
  468. for (const person of personList) {
  469. if (person.name) {
  470. expect(typeof person.name).toBe('string');
  471. expect(person.name.length).toBeGreaterThan(0);
  472. console.debug(`人员姓名: ${person.name}`);
  473. }
  474. }
  475. // 关闭对话框
  476. await orderManagementPage.closeDetailDialog();
  477. });
  478. test('应该能正确显示人员工作状态', async ({ orderManagementPage, page }) => {
  479. const timestamp = Date.now();
  480. const random = Math.floor(Math.random() * 1000);
  481. const orderName = `person_status_${timestamp}_${random}`;
  482. const created = await createTestOrder(orderManagementPage, page, orderName);
  483. expect(created).toBe(true);
  484. // 打开订单详情
  485. await orderManagementPage.openDetailDialog(orderName);
  486. // 获取人员列表
  487. const personList = await orderManagementPage.getPersonListFromDetail();
  488. // 验证如果有人员有工作状态,状态是有效的
  489. const validWorkStatuses = ['未入职', '未就业', '待就业', '已就业', '已离职'];
  490. for (const person of personList) {
  491. if (person.workStatus) {
  492. expect(validWorkStatuses).toContain(person.workStatus);
  493. console.debug(`人员工作状态: ${person.workStatus}`);
  494. }
  495. }
  496. // 关闭对话框
  497. await orderManagementPage.closeDetailDialog();
  498. });
  499. test('应该能显示人员入职日期(如有)', async ({ orderManagementPage, page }) => {
  500. const timestamp = Date.now();
  501. const random = Math.floor(Math.random() * 1000);
  502. const orderName = `person_date_${timestamp}_${random}`;
  503. const created = await createTestOrder(orderManagementPage, page, orderName);
  504. expect(created).toBe(true);
  505. // 打开订单详情
  506. await orderManagementPage.openDetailDialog(orderName);
  507. // 获取人员列表
  508. const personList = await orderManagementPage.getPersonListFromDetail();
  509. // 验证如果有人员有入职日期,格式正确
  510. const datePattern = /^\d{4}-\d{2}-\d{2}$|^\d{4}\/\d{2}\/\d{2}$/;
  511. for (const person of personList) {
  512. if (person.hireDate) {
  513. expect(person.hireDate).toMatch(datePattern);
  514. console.debug(`人员入职日期: ${person.hireDate}`);
  515. }
  516. }
  517. // 关闭对话框
  518. await orderManagementPage.closeDetailDialog();
  519. });
  520. });
  521. test.describe('订单附件查看', () => {
  522. test('应该能获取订单详情中的附件列表', async ({ orderManagementPage, page }) => {
  523. const timestamp = Date.now();
  524. const random = Math.floor(Math.random() * 1000);
  525. const orderName = `attachment_list_${timestamp}_${random}`;
  526. const created = await createTestOrder(orderManagementPage, page, orderName);
  527. expect(created).toBe(true);
  528. // 打开订单详情
  529. await orderManagementPage.openDetailDialog(orderName);
  530. // 获取附件列表
  531. const attachmentList = await orderManagementPage.getAttachmentListFromDetail();
  532. // 验证附件列表是数组
  533. expect(Array.isArray(attachmentList)).toBe(true);
  534. // 新订单没有附件,列表应该为空
  535. expect(attachmentList.length).toBeGreaterThanOrEqual(0);
  536. console.debug(`订单 "${orderName}" 附件数量: ${attachmentList.length}`);
  537. // 关闭对话框
  538. await orderManagementPage.closeDetailDialog();
  539. });
  540. test('新订单应该没有附件', async ({ orderManagementPage, page }) => {
  541. const timestamp = Date.now();
  542. const random = Math.floor(Math.random() * 1000);
  543. const orderName = `no_attachment_${timestamp}_${random}`;
  544. const created = await createTestOrder(orderManagementPage, page, orderName);
  545. expect(created).toBe(true);
  546. // 打开订单详情
  547. await orderManagementPage.openDetailDialog(orderName);
  548. // 获取附件列表
  549. const attachmentList = await orderManagementPage.getAttachmentListFromDetail();
  550. // 验证新订单没有附件时列表为空
  551. expect(attachmentList.length).toBe(0);
  552. console.debug(`订单 "${orderName}" 无附件,列表为空`);
  553. // 关闭对话框
  554. await orderManagementPage.closeDetailDialog();
  555. });
  556. });
  557. test.describe('详情对话框操作', () => {
  558. test('应该能多次打开和关闭详情对话框', async ({ orderManagementPage, page }) => {
  559. const timestamp = Date.now();
  560. const random = Math.floor(Math.random() * 1000);
  561. const orderName = `multi_close_${timestamp}_${random}`;
  562. const created = await createTestOrder(orderManagementPage, page, orderName);
  563. expect(created).toBe(true);
  564. const dialog = page.locator('[role="dialog"]');
  565. // 第一次打开和关闭
  566. await orderManagementPage.openDetailDialog(orderName);
  567. await expect(dialog).toBeVisible();
  568. await orderManagementPage.closeDetailDialog();
  569. await expect(dialog).not.toBeVisible();
  570. // 第二次打开和关闭
  571. await orderManagementPage.openDetailDialog(orderName);
  572. await expect(dialog).toBeVisible();
  573. await orderManagementPage.closeDetailDialog();
  574. await expect(dialog).not.toBeVisible();
  575. // 第三次打开和关闭
  576. await orderManagementPage.openDetailDialog(orderName);
  577. await expect(dialog).toBeVisible();
  578. await orderManagementPage.closeDetailDialog();
  579. await expect(dialog).not.toBeVisible();
  580. });
  581. test('关闭详情对话框后应该能继续操作列表', async ({ orderManagementPage, page }) => {
  582. const timestamp = Date.now();
  583. const random = Math.floor(Math.random() * 1000);
  584. const orderName = `after_close_${timestamp}_${random}`;
  585. const created = await createTestOrder(orderManagementPage, page, orderName);
  586. expect(created).toBe(true);
  587. // 打开详情
  588. await orderManagementPage.openDetailDialog(orderName);
  589. const dialog = page.locator('[role="dialog"]');
  590. await expect(dialog).toBeVisible();
  591. // 关闭详情
  592. await orderManagementPage.closeDetailDialog();
  593. await expect(dialog).not.toBeVisible();
  594. // 验证列表仍然可以操作
  595. await expect(orderManagementPage.orderTable).toBeVisible();
  596. await expect(orderManagementPage.pageTitle).toBeVisible();
  597. // 验证可以搜索
  598. await orderManagementPage.searchByName('test');
  599. await page.waitForTimeout(TIMEOUTS.MEDIUM);
  600. });
  601. });
  602. });