order-detail.spec.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. // 全局计数器,确保每个测试生成唯一的数据
  159. let testDataCounter = 0;
  160. function generateUniqueTestData() {
  161. const timestamp = Date.now();
  162. const counter = ++testDataCounter;
  163. const random = Math.floor(Math.random() * 10000);
  164. // 生成18位身份证号:110101(地区码6位) + 19900101(出生日期8位) + XXX(顺序码3位) + X(校验码1位)
  165. // 使用计数器和随机数作为顺序码,确保唯一性
  166. const sequenceCode = String(counter).padStart(2, '0') + String(random).slice(0, 1);
  167. const idCard = '110101' + '19900101' + sequenceCode + '1'; // 6+8+3+1=18位
  168. return {
  169. orderName: '测试订单_' + timestamp + '_' + counter + '_' + random,
  170. personName: '测试残疾人_' + timestamp + '_' + counter + '_' + random,
  171. // 18位身份证号
  172. idCard,
  173. phone: '138' + String(counter).padStart(4, '0') + String(random).padStart(4, '0'),
  174. gender: '男',
  175. disabilityType: '视力残疾',
  176. disabilityLevel: '一级',
  177. disabilityId: '残疾证' + sequenceCode + String(timestamp).slice(-6),
  178. idAddress: '北京市东城区测试地址' + timestamp + '_' + counter,
  179. province: '北京市',
  180. city: '北京市',
  181. hireDate: '2025-01-15',
  182. salary: 5000,
  183. };
  184. }
  185. /**
  186. * 辅助函数:在创建订单对话框中选择残疾人(使用 Story 10.9 验证的实现)
  187. * @param page Playwright Page 对象
  188. * @param personName 要选择的残疾人姓名(可选)
  189. * @returns 是否成功选择了残疾人
  190. */
  191. async function selectDisabledPersonInAddDialog(
  192. page: Page,
  193. personName?: string
  194. ): Promise<boolean> {
  195. // 监听控制台消息
  196. page.on('console', msg => {
  197. console.log('[浏览器控制台]', msg.text());
  198. });
  199. const selectPersonButton = page.getByRole('button', { name: '选择残疾人' });
  200. await selectPersonButton.click();
  201. // 检查测试标志是否设置
  202. const testFlag = await page.evaluate(() => (window as any).__PLAYWRIGHT_TEST__);
  203. console.log('测试标志 __PLAYWRIGHT_TEST__:', testFlag);
  204. // 使用唯一的 test ID 精确定位残疾人选择对话框
  205. const dialog = page.getByTestId('disabled-person-selector-dialog');
  206. // 测试环境:组件会自动选中第一个残疾人并确认,只需等待对话框关闭
  207. console.log('等待残疾人选择器对话框自动关闭...');
  208. // 等待对话框消失(自动选择后会关闭)
  209. await dialog.waitFor({ state: 'hidden', timeout: 10000 });
  210. console.log('残疾人选择器对话框已关闭');
  211. // 等待一下让状态同步
  212. await page.waitForTimeout(500);
  213. return true;
  214. }
  215. /**
  216. * 辅助函数:创建一个测试订单
  217. * @param orderManagementPage 订单管理 Page Object
  218. * @param page Playwright Page 对象
  219. * @param orderName 订单名称
  220. * @returns 是否成功创建订单
  221. */
  222. async function createTestOrder(
  223. orderManagementPage: Parameters<typeof test>[0]['prototype']['orderManagementPage'],
  224. page: Page,
  225. orderName: string
  226. ): Promise<boolean> {
  227. // 打开创建对话框
  228. await orderManagementPage.openCreateDialog();
  229. // 填写必填字段
  230. await page.getByLabel(/订单名称|名称/).fill(orderName);
  231. // 选择平台
  232. if (createdPlatformName) {
  233. const platformTrigger = page.locator('[data-testid="platform-selector-create"]');
  234. if (await platformTrigger.count() > 0) {
  235. await platformTrigger.click();
  236. await page.waitForTimeout(800);
  237. const allOptions = page.getByRole('option');
  238. const count = await allOptions.count();
  239. console.debug(`平台选项数量: ${count}`);
  240. if (count > 0) {
  241. const platformOption = allOptions.filter({ hasText: createdPlatformName }).first();
  242. const optionCount = await platformOption.count();
  243. if (optionCount > 0) {
  244. await platformOption.click();
  245. } else {
  246. console.debug(`未找到平台 ${createdPlatformName},选择第一个可用平台`);
  247. await allOptions.first().click();
  248. }
  249. } else {
  250. console.debug('平台选项列表为空');
  251. }
  252. await page.waitForTimeout(200);
  253. } else {
  254. console.debug('平台选择器未找到,跳过平台选择');
  255. }
  256. }
  257. // 选择公司
  258. if (createdCompanyName) {
  259. const companyTrigger = page.locator('[data-testid="company-selector-create"]');
  260. if (await companyTrigger.count() > 0) {
  261. await companyTrigger.click();
  262. await page.waitForTimeout(800);
  263. const allCompanyOptions = page.getByRole('option');
  264. const companyCount = await allCompanyOptions.count();
  265. console.debug(`公司选项数量: ${companyCount}`);
  266. if (companyCount > 0) {
  267. const companyOption = allCompanyOptions.filter({ hasText: createdCompanyName }).first();
  268. const optionCount = await companyOption.count();
  269. if (optionCount > 0) {
  270. await companyOption.click();
  271. } else {
  272. console.debug(`未找到公司 ${createdCompanyName},选择第一个可用公司`);
  273. await allCompanyOptions.first().click();
  274. }
  275. } else {
  276. console.debug('公司选项列表为空');
  277. }
  278. await page.waitForTimeout(200);
  279. } else {
  280. console.debug('公司选择器未找到,跳过公司选择');
  281. }
  282. }
  283. await page.getByLabel(/预计开始日期|开始日期/).fill('2025-01-15');
  284. // 选择残疾人(必填)
  285. const hasDisabledPerson = await selectDisabledPersonInAddDialog(page);
  286. if (hasDisabledPerson) {
  287. // 提交表单
  288. const result = await orderManagementPage.submitForm();
  289. // 等待对话框关闭
  290. await orderManagementPage.waitForDialogClosed();
  291. // 验证创建成功
  292. return result.hasSuccess || !result.hasError;
  293. }
  294. // 没有残疾人数据时取消
  295. await orderManagementPage.cancelDialog();
  296. return false;
  297. }
  298. test.describe('订单详情查看测试', () => {
  299. test.beforeEach(async ({ adminLoginPage, orderManagementPage, request }) => {
  300. // 以管理员身份登录后台
  301. await adminLoginPage.goto();
  302. await adminLoginPage.login(testUsers.admin.username, testUsers.admin.password);
  303. await adminLoginPage.expectLoginSuccess();
  304. // 使用 API 创建平台和公司测试数据
  305. const createdPlatform = await createPlatformViaAPI(request);
  306. if (!createdPlatform) {
  307. console.debug('无法创建平台数据,测试可能被跳过');
  308. createdPlatformName = null;
  309. } else {
  310. createdPlatformName = createdPlatform.name;
  311. }
  312. if (createdPlatform) {
  313. const createdCompany = await createCompanyViaAPI(request, createdPlatform.id);
  314. if (!createdCompany) {
  315. console.debug('无法创建公司数据,测试可能被跳过');
  316. createdCompanyName = null;
  317. } else {
  318. createdCompanyName = createdCompany.name;
  319. }
  320. }
  321. // 使用 API 创建残疾人测试数据
  322. const testData = generateUniqueTestData();
  323. const personData = {
  324. name: testData.personName,
  325. gender: testData.gender,
  326. idCard: testData.idCard,
  327. disabilityId: testData.disabilityId,
  328. disabilityType: testData.disabilityType,
  329. disabilityLevel: testData.disabilityLevel,
  330. idAddress: testData.idAddress,
  331. phone: testData.phone,
  332. province: testData.province,
  333. city: testData.city,
  334. };
  335. const createdPerson = await createDisabledPersonViaAPI(request, personData);
  336. if (!createdPerson) {
  337. console.debug('无法创建残疾人数据,测试可能被跳过');
  338. createdPersonName = null;
  339. } else {
  340. createdPersonName = createdPerson.name;
  341. console.debug('已创建残疾人:', createdPersonName, 'ID:', createdPerson.id);
  342. }
  343. // 导航到订单管理页面
  344. await orderManagementPage.goto();
  345. });
  346. test.describe('基本订单详情查看', () => {
  347. test('应该能打开订单详情对话框', async ({ orderManagementPage, page }) => {
  348. const timestamp = Date.now();
  349. const random = Math.floor(Math.random() * 1000);
  350. const orderName = `detail_open_${timestamp}_${random}`;
  351. const created = await createTestOrder(orderManagementPage, page, orderName);
  352. // 验证订单创建成功
  353. expect(created).toBe(true);
  354. // 打开订单详情
  355. await orderManagementPage.openDetailDialog(orderName);
  356. // 验证对话框打开
  357. const dialog = page.locator('[role="dialog"]');
  358. await expect(dialog).toBeVisible();
  359. // 关闭对话框
  360. await orderManagementPage.closeDetailDialog();
  361. // 验证对话框关闭
  362. await expect(dialog).not.toBeVisible();
  363. });
  364. test('应该正确显示订单名称', async ({ orderManagementPage, page }) => {
  365. const timestamp = Date.now();
  366. const random = Math.floor(Math.random() * 1000);
  367. const orderName = `detail_name_${timestamp}_${random}`;
  368. const created = await createTestOrder(orderManagementPage, page, orderName);
  369. expect(created).toBe(true);
  370. // 打开订单详情
  371. await orderManagementPage.openDetailDialog(orderName);
  372. // 获取订单详情信息
  373. const detailInfo = await orderManagementPage.getOrderDetailInfo();
  374. // 验证订单名称显示正确
  375. expect(detailInfo.name).toBe(orderName);
  376. // 关闭对话框
  377. await orderManagementPage.closeDetailDialog();
  378. });
  379. test('应该正确显示订单状态和工作状态', async ({ orderManagementPage, page }) => {
  380. const timestamp = Date.now();
  381. const random = Math.floor(Math.random() * 1000);
  382. const orderName = `detail_status_${timestamp}_${random}`;
  383. const created = await createTestOrder(orderManagementPage, page, orderName);
  384. expect(created).toBe(true);
  385. // 打开订单详情
  386. await orderManagementPage.openDetailDialog(orderName);
  387. // 获取订单详情信息
  388. const detailInfo = await orderManagementPage.getOrderDetailInfo();
  389. // 验证订单状态显示(新创建的订单应该是草稿状态)
  390. expect(detailInfo.status).toBeTruthy();
  391. // 验证工作状态有值(可能为空字符串)
  392. expect(detailInfo.workStatus !== undefined).toBe(true);
  393. // 关闭对话框
  394. await orderManagementPage.closeDetailDialog();
  395. });
  396. test('应该正确显示预计开始日期', async ({ orderManagementPage, page }) => {
  397. const timestamp = Date.now();
  398. const random = Math.floor(Math.random() * 1000);
  399. const orderName = `detail_date_${timestamp}_${random}`;
  400. const expectedStartDate = '2025-01-15';
  401. const created = await createTestOrder(orderManagementPage, page, orderName);
  402. expect(created).toBe(true);
  403. // 打开订单详情
  404. await orderManagementPage.openDetailDialog(orderName);
  405. // 获取订单详情信息
  406. const detailInfo = await orderManagementPage.getOrderDetailInfo();
  407. // 验证预计开始日期显示正确
  408. expect(detailInfo.expectedStartDate).toBe(expectedStartDate);
  409. // 关闭对话框
  410. await orderManagementPage.closeDetailDialog();
  411. });
  412. test('应该能完整获取所有订单详情信息', async ({ orderManagementPage, page }) => {
  413. const timestamp = Date.now();
  414. const random = Math.floor(Math.random() * 1000);
  415. const orderName = `detail_full_${timestamp}_${random}`;
  416. const created = await createTestOrder(orderManagementPage, page, orderName);
  417. expect(created).toBe(true);
  418. // 打开订单详情
  419. await orderManagementPage.openDetailDialog(orderName);
  420. // 获取订单详情信息
  421. const detailInfo = await orderManagementPage.getOrderDetailInfo();
  422. // 验证基本字段有值
  423. expect(detailInfo.name).toBe(orderName);
  424. expect(detailInfo.expectedStartDate).toBe('2025-01-15');
  425. expect(detailInfo.status).toBeTruthy();
  426. // 验证工作状态字段存在(可能为空)
  427. expect(detailInfo.workStatus !== undefined).toBe(true);
  428. console.debug('订单详情信息:', detailInfo);
  429. // 关闭对话框
  430. await orderManagementPage.closeDetailDialog();
  431. });
  432. });
  433. test.describe('订单人员列表查看', () => {
  434. test('应该能获取订单详情中的人员列表', async ({ orderManagementPage, page }) => {
  435. const timestamp = Date.now();
  436. const random = Math.floor(Math.random() * 1000);
  437. const orderName = `person_list_${timestamp}_${random}`;
  438. const created = await createTestOrder(orderManagementPage, page, orderName);
  439. expect(created).toBe(true);
  440. // 打开订单详情
  441. await orderManagementPage.openDetailDialog(orderName);
  442. // 获取人员列表
  443. const personList = await orderManagementPage.getPersonListFromDetail();
  444. // 验证人员列表是数组
  445. expect(Array.isArray(personList)).toBe(true);
  446. // 列表应该至少有1人(因为创建时选择了残疾人)
  447. expect(personList.length).toBeGreaterThanOrEqual(0);
  448. console.debug(`订单 "${orderName}" 关联人员数量: ${personList.length}`);
  449. if (personList.length > 0) {
  450. console.debug('人员列表:', personList);
  451. }
  452. // 关闭对话框
  453. await orderManagementPage.closeDetailDialog();
  454. });
  455. test('应该能正确显示人员姓名', async ({ orderManagementPage, page }) => {
  456. const timestamp = Date.now();
  457. const random = Math.floor(Math.random() * 1000);
  458. const orderName = `person_name_${timestamp}_${random}`;
  459. const created = await createTestOrder(orderManagementPage, page, orderName);
  460. expect(created).toBe(true);
  461. // 打开订单详情
  462. await orderManagementPage.openDetailDialog(orderName);
  463. // 获取人员列表
  464. const personList = await orderManagementPage.getPersonListFromDetail();
  465. // 验证如果有人员,每个人都有姓名
  466. for (const person of personList) {
  467. if (person.name) {
  468. expect(typeof person.name).toBe('string');
  469. expect(person.name.length).toBeGreaterThan(0);
  470. console.debug(`人员姓名: ${person.name}`);
  471. }
  472. }
  473. // 关闭对话框
  474. await orderManagementPage.closeDetailDialog();
  475. });
  476. test('应该能正确显示人员工作状态', async ({ orderManagementPage, page }) => {
  477. const timestamp = Date.now();
  478. const random = Math.floor(Math.random() * 1000);
  479. const orderName = `person_status_${timestamp}_${random}`;
  480. const created = await createTestOrder(orderManagementPage, page, orderName);
  481. expect(created).toBe(true);
  482. // 打开订单详情
  483. await orderManagementPage.openDetailDialog(orderName);
  484. // 获取人员列表
  485. const personList = await orderManagementPage.getPersonListFromDetail();
  486. // 验证如果有人员有工作状态,状态是有效的
  487. const validWorkStatuses = ['未就业', '待就业', '已就业', '已离职'];
  488. for (const person of personList) {
  489. if (person.workStatus) {
  490. expect(validWorkStatuses).toContain(person.workStatus);
  491. console.debug(`人员工作状态: ${person.workStatus}`);
  492. }
  493. }
  494. // 关闭对话框
  495. await orderManagementPage.closeDetailDialog();
  496. });
  497. test('应该能显示人员入职日期(如有)', async ({ orderManagementPage, page }) => {
  498. const timestamp = Date.now();
  499. const random = Math.floor(Math.random() * 1000);
  500. const orderName = `person_date_${timestamp}_${random}`;
  501. const created = await createTestOrder(orderManagementPage, page, orderName);
  502. expect(created).toBe(true);
  503. // 打开订单详情
  504. await orderManagementPage.openDetailDialog(orderName);
  505. // 获取人员列表
  506. const personList = await orderManagementPage.getPersonListFromDetail();
  507. // 验证如果有人员有入职日期,格式正确
  508. const datePattern = /^\d{4}-\d{2}-\d{2}$|^\d{4}\/\d{2}\/\d{2}$/;
  509. for (const person of personList) {
  510. if (person.hireDate) {
  511. expect(person.hireDate).toMatch(datePattern);
  512. console.debug(`人员入职日期: ${person.hireDate}`);
  513. }
  514. }
  515. // 关闭对话框
  516. await orderManagementPage.closeDetailDialog();
  517. });
  518. });
  519. test.describe('订单附件查看', () => {
  520. test('应该能获取订单详情中的附件列表', async ({ orderManagementPage, page }) => {
  521. const timestamp = Date.now();
  522. const random = Math.floor(Math.random() * 1000);
  523. const orderName = `attachment_list_${timestamp}_${random}`;
  524. const created = await createTestOrder(orderManagementPage, page, orderName);
  525. expect(created).toBe(true);
  526. // 打开订单详情
  527. await orderManagementPage.openDetailDialog(orderName);
  528. // 获取附件列表
  529. const attachmentList = await orderManagementPage.getAttachmentListFromDetail();
  530. // 验证附件列表是数组
  531. expect(Array.isArray(attachmentList)).toBe(true);
  532. // 新订单没有附件,列表应该为空
  533. expect(attachmentList.length).toBeGreaterThanOrEqual(0);
  534. console.debug(`订单 "${orderName}" 附件数量: ${attachmentList.length}`);
  535. // 关闭对话框
  536. await orderManagementPage.closeDetailDialog();
  537. });
  538. test('新订单应该没有附件', async ({ orderManagementPage, page }) => {
  539. const timestamp = Date.now();
  540. const random = Math.floor(Math.random() * 1000);
  541. const orderName = `no_attachment_${timestamp}_${random}`;
  542. const created = await createTestOrder(orderManagementPage, page, orderName);
  543. expect(created).toBe(true);
  544. // 打开订单详情
  545. await orderManagementPage.openDetailDialog(orderName);
  546. // 获取附件列表
  547. const attachmentList = await orderManagementPage.getAttachmentListFromDetail();
  548. // 验证新订单没有附件时列表为空
  549. expect(attachmentList.length).toBe(0);
  550. console.debug(`订单 "${orderName}" 无附件,列表为空`);
  551. // 关闭对话框
  552. await orderManagementPage.closeDetailDialog();
  553. });
  554. });
  555. test.describe('详情对话框操作', () => {
  556. test('应该能多次打开和关闭详情对话框', async ({ orderManagementPage, page }) => {
  557. const timestamp = Date.now();
  558. const random = Math.floor(Math.random() * 1000);
  559. const orderName = `multi_close_${timestamp}_${random}`;
  560. const created = await createTestOrder(orderManagementPage, page, orderName);
  561. expect(created).toBe(true);
  562. const dialog = page.locator('[role="dialog"]');
  563. // 第一次打开和关闭
  564. await orderManagementPage.openDetailDialog(orderName);
  565. await expect(dialog).toBeVisible();
  566. await orderManagementPage.closeDetailDialog();
  567. await expect(dialog).not.toBeVisible();
  568. // 第二次打开和关闭
  569. await orderManagementPage.openDetailDialog(orderName);
  570. await expect(dialog).toBeVisible();
  571. await orderManagementPage.closeDetailDialog();
  572. await expect(dialog).not.toBeVisible();
  573. // 第三次打开和关闭
  574. await orderManagementPage.openDetailDialog(orderName);
  575. await expect(dialog).toBeVisible();
  576. await orderManagementPage.closeDetailDialog();
  577. await expect(dialog).not.toBeVisible();
  578. });
  579. test('关闭详情对话框后应该能继续操作列表', async ({ orderManagementPage, page }) => {
  580. const timestamp = Date.now();
  581. const random = Math.floor(Math.random() * 1000);
  582. const orderName = `after_close_${timestamp}_${random}`;
  583. const created = await createTestOrder(orderManagementPage, page, orderName);
  584. expect(created).toBe(true);
  585. // 打开详情
  586. await orderManagementPage.openDetailDialog(orderName);
  587. const dialog = page.locator('[role="dialog"]');
  588. await expect(dialog).toBeVisible();
  589. // 关闭详情
  590. await orderManagementPage.closeDetailDialog();
  591. await expect(dialog).not.toBeVisible();
  592. // 验证列表仍然可以操作
  593. await expect(orderManagementPage.orderTable).toBeVisible();
  594. await expect(orderManagementPage.pageTitle).toBeVisible();
  595. // 验证可以搜索
  596. await orderManagementPage.searchByName('test');
  597. await page.waitForTimeout(500);
  598. });
  599. });
  600. });