2
0

order-config-validation.spec.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. import { test, expect } from '../../utils/test-setup';
  2. /**
  3. * Story 11.9: 配置数据验证(订单可以选择平台和公司)
  4. *
  5. * **目标**: 验证 Epic 11 创建的配置管理数据(Platform、Company)能被订单正确使用
  6. *
  7. * **与 Epic 10 的区别**:
  8. * - Epic 10: 测试订单创建功能(使用现有配置数据,必须选择残疾人)
  9. * - Story 11.9: 验证 Epic 11 → Epic 10 的数据流(创建配置数据后验证订单表单可用)
  10. *
  11. * **测试重点**:
  12. * 1. 集成验证: Epic 11 创建的数据在订单表单中可选择
  13. * 2. 关联验证: 平台与公司的 1:N 关系正确
  14. * 3. 清理策略: 演示正确的数据清理顺序
  15. */
  16. test.describe('订单配置数据验证 (Epic 11 → Epic 10 集成)', () => {
  17. test.beforeEach(async ({ adminLoginPage, orderManagementPage }) => {
  18. // 以管理员身份登录后台
  19. await adminLoginPage.goto();
  20. await adminLoginPage.login('admin', 'admin123');
  21. await adminLoginPage.expectLoginSuccess();
  22. // 导航到订单管理页面
  23. await orderManagementPage.goto();
  24. });
  25. test.describe('集成验证: Epic 11 配置数据在订单表单中可选择', () => {
  26. test('应该能在订单表单中选择 Epic 11 创建的平台', async ({
  27. orderManagementPage,
  28. platformManagementPage,
  29. }) => {
  30. const timestamp = Date.now();
  31. // 步骤 1: Epic 11 - 创建测试平台
  32. const platformName = `集成测试平台_${timestamp}`;
  33. await platformManagementPage.goto();
  34. const platformResult = await platformManagementPage.createPlatform({
  35. platformName,
  36. contactPerson: `测试联系人_${timestamp}`,
  37. contactPhone: '13800138000',
  38. contactEmail: `test_${timestamp}@example.com`
  39. });
  40. expect(platformResult.responses?.[0]?.ok).toBe(true);
  41. expect(await platformManagementPage.platformExists(platformName)).toBe(true);
  42. // 步骤 2: Epic 10 - 验证平台在订单表单中可选择
  43. await orderManagementPage.goto();
  44. await orderManagementPage.openCreateDialog();
  45. // 选择平台(使用与 Epic 10 相同的选择器)
  46. const platformTrigger = orderManagementPage.page.locator('[data-testid="platform-search-select"]');
  47. await expect(platformTrigger).toBeVisible();
  48. await platformTrigger.click({ force: true });
  49. // 等待选项列表并选择创建的平台
  50. const platformOption = orderManagementPage.page.getByRole('option').filter({ hasText: platformName });
  51. await expect(platformOption).toBeVisible({ timeout: 5000 });
  52. await platformOption.click();
  53. // 填写订单名称(表单验证需要)
  54. await orderManagementPage.page.getByLabel(/订单名称|名称/).fill(`测试订单_${timestamp}`);
  55. // 验证: 平台已选择(通过检查对话框仍然打开来验证选择成功)
  56. const dialog = orderManagementPage.page.locator('[role="dialog"]');
  57. await expect(dialog).toBeVisible();
  58. // 关闭对话框(不提交,因为订单需要残疾人)
  59. await orderManagementPage.cancelDialog();
  60. // 清理: 删除平台
  61. await platformManagementPage.goto();
  62. await platformManagementPage.deletePlatform(platformName);
  63. expect(await platformManagementPage.platformExists(platformName)).toBe(false);
  64. });
  65. test('应该能在订单表单中选择 Epic 11 创建的公司', async ({
  66. orderManagementPage,
  67. platformManagementPage,
  68. companyManagementPage,
  69. }) => {
  70. const timestamp = Date.now();
  71. // 步骤 1: Epic 11 - 创建测试平台和公司
  72. const platformName = `集成测试平台_${timestamp}`;
  73. await platformManagementPage.goto();
  74. await platformManagementPage.createPlatform({
  75. platformName,
  76. contactPerson: `测试联系人_${timestamp}`,
  77. contactPhone: '13800138000',
  78. contactEmail: `test_${timestamp}@example.com`
  79. });
  80. const companyName = `集成测试公司_${timestamp}`;
  81. await companyManagementPage.goto();
  82. const companyResult = await companyManagementPage.createCompany({
  83. companyName
  84. }, platformName);
  85. expect(companyResult.responses?.[0]?.ok).toBe(true);
  86. expect(await companyManagementPage.companyExists(companyName)).toBe(true);
  87. // 步骤 2: Epic 10 - 验证公司在订单表单中可选择
  88. await orderManagementPage.goto();
  89. await orderManagementPage.openCreateDialog();
  90. // 选择公司
  91. const companyTrigger = orderManagementPage.page.locator('[data-testid="company-search-select"]');
  92. await expect(companyTrigger).toBeVisible();
  93. await companyTrigger.click({ force: true });
  94. // 等待选项列表并选择创建的公司
  95. const companyOption = orderManagementPage.page.getByRole('option').filter({ hasText: companyName });
  96. await expect(companyOption).toBeVisible({ timeout: 5000 });
  97. await companyOption.click();
  98. // 填写订单名称
  99. await orderManagementPage.page.getByLabel(/订单名称|名称/).fill(`测试订单_${timestamp}`);
  100. // 验证: 对话框仍然打开
  101. const dialog = orderManagementPage.page.locator('[role="dialog"]');
  102. await expect(dialog).toBeVisible();
  103. // 关闭对话框
  104. await orderManagementPage.cancelDialog();
  105. // 清理: 公司 → 平台
  106. await companyManagementPage.goto();
  107. await companyManagementPage.deleteCompany(companyName);
  108. await platformManagementPage.goto();
  109. await platformManagementPage.deletePlatform(platformName);
  110. });
  111. test('应该能在订单表单中同时选择平台和公司', async ({
  112. orderManagementPage,
  113. platformManagementPage,
  114. companyManagementPage,
  115. }) => {
  116. const timestamp = Date.now();
  117. // 创建测试数据
  118. const platformName = `集成测试平台_${timestamp}`;
  119. const companyName = `集成测试公司_${timestamp}`;
  120. await platformManagementPage.goto();
  121. await platformManagementPage.createPlatform({
  122. platformName,
  123. contactPerson: `测试联系人_${timestamp}`,
  124. contactPhone: '13800138000',
  125. contactEmail: `test_${timestamp}@example.com`
  126. });
  127. await companyManagementPage.goto();
  128. await companyManagementPage.createCompany({
  129. companyName
  130. }, platformName);
  131. // 验证: 在订单表单中同时选择平台和公司
  132. await orderManagementPage.goto();
  133. await orderManagementPage.openCreateDialog();
  134. // 选择平台
  135. const platformTrigger = orderManagementPage.page.locator('[data-testid="platform-search-select"]');
  136. await expect(platformTrigger).toBeVisible();
  137. await platformTrigger.click({ force: true });
  138. const platformOption = orderManagementPage.page.getByRole('option').filter({ hasText: platformName });
  139. await expect(platformOption).toBeVisible({ timeout: 5000 });
  140. await platformOption.click();
  141. // 选择公司
  142. const companyTrigger = orderManagementPage.page.locator('[data-testid="company-search-select"]');
  143. await expect(companyTrigger).toBeVisible();
  144. await companyTrigger.click({ force: true });
  145. const companyOption = orderManagementPage.page.getByRole('option').filter({ hasText: companyName });
  146. await expect(companyOption).toBeVisible({ timeout: 5000 });
  147. await companyOption.click();
  148. // 填写订单名称
  149. await orderManagementPage.page.getByLabel(/订单名称|名称/).fill(`测试订单_${timestamp}`);
  150. // 验证: 对话框仍然打开(说明两个选择都成功了)
  151. const dialog = orderManagementPage.page.locator('[role="dialog"]');
  152. await expect(dialog).toBeVisible();
  153. // 关闭对话框
  154. await orderManagementPage.cancelDialog();
  155. // 清理: 公司 → 平台
  156. await companyManagementPage.goto();
  157. await companyManagementPage.deleteCompany(companyName);
  158. await platformManagementPage.goto();
  159. await platformManagementPage.deletePlatform(platformName);
  160. });
  161. });
  162. test.describe('关联验证: 平台与公司的 1:N 关系', () => {
  163. test('同一平台下的多个公司都应该能在订单表单中选择', async ({
  164. orderManagementPage,
  165. platformManagementPage,
  166. companyManagementPage,
  167. }) => {
  168. const timestamp = Date.now();
  169. // 创建测试平台
  170. const platformName = `关联验证平台_${timestamp}`;
  171. await platformManagementPage.goto();
  172. await platformManagementPage.createPlatform({
  173. platformName,
  174. contactPerson: `测试联系人_${timestamp}`,
  175. contactPhone: '13800138000',
  176. contactEmail: `test_${timestamp}@example.com`
  177. });
  178. // 创建同一平台下的多个公司
  179. const companyNames = [
  180. `关联公司_A_${timestamp}`,
  181. `关联公司_B_${timestamp}`,
  182. ];
  183. for (const companyName of companyNames) {
  184. await companyManagementPage.goto();
  185. await companyManagementPage.createCompany({ companyName }, platformName);
  186. }
  187. // 验证: 每个公司都能在订单表单中选择
  188. for (const companyName of companyNames) {
  189. await orderManagementPage.goto();
  190. await orderManagementPage.openCreateDialog();
  191. // 选择公司
  192. const companyTrigger = orderManagementPage.page.locator('[data-testid="company-search-select"]');
  193. await expect(companyTrigger).toBeVisible();
  194. await companyTrigger.click({ force: true });
  195. const companyOption = orderManagementPage.page.getByRole('option').filter({ hasText: companyName });
  196. await expect(companyOption).toBeVisible({ timeout: 5000 });
  197. await companyOption.click();
  198. // 填写订单名称
  199. await orderManagementPage.page.getByLabel(/订单名称|名称/).fill(`订单_${companyName}`);
  200. // 验证: 对话框仍然打开
  201. const dialog = orderManagementPage.page.locator('[role="dialog"]');
  202. await expect(dialog).toBeVisible();
  203. // 关闭对话框
  204. await orderManagementPage.cancelDialog();
  205. }
  206. // 清理: 所有公司 → 平台
  207. await companyManagementPage.goto();
  208. for (const companyName of companyNames) {
  209. await companyManagementPage.deleteCompany(companyName);
  210. }
  211. await platformManagementPage.goto();
  212. await platformManagementPage.deletePlatform(platformName);
  213. });
  214. });
  215. test.describe('清理策略: 演示正确的数据清理顺序', () => {
  216. test('应该按正确顺序清理测试数据(公司→平台)', async ({
  217. platformManagementPage,
  218. companyManagementPage,
  219. }) => {
  220. const timestamp = Date.now();
  221. // 创建完整的测试数据链
  222. const platformName = `清理验证平台_${timestamp}`;
  223. const companyName = `清理验证公司_${timestamp}`;
  224. await platformManagementPage.goto();
  225. await platformManagementPage.createPlatform({
  226. platformName,
  227. contactPerson: `测试联系人_${timestamp}`,
  228. contactPhone: '13800138000',
  229. contactEmail: `test_${timestamp}@example.com`
  230. });
  231. await companyManagementPage.goto();
  232. await companyManagementPage.createCompany({ companyName }, platformName);
  233. // 验证所有数据存在
  234. await companyManagementPage.goto();
  235. expect(await companyManagementPage.companyExists(companyName)).toBe(true);
  236. await platformManagementPage.goto();
  237. expect(await platformManagementPage.platformExists(platformName)).toBe(true);
  238. // 清理步骤 1: 删除公司(依赖平台)
  239. await companyManagementPage.goto();
  240. await companyManagementPage.deleteCompany(companyName);
  241. expect(await companyManagementPage.companyExists(companyName)).toBe(false);
  242. // 清理步骤 2: 删除平台(无依赖)
  243. await platformManagementPage.goto();
  244. await platformManagementPage.deletePlatform(platformName);
  245. expect(await platformManagementPage.platformExists(platformName)).toBe(false);
  246. });
  247. });
  248. });