You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

646 regels
41 KiB

  1. import type { Locator, Page } from '@playwright/test'
  2. import { captureScreenshot, expect, test } from './fixtures'
  3. import { TeachingContractMock } from './teaching-contract-mock'
  4. const visibleDialog = (page: Page) => page.locator('.el-dialog:visible').last()
  5. const chooseSelectOption = async (page: Page, scope: Locator, label: string, option: string) => {
  6. const formSelect = scope.locator('.el-form-item').filter({ hasText: label }).first().locator('.el-select')
  7. const select = await formSelect.count()
  8. ? formSelect
  9. : scope.locator('.el-select').filter({ hasText: label }).first()
  10. await select.click()
  11. const dropdown = page.locator('.el-select-dropdown:visible').last()
  12. await expect(dropdown.getByText(option, { exact: true })).toBeVisible()
  13. await dropdown.getByText(option, { exact: true }).click()
  14. }
  15. const switchIdentity = async (page: Page, contract: TeachingContractMock, identity: Parameters<TeachingContractMock['setIdentity']>[0]) => {
  16. contract.setIdentity(identity)
  17. await page.reload()
  18. }
  19. test.describe('教学实施模块状态化 UI 契约', () => {
  20. test('六个侧栏入口可达,指导书和训练记录可在模块内完成完整往返', async ({ page }, testInfo) => {
  21. await page.setViewportSize({ width: 1920, height: 1080 })
  22. const contract = new TeachingContractMock('admin')
  23. contract.seedVirtualReviewedRun()
  24. await contract.install(page)
  25. const entries = [
  26. ['/teaching/virtual-training', '虚拟仿真任务管理'],
  27. ['/teaching/physical-training', '实装实训任务管理'],
  28. ['/teaching/confrontation', '对抗训练任务管理'],
  29. ['/teaching/immersive', '沉浸交互与外设联调'],
  30. ['/teaching/exams', '考试测评'],
  31. ['/teaching/data-center', '教学数据中心'],
  32. ] as const
  33. for (const [path, heading] of entries) {
  34. await page.goto(path)
  35. await expect(page.getByRole('heading', { name: heading, exact: true })).toBeVisible()
  36. await expect(page.getByTestId('teaching-dashboard-hero').or(page.locator('.ttc-hero'))).toBeVisible()
  37. await expect(page.locator('iframe')).toHaveCount(0)
  38. }
  39. await page.goto('/teaching/virtual-training')
  40. await page.getByTestId('teaching-tab-guides').click()
  41. await expect(page).toHaveURL(/\/teaching\/virtual-training\?view=guides$/)
  42. await expect(page.getByRole('heading', { name: '虚拟仿真作业指导书', exact: true })).toBeVisible()
  43. await expect(page.getByTestId('teaching-guide-library').locator('.guide-card-v2')).toHaveCount(1)
  44. await page.getByRole('button', { name: /打开阅读/ }).first().click()
  45. const guideReader = page.locator('.guide-reader-v2')
  46. await expect(guideReader).toBeVisible()
  47. await expect(guideReader).toContainText('01 安全准备')
  48. await expect(guideReader).toContainText('断电隔离')
  49. await guideReader.getByRole('button', { name: '下一步', exact: true }).click()
  50. await expect(guideReader.getByRole('heading', { name: '压力释放', exact: true })).toBeVisible()
  51. await expect(guideReader).toContainText('目标压力')
  52. await guideReader.getByRole('button', { name: '下一步', exact: true }).click()
  53. await expect(guideReader.getByRole('heading', { name: '复装与复测', exact: true })).toBeVisible()
  54. await expect(guideReader.getByRole('button', { name: '下一步', exact: true })).toBeDisabled()
  55. await captureScreenshot(page, testInfo, 'teaching-guide-full-reader')
  56. await page.getByRole('button', { name: /返回指导书列表/ }).click()
  57. await expect(page.locator('.guide-list-card')).toBeVisible()
  58. await page.getByTestId('teaching-tab-tasks').click()
  59. await expect(page).toHaveURL(/\/teaching\/virtual-training$/)
  60. await expect(page.getByTestId('teaching-assignment-TASK-VIRTUAL-001')).toBeVisible()
  61. await page.getByTestId('teaching-tab-records').click()
  62. await expect(page).toHaveURL(/\/teaching\/virtual-training\?view=records$/)
  63. await expect(page.locator('.ttc-record-table')).toBeVisible()
  64. await expect(page.locator('.ttc-record-table tbody tr')).toHaveCount(1)
  65. await page.getByRole('button', { name: '查看详情', exact: true }).first().click()
  66. const recordDialog = visibleDialog(page)
  67. await expect(recordDialog).toContainText('详情页仅展示任务结果与步骤快照')
  68. await expect(recordDialog).toContainText('92 分')
  69. await expect(recordDialog).toContainText('2 / 2')
  70. await captureScreenshot(page, testInfo, 'teaching-training-record-detail')
  71. await recordDialog.getByRole('button', { name: /返回记录列表/ }).click()
  72. await expect(page.locator('.ttc-record-table')).toBeVisible()
  73. await page.getByRole('button', { name: '完整过程', exact: true }).first().click()
  74. await expect(page).toHaveURL(/\/teaching\/virtual-training\/runs\/run-virtual-reviewed\?returnView=records&observe=1$/)
  75. await expect(page.locator('.teaching-runtime-v2')).toBeVisible()
  76. await expect(page.getByText('当前为教员/管理员观察席', { exact: true })).toBeVisible()
  77. await expect(page.getByText('完成:识别作业对象', { exact: true })).toBeVisible()
  78. await expect(page.getByRole('button', { name: /完成|提交训练结果|开始训练/ })).toHaveCount(0)
  79. await captureScreenshot(page, testInfo, 'teaching-training-record-full-process')
  80. await page.locator('.runtime-back').click()
  81. await expect(page).toHaveURL(/\/teaching\/virtual-training\?view=records$/)
  82. await expect(page.locator('.ttc-record-table')).toBeVisible()
  83. await page.getByTestId('teaching-tab-tasks').click()
  84. await expect(page).toHaveURL(/\/teaching\/virtual-training$/)
  85. await expect(page.locator('iframe')).toHaveCount(0)
  86. await captureScreenshot(page, testInfo, 'teaching-module-guide-record-roundtrip')
  87. })
  88. test('对抗任务监控可切换运行、进入三维只读观察并按最终 API 契约注入故障', async ({ page }, testInfo) => {
  89. await page.setViewportSize({ width: 1920, height: 1080 })
  90. const contract = new TeachingContractMock('teacher')
  91. contract.seedConfrontationMonitorRuns()
  92. await contract.install(page)
  93. await page.goto('/teaching/confrontation')
  94. await page.getByTestId('teaching-monitor-TASK-CONFRONTATION-001').click()
  95. await expect(page).toHaveURL(/\/teaching\/confrontation\/tasks\/assignment-confrontation\/monitor$/)
  96. const monitor = page.getByTestId('confrontation-monitor')
  97. await expect(monitor).toBeVisible()
  98. await expect(monitor.locator('.monitor-run-list button')).toHaveCount(2)
  99. await expect(page.getByTestId('confrontation-monitor-scene').locator('canvas')).toBeVisible({ timeout: 30_000 })
  100. await expect(page.getByTestId('confrontation-monitor-run-run-confrontation')).toHaveClass(/active/)
  101. await expect(page.getByTestId('confrontation-monitor-run-run-confrontation')).toContainText('RED')
  102. await page.getByTestId('confrontation-monitor-run-run-confrontation-blue').click()
  103. await expect(page.getByTestId('confrontation-monitor-run-run-confrontation-blue')).toHaveClass(/active/)
  104. await expect(page.getByTestId('confrontation-monitor-run-run-confrontation-blue')).toContainText('BLUE')
  105. await expect(monitor.locator('.monitor-event-timeline')).toContainText('尚未产生过程事件')
  106. await captureScreenshot(page, testInfo, 'teaching-confrontation-monitor-switch')
  107. await page.getByTestId('confrontation-monitor-inject').click()
  108. const injectionDialog = visibleDialog(page)
  109. await expect(injectionDialog).toContainText('故障真值仅写入服务端私密载荷')
  110. const publicSummary = '训练设备出现动臂响应迟缓与压力波动,请按岗位流程排查。'
  111. await injectionDialog.locator('textarea').fill(publicSummary)
  112. await injectionDialog.getByRole('button', { name: '确认注入', exact: true }).click()
  113. await expect(injectionDialog).toBeHidden()
  114. await expect(monitor.locator('.monitor-interventions')).toContainText(publicSummary)
  115. const createIntervention = contract.last('POST', '/assignments/assignment-confrontation/interventions')
  116. expect(createIntervention?.body).toMatchObject({
  117. type: 'FAULT',
  118. targetScope: 'ASSIGNMENT',
  119. publicSummary,
  120. publicPayload: { assignmentFaultId: 'assignment-fault-public', faultCode: 'HYDRAULIC.VALVE.STUCK' },
  121. privatePayload: {
  122. assignmentFaultId: 'assignment-fault-public',
  123. faultCode: 'HYDRAULIC.VALVE.STUCK',
  124. privateTruth: { text: '液压阀芯卡滞真值' },
  125. },
  126. })
  127. expect(JSON.stringify(createIntervention?.body.publicPayload)).not.toContain('液压阀芯卡滞真值')
  128. expect(contract.count('POST', /\/interventions\/[^/]+\/activate$/)).toBe(1)
  129. await page.getByTestId('confrontation-monitor-run-run-confrontation').click()
  130. await page.getByTestId('confrontation-monitor-observe').click()
  131. await expect(page).toHaveURL(/\/teaching\/confrontation\/runs\/run-confrontation\?observe=1$/)
  132. const observerWorkbench = page.locator('.teaching-runtime-v2[data-channel="confrontation"]')
  133. await expect(observerWorkbench).toBeVisible()
  134. await expect(observerWorkbench.getByText('只读观察', { exact: true })).toBeVisible()
  135. await expect(observerWorkbench.getByText('当前为教员/管理员观察席', { exact: true })).toBeVisible()
  136. await expect(observerWorkbench.locator('.runtime-stage-card canvas')).toBeVisible({ timeout: 30_000 })
  137. await expect(observerWorkbench.getByRole('button', { name: /提交岗位动作|完成当前岗位动作|提交团队结果/ })).toHaveCount(0)
  138. await captureScreenshot(page, testInfo, 'teaching-confrontation-observer-runtime')
  139. })
  140. test('虚拟、实装、对抗三通道运行工作台结构完整,正式考核仅投影当前步骤并锁定辅助能力', async ({ page }, testInfo) => {
  141. await page.setViewportSize({ width: 1920, height: 1080 })
  142. const contract = new TeachingContractMock('studentLeader')
  143. contract.seedImmersiveRun()
  144. await contract.install(page)
  145. const workbenchCases = [
  146. {
  147. path: '/teaching/virtual-training/runs/run-immersive',
  148. channel: 'virtual',
  149. expected: ['虚拟仿真 · 训练工作台', '数字教员', '规则检测目标'],
  150. screenshot: 'teaching-runtime-virtual-workbench',
  151. },
  152. {
  153. path: '/teaching/physical-training/runs/run-physical',
  154. channel: 'physical',
  155. expected: ['实装实训 · 训练工作台', '现场事件接入', '当前事件通道'],
  156. screenshot: 'teaching-runtime-physical-workbench',
  157. },
  158. {
  159. path: '/teaching/confrontation/runs/run-confrontation',
  160. channel: 'confrontation',
  161. expected: ['对抗训练 · 训练工作台', '团队与岗位', '故障与异常'],
  162. screenshot: 'teaching-runtime-confrontation-workbench',
  163. },
  164. ] as const
  165. for (const item of workbenchCases) {
  166. await page.goto(item.path)
  167. const workbench = page.locator(`.teaching-runtime-v2[data-channel="${item.channel}"]`)
  168. await expect(workbench).toBeVisible()
  169. await expect(workbench.locator('.runtime-left-rail')).toBeVisible()
  170. await expect(workbench.locator('.runtime-stage-card canvas')).toBeVisible({ timeout: 30_000 })
  171. await expect(workbench.locator('.runtime-right-rail')).toBeVisible()
  172. await expect(workbench.locator('.runtime-operation-dock')).toBeVisible()
  173. for (const copy of item.expected) await expect(workbench.getByText(copy, { exact: true }).first()).toBeVisible()
  174. await expect(workbench.locator('iframe')).toHaveCount(0)
  175. await captureScreenshot(page, testInfo, item.screenshot)
  176. }
  177. await page.goto('/teaching/exams/runs/run-exam')
  178. const examWorkbench = page.locator('.teaching-runtime-v2[data-formal-exam="true"]')
  179. await expect(examWorkbench).toBeVisible()
  180. await expect(examWorkbench.getByText('正式考核保护已启用', { exact: true })).toBeVisible()
  181. await expect(examWorkbench.locator('.runtime-step-rail li')).toHaveCount(1)
  182. await expect(examWorkbench.locator('.runtime-step-rail>header')).toContainText('1 / 2')
  183. await expect(examWorkbench.getByRole('button', { name: /操作帮助|过程记录|上一步|回放|演示|提示/ })).toHaveCount(0)
  184. await expect(examWorkbench.locator('.digital-instructor-card')).toHaveCount(0)
  185. await expect.poll(() => contract.count('GET', '/runs/run-exam/execution')).toBeGreaterThan(0)
  186. await captureScreenshot(page, testInfo, 'teaching-runtime-formal-exam-lock')
  187. })
  188. test('沉浸交互的本地按键配置可保存、刷新恢复并一键回到默认值', async ({ page }, testInfo) => {
  189. await page.setViewportSize({ width: 1920, height: 1080 })
  190. const contract = new TeachingContractMock('studentLeader')
  191. contract.seedImmersiveRun()
  192. contract.keepOnlyRuns('run-immersive')
  193. await contract.install(page)
  194. await page.goto('/teaching/immersive')
  195. const mappingPanel = page.locator('.xr-v2-mapping-panel')
  196. await expect(mappingPanel).toBeVisible()
  197. const triggerMapping = mappingPanel.locator('label').filter({ hasText: '扳机键' })
  198. await triggerMapping.locator('.el-select').click()
  199. await page.locator('.el-select-dropdown:visible').last().getByText('确认当前操作', { exact: true }).click()
  200. await page.getByRole('button', { name: '保存本地配置', exact: true }).click()
  201. const saved = await page.evaluate(() => JSON.parse(window.localStorage.getItem('unreal-tran:teaching-xr-preferences:v1') || '{}') as { interactionMode?: string; mappings?: Record<string, string> })
  202. expect(saved).toMatchObject({ interactionMode: 'DESKTOP', mappings: { trigger: '确认当前操作' } })
  203. await expect(page.getByText('本地交互配置已保存', { exact: true }).first()).toBeVisible()
  204. await captureScreenshot(page, testInfo, 'teaching-immersive-local-config-saved')
  205. await page.reload()
  206. const restoredPanel = page.locator('.xr-v2-mapping-panel')
  207. const restoredTrigger = restoredPanel.locator('label').filter({ hasText: '扳机键' })
  208. await expect(restoredTrigger.locator('.el-select')).toContainText('确认当前操作')
  209. await restoredPanel.getByRole('button', { name: '恢复默认', exact: true }).click()
  210. await expect(restoredTrigger.locator('.el-select')).toContainText('抓取 / 释放零件')
  211. expect(await page.evaluate(() => window.localStorage.getItem('unreal-tran:teaching-xr-preferences:v1'))).toBeNull()
  212. await expect(page.getByTestId('immersive-event-log')).toContainText('本地交互配置已恢复默认')
  213. await captureScreenshot(page, testInfo, 'teaching-immersive-local-config-restored')
  214. })
  215. test('纯行政只读加载任务时不请求 runs,数据中心仅展示部门聚合', async ({ page }, testInfo) => {
  216. const contract = new TeachingContractMock('administrative')
  217. await contract.install(page)
  218. await page.goto('/teaching/virtual-training')
  219. await expect(page.getByText('虚拟维修训练', { exact: true })).toBeVisible()
  220. await expect(page.getByText('部门范围只读', { exact: true })).toBeVisible()
  221. await expect(page.getByRole('button', { name: /新建任务/ })).toHaveCount(0)
  222. expect(contract.count('GET', '/runs')).toBe(0)
  223. expect(contract.administrativeRunsRejected).toBe(0)
  224. await page.getByRole('button', { name: '查看', exact: true }).click()
  225. const drawer = page.locator('.el-drawer:visible')
  226. await expect(drawer).toContainText('虚拟维修训练')
  227. await expect(drawer.getByText('执行与评定记录', { exact: true })).toHaveCount(0)
  228. await expect(drawer.getByRole('button', { name: '查看运行' })).toHaveCount(0)
  229. expect(contract.count('GET', /\/runs$/)).toBe(0)
  230. await page.goto('/teaching/data-center')
  231. await expect(page.getByText('部门范围只读汇总', { exact: true })).toBeVisible()
  232. await expect(page.getByTestId('analytics-learner-table')).toHaveCount(0)
  233. expect(contract.count('GET', '/analytics/records')).toBe(0)
  234. expect(contract.administrativeAnalyticsRecordsRejected).toBe(0)
  235. await captureScreenshot(page, testInfo, 'teaching-administrative-readonly')
  236. })
  237. test('UNION 行政加学员可识别本人运行,并完成 COMMON 领取到教员评定闭环', async ({ page }, testInfo) => {
  238. const contract = new TeachingContractMock('unionAdministrativeStudent')
  239. const definition = contract.assignments.get('assignment-virtual-common')?.definitionSnapshot as { steps: Array<Record<string, unknown>> }
  240. expect(definition.steps.every((step) => typeof step.stepCode === 'string' && !('code' in step) && !('id' in step))).toBe(true)
  241. await contract.install(page)
  242. await page.goto('/teaching/virtual-training')
  243. await expect(page.getByText('虚拟维修训练', { exact: true })).toBeVisible()
  244. await expect(page.getByText('部门范围只读', { exact: true })).toHaveCount(0)
  245. await page.getByRole('button', { name: '领取任务', exact: true }).click()
  246. await expect(page).toHaveURL(/\/teaching\/virtual-training\/runs\/run-virtual-common$/)
  247. await expect(page.getByRole('button', { name: '开始训练', exact: true })).toBeVisible()
  248. const acceptRequest = contract.last('POST', '/assignments/assignment-virtual-common/accept')
  249. expect(acceptRequest?.body).toEqual({
  250. assignmentVersion: 3,
  251. teamCode: 'NEUTRAL',
  252. groupCode: 'INDIVIDUAL',
  253. positionCode: 'LEARNER',
  254. })
  255. await page.getByRole('button', { name: '开始训练', exact: true }).click()
  256. await page.getByRole('button', { name: '完成并进入下一步', exact: true }).click()
  257. await expect(page.getByRole('button', { name: '完成当前步骤', exact: true })).toBeVisible()
  258. await page.getByRole('button', { name: '完成当前步骤', exact: true }).click()
  259. await expect(page.getByRole('button', { name: '提交训练结果', exact: true })).toBeVisible()
  260. const progressRequests = contract.requests.filter((item) => item.method === 'PUT' && item.path === '/runs/run-virtual-common/progress')
  261. expect(progressRequests).toHaveLength(2)
  262. expect(progressRequests.map((item) => item.body.completedStepCode)).toEqual(['STEP-01', 'STEP-02'])
  263. for (const request of progressRequests) {
  264. expect(request.body).not.toHaveProperty('percent')
  265. expect(request.body).not.toHaveProperty('currentStepCode')
  266. }
  267. await page.getByRole('button', { name: '提交训练结果', exact: true }).click()
  268. await visibleDialog(page).getByRole('button', { name: '确认提交', exact: true }).click()
  269. await expect(page.getByText('待评定', { exact: true }).first()).toBeVisible()
  270. expect(contract.runs.get('run-virtual-common')?.status).toBe('SUBMITTED')
  271. await page.goto('/teaching/data-center')
  272. await expect.poll(() => contract.count('GET', '/analytics/records')).toBeGreaterThan(0)
  273. expect(contract.last('GET', '/analytics/records')?.query.get('userId')).toBe('4')
  274. await expect(page.locator('.teaching-v2-filter-toolbar').getByText('全部部门', { exact: true })).toHaveCount(0)
  275. await expect(page.locator('.teaching-v2-filter-toolbar').getByText('全部学员', { exact: true })).toHaveCount(0)
  276. await switchIdentity(page, contract, 'teacher')
  277. await page.goto('/teaching/virtual-training')
  278. await page.getByRole('button', { name: '查看', exact: true }).click()
  279. const drawer = page.locator('.el-drawer:visible')
  280. await expect(drawer.getByRole('button', { name: '评定', exact: true })).toBeVisible()
  281. await drawer.getByRole('button', { name: '评定', exact: true }).click()
  282. await visibleDialog(page).getByRole('button', { name: '提交评定', exact: true }).click()
  283. await expect(page.getByText('评定结果已提交', { exact: true })).toBeVisible()
  284. expect(contract.runs.get('run-virtual-common')?.status).toBe('REVIEWED')
  285. expect(contract.count('POST', '/runs/run-virtual-common/review')).toBe(1)
  286. await captureScreenshot(page, testInfo, 'teaching-common-stateful-review')
  287. })
  288. test('无评定权限不显示超时入口,教员可将超时运行结算后评定', async ({ page }, testInfo) => {
  289. const contract = new TeachingContractMock('administrative')
  290. contract.seedExpiredRun()
  291. await contract.install(page)
  292. await page.goto('/teaching/virtual-training')
  293. await page.getByRole('button', { name: '查看', exact: true }).click()
  294. await expect(page.locator('.el-drawer:visible').getByRole('button', { name: '超时结算', exact: true })).toHaveCount(0)
  295. expect(contract.count('POST', '/runs/run-timeout/timeout')).toBe(0)
  296. await switchIdentity(page, contract, 'teacher')
  297. await page.getByRole('button', { name: '查看', exact: true }).click()
  298. const drawer = page.locator('.el-drawer:visible')
  299. await expect(drawer.getByRole('button', { name: '超时结算', exact: true })).toBeVisible()
  300. await expect(drawer.getByRole('button', { name: '结束运行', exact: true })).toHaveCount(0)
  301. await drawer.getByRole('button', { name: '超时结算', exact: true }).click()
  302. const timeoutDialog = visibleDialog(page)
  303. await expect(timeoutDialog.getByRole('heading', { name: '确认超时结算', exact: true })).toBeVisible()
  304. await expect(timeoutDialog).toContainText('结算后该运行进入待评定状态')
  305. await timeoutDialog.getByRole('button', { name: '确认结算', exact: true }).click()
  306. await expect(page.getByText('运行已超时结算,可继续进行评定', { exact: true })).toBeVisible()
  307. await expect(timeoutDialog).toBeHidden()
  308. await expect(drawer.locator('.el-loading-mask:visible')).toHaveCount(0)
  309. expect(contract.last('POST', '/runs/run-timeout/timeout')?.body).toEqual({ version: 2 })
  310. expect(contract.runs.get('run-timeout')?.status).toBe('SUBMITTED')
  311. await expect(drawer.getByRole('button', { name: '评定', exact: true })).toBeVisible()
  312. await drawer.getByRole('button', { name: '评定', exact: true }).click()
  313. await visibleDialog(page).getByRole('button', { name: '提交评定', exact: true }).click()
  314. await expect(page.getByText('评定结果已提交', { exact: true })).toBeVisible()
  315. expect(contract.runs.get('run-timeout')?.status).toBe('REVIEWED')
  316. expect(contract.last('POST', '/runs/run-timeout/review')?.body).toMatchObject({ version: 3, score: 80, passed: true })
  317. await captureScreenshot(page, testInfo, 'teaching-timeout-settlement-review')
  318. })
  319. test('教员可填写原因中途结束未超时运行并继续评定', async ({ page }, testInfo) => {
  320. const contract = new TeachingContractMock('teacher')
  321. contract.seedTerminableRun()
  322. await contract.install(page)
  323. await page.goto('/teaching/virtual-training')
  324. await page.getByRole('button', { name: '查看', exact: true }).click()
  325. const drawer = page.locator('.el-drawer:visible')
  326. await expect(drawer.getByRole('button', { name: '超时结算', exact: true })).toHaveCount(0)
  327. await expect(drawer.getByRole('button', { name: '结束运行', exact: true })).toBeVisible()
  328. await drawer.getByRole('button', { name: '结束运行', exact: true }).click()
  329. const terminateDialog = visibleDialog(page)
  330. await expect(terminateDialog.getByRole('heading', { name: '结束运行', exact: true })).toBeVisible()
  331. await expect(terminateDialog).toContainText('人工中止')
  332. await terminateDialog.getByRole('button', { name: '确认结束', exact: true }).click()
  333. expect(contract.count('POST', '/runs/run-terminate/terminate')).toBe(0)
  334. await expect(terminateDialog).toBeVisible()
  335. const reason = '现场安全条件不满足,教员人工结束运行。'
  336. await terminateDialog.getByPlaceholder('请输入结束运行原因').fill(reason)
  337. await terminateDialog.getByRole('button', { name: '确认结束', exact: true }).click()
  338. await expect(page.getByText('运行已结束并进入待评定状态', { exact: true })).toBeVisible()
  339. await expect(terminateDialog).toBeHidden()
  340. await expect(drawer.locator('.el-loading-mask:visible')).toHaveCount(0)
  341. expect(contract.last('POST', '/runs/run-terminate/terminate')?.body).toEqual({ version: 2, reason })
  342. expect(contract.runs.get('run-terminate')?.status).toBe('SUBMITTED')
  343. await expect(drawer.getByRole('button', { name: '评定', exact: true })).toBeVisible()
  344. await drawer.getByRole('button', { name: '评定', exact: true }).click()
  345. await visibleDialog(page).getByRole('button', { name: '提交评定', exact: true }).click()
  346. await expect(page.getByText('评定结果已提交', { exact: true })).toBeVisible()
  347. expect(contract.runs.get('run-terminate')?.status).toBe('REVIEWED')
  348. expect(contract.last('POST', '/runs/run-terminate/review')?.body).toMatchObject({ version: 3, score: 80, passed: true })
  349. await captureScreenshot(page, testInfo, 'teaching-terminate-settlement-review')
  350. })
  351. test('对抗未开训运行可人工结束,已开训运行只能走回合超时结算', async ({ page }, testInfo) => {
  352. const contract = new TeachingContractMock('teacher')
  353. contract.seedConfrontationTerminationCases()
  354. await contract.install(page)
  355. await page.goto('/teaching/confrontation')
  356. await page.getByRole('button', { name: '查看', exact: true }).click()
  357. const drawer = page.locator('.el-drawer:visible')
  358. const activeRow = drawer.getByRole('row').filter({ hasText: '进行中' })
  359. await expect(activeRow.getByRole('button', { name: '超时结算', exact: true })).toBeVisible()
  360. await expect(activeRow.getByRole('button', { name: '结束运行', exact: true })).toHaveCount(0)
  361. const acceptedRow = drawer.getByRole('row').filter({ hasText: '待开始' })
  362. await expect(acceptedRow.getByRole('button', { name: '超时结算', exact: true })).toHaveCount(0)
  363. await acceptedRow.getByRole('button', { name: '结束运行', exact: true }).click()
  364. const dialog = visibleDialog(page)
  365. const reason = '对抗编组条件未就绪,开训前结束本次运行。'
  366. await dialog.getByPlaceholder('请输入结束运行原因').fill(reason)
  367. await dialog.getByRole('button', { name: '确认结束', exact: true }).click()
  368. await expect(page.getByText('运行已结束并进入待评定状态', { exact: true })).toBeVisible()
  369. await expect(dialog).toBeHidden()
  370. await expect(drawer.locator('.el-loading-mask:visible')).toHaveCount(0)
  371. expect(contract.last('POST', '/runs/run-confrontation-queued/terminate')?.body).toEqual({ version: 2, reason })
  372. expect(contract.runs.get('run-confrontation-queued')?.status).toBe('SUBMITTED')
  373. expect(contract.count('POST', '/runs/run-confrontation/terminate')).toBe(0)
  374. const submittedRow = drawer.getByRole('row').filter({ hasText: '待评定' })
  375. await submittedRow.getByRole('button', { name: '评定', exact: true }).click()
  376. await visibleDialog(page).getByRole('button', { name: '提交评定', exact: true }).click()
  377. await expect(page.getByText('评定结果已提交', { exact: true })).toBeVisible()
  378. expect(contract.runs.get('run-confrontation-queued')?.status).toBe('REVIEWED')
  379. await captureScreenshot(page, testInfo, 'teaching-confrontation-prestart-terminate')
  380. })
  381. test('实装训练两步只走 physical-events,服务端响应驱动下一待办步骤', async ({ page }, testInfo) => {
  382. const contract = new TeachingContractMock('studentLeader')
  383. await contract.install(page)
  384. await page.goto('/teaching/physical-training/runs/run-physical')
  385. await expect(page.getByText('现场事件接入', { exact: true })).toBeVisible()
  386. await page.getByRole('button', { name: '开始训练', exact: true }).click()
  387. const confirm = page.getByRole('button', { name: '确认已完成当前实装步骤', exact: true })
  388. await expect(confirm).toBeVisible()
  389. await confirm.click()
  390. await expect(page.getByText('确认液压卸压', { exact: true })).toBeVisible()
  391. await confirm.click()
  392. await expect(page.getByRole('button', { name: '提交训练结果', exact: true })).toBeVisible()
  393. const requests = contract.requests.filter((item) => item.method === 'POST' && item.path === '/runs/run-physical/physical-events')
  394. expect(requests).toHaveLength(2)
  395. expect(requests.map((item) => item.body.stepCode)).toEqual(['STEP-01', 'STEP-02'])
  396. expect(requests.map((item) => item.body.eventType)).toEqual(['MANUAL_CONFIRM_POWER_OFF', 'MANUAL_CONFIRM_PRESSURE_RELEASED'])
  397. expect(requests.every((item) => item.body.source === 'MANUAL' && item.body.manualConfirmed === true)).toBe(true)
  398. expect(requests.every((item) => Number(item.body.occurredAt) < 1_000_000_000_000)).toBe(true)
  399. expect(contract.count('PUT', '/runs/run-physical/progress')).toBe(0)
  400. expect(contract.runs.get('run-physical')?.progressPercent).toBe(100)
  401. await captureScreenshot(page, testInfo, 'teaching-physical-two-step-events')
  402. })
  403. test('指定任务预创建的待接收运行可完成接收并进入任务', async ({ page }) => {
  404. const contract = new TeachingContractMock('studentLeader')
  405. const pendingRun = contract.runs.get('run-physical')
  406. if (!pendingRun) throw new Error('缺少指定任务运行夹具')
  407. pendingRun.status = 'PENDING'
  408. pendingRun.acceptedAt = null
  409. await contract.install(page)
  410. await page.goto('/teaching/physical-training')
  411. const card = page.locator('.ttc-assignment-card').filter({ hasText: '实装维修训练' })
  412. await expect(card.getByRole('button', { name: '接收任务', exact: true })).toBeVisible()
  413. await card.getByRole('button', { name: '接收任务', exact: true }).click()
  414. await expect(page).toHaveURL(/\/teaching\/physical-training\/runs\/run-physical$/)
  415. expect(contract.count('POST', '/assignments/assignment-physical/accept')).toBe(1)
  416. expect(contract.runs.get('run-physical')?.status).toBe('ACCEPTED')
  417. })
  418. test('对抗共享运行按岗位推进、负责人提交,并仅展示故障公开投影与 TEAM 编组干预', async ({ page }, testInfo) => {
  419. const contract = new TeachingContractMock('studentOperator')
  420. await contract.install(page)
  421. const faultResponsePromise = page.waitForResponse((response) => response.url().includes('/assignments/assignment-confrontation/faults'))
  422. await page.goto('/teaching/confrontation/runs/run-confrontation')
  423. const faultResponse = await faultResponsePromise
  424. const faultPayload = await faultResponse.json() as { data: unknown }
  425. expect(JSON.stringify(faultPayload.data)).not.toContain('液压阀芯卡滞真值')
  426. expect(JSON.stringify(faultPayload.data)).not.toContain('内部触发条件')
  427. await expect(page.getByText('动臂响应迟缓且压力波动', { exact: true })).toBeVisible()
  428. await expect(page.getByText('液压阀芯卡滞真值')).toHaveCount(0)
  429. await expect(page.getByText('红蓝双方按岗位协同完成液压故障隔离', { exact: true })).toBeVisible()
  430. await expect(page.getByText('在安全约束下按完成度与用时综合判定', { exact: true })).toBeVisible()
  431. await expect(page.getByText(/红方维修组 · OPERATOR/)).toBeVisible()
  432. await expect(page.getByText(/此动作需由 TEAM_LEADER/)).toBeVisible()
  433. await expect(page.getByRole('button', { name: '提交岗位动作', exact: true })).toBeDisabled()
  434. await switchIdentity(page, contract, 'studentLeader')
  435. await page.getByRole('button', { name: '提交岗位动作', exact: true }).click()
  436. expect(contract.last('PUT', '/runs/run-confrontation/progress')?.body).toMatchObject({ completedStepCode: 'STEP-01', actionCode: 'ISSUE_COMMAND' })
  437. await switchIdentity(page, contract, 'studentOperator')
  438. await expect(page.getByText(/当前动作由岗位“OPERATOR”执行/)).toBeVisible()
  439. await page.getByRole('button', { name: '完成当前岗位动作', exact: true }).click()
  440. await expect(page.getByText('等待组长/指挥员提交', { exact: true })).toBeVisible()
  441. expect(contract.last('PUT', '/runs/run-confrontation/progress')?.body).toMatchObject({ completedStepCode: 'STEP-02', actionCode: 'ISOLATE_FAULT' })
  442. await switchIdentity(page, contract, 'studentLeader')
  443. await page.getByRole('button', { name: '提交团队结果', exact: true }).click()
  444. await visibleDialog(page).getByRole('button', { name: '确认提交', exact: true }).click()
  445. expect(contract.runs.get('run-confrontation')?.status).toBe('SUBMITTED')
  446. await switchIdentity(page, contract, 'teacher')
  447. await page.getByRole('button', { name: '新建干预', exact: true }).click()
  448. const dialog = visibleDialog(page)
  449. await chooseSelectOption(page, dialog, '作用层级', '指定队伍')
  450. await chooseSelectOption(page, dialog, '目标队伍', '红方')
  451. await dialog.locator('input[placeholder="可选:进一步限定编组"]').fill('GROUP-RED')
  452. await dialog.locator('textarea[placeholder="请输入不泄露故障答案的公开说明"]').fill('红方液压压力波动,请按岗位流程处置。')
  453. await dialog.getByRole('button', { name: '保存干预', exact: true }).click()
  454. await expect(page.getByText('红方液压压力波动,请按岗位流程处置。', { exact: true })).toBeVisible()
  455. await page.getByRole('button', { name: '激活', exact: true }).click()
  456. const intervention = contract.last('POST', '/assignments/assignment-confrontation/interventions')
  457. expect(intervention?.body).toMatchObject({ targetScope: 'TEAM', targetTeamCode: 'RED', targetGroupCode: 'GROUP-RED' })
  458. expect(intervention?.body).not.toHaveProperty('privatePayload')
  459. expect(contract.interventions[0]?.status).toBe('ACTIVE')
  460. await captureScreenshot(page, testInfo, 'teaching-confrontation-role-and-intervention')
  461. })
  462. test('正式考核提交 Unix 秒并锁定所有辅助能力', async ({ page }, testInfo) => {
  463. const contract = new TeachingContractMock('teacher')
  464. await contract.install(page)
  465. await page.goto('/teaching/exams')
  466. await page.getByRole('button', { name: '新建正式考核', exact: true }).click()
  467. const dialog = visibleDialog(page)
  468. await dialog.getByRole('textbox', { name: /任务名称/ }).fill('状态化契约正式考核')
  469. await chooseSelectOption(page, dialog, '训练内容', '挖掘机液压系统训练 · V2')
  470. await dialog.getByRole('combobox', { name: '开始时间' }).fill('2026-08-11 09:00:00')
  471. await dialog.getByRole('combobox', { name: '截止时间' }).fill('2026-08-11 11:00:00')
  472. await chooseSelectOption(page, dialog, '参训学员', '红方队长 · 维修教研室')
  473. await page.keyboard.press('Escape')
  474. await dialog.getByRole('button', { name: '保存草稿', exact: true }).click()
  475. await expect(dialog).toBeHidden()
  476. const createRequest = contract.last('POST', '/assignments')
  477. expect(createRequest?.body).toMatchObject({ assignmentKind: 'FORMAL_EXAM', executionMode: 'EXAM', digitalHumanAllowed: false })
  478. expect(typeof createRequest?.body.scheduleStartAt).toBe('number')
  479. expect(typeof createRequest?.body.dueAt).toBe('number')
  480. expect(Number(createRequest?.body.scheduleStartAt)).toBeLessThan(1_000_000_000_000)
  481. expect(Number(createRequest?.body.dueAt)).toBeGreaterThan(Number(createRequest?.body.scheduleStartAt))
  482. contract.keepOnlyRuns('run-exam')
  483. await switchIdentity(page, contract, 'studentLeader')
  484. await page.goto('/teaching/exams/runs/run-exam')
  485. await expect(page.getByText('正式考核保护已启用', { exact: true })).toBeVisible()
  486. await expect(page.getByText(/关闭演示、步骤提示、回退、答案和数字教员/)).toBeVisible()
  487. await expect(page.getByRole('button', { name: /演示|提示|回退|回放|上一步/ })).toHaveCount(0)
  488. await expect.poll(() => contract.count('GET', '/runs/run-exam/execution')).toBeGreaterThan(0)
  489. await page.goto('/teaching/immersive')
  490. await expect(page.getByText('正式考核禁止数字人、提示和演示。', { exact: true })).toBeVisible()
  491. await expect(page.getByText('本地数字人服务', { exact: true })).toHaveCount(0)
  492. await expect.poll(() => contract.count('GET', '/runs/run-exam/assets')).toBeGreaterThan(0)
  493. await expect.poll(() => contract.count('GET', '/runs/run-exam/execution')).toBeGreaterThan(1)
  494. await captureScreenshot(page, testInfo, 'teaching-formal-exam-seconds-and-lock')
  495. })
  496. test('沉浸执行权限缺失时启动检查与桌面 WebXR 入口前置只读', async ({ page }) => {
  497. const contract = new TeachingContractMock('studentLeader')
  498. contract.seedImmersiveRun()
  499. contract.keepOnlyRuns('run-immersive')
  500. contract.denyPermissions('teaching.immersive.execute')
  501. await contract.install(page)
  502. await page.goto('/teaching/immersive')
  503. const preflight = page.getByTestId('immersive-preflight')
  504. await expect(preflight).toContainText('当前身份仅可查看,无沉浸训练执行权限')
  505. await expect(preflight).toContainText('不会创建服务端会话,也不会申请浏览器 WebXR 会话')
  506. const desktopStarts = page.getByRole('button', { name: /只读查看,无法启动/ })
  507. await expect(desktopStarts).toHaveCount(2)
  508. for (const button of await desktopStarts.all()) await expect(button).toBeDisabled()
  509. await expect(page.getByRole('button', { name: 'VR 沉浸模式' })).toBeDisabled()
  510. expect(contract.count('POST', /\/runs\/[^/]+\/xr-sessions$/)).toBe(0)
  511. })
  512. test('运行场景与 WebXR 消费 definitionSnapshot 和教学资产,并完成桌面会话登记与结束', async ({ page }, testInfo) => {
  513. const contract = new TeachingContractMock('studentLeader')
  514. contract.seedImmersiveRun()
  515. contract.keepOnlyRuns('run-immersive')
  516. await contract.install(page)
  517. let modelRequests = 0
  518. page.on('request', (request) => { if (new URL(request.url()).pathname === '/models/excavator-a.glb') modelRequests += 1 })
  519. await page.goto('/teaching/immersive')
  520. await expect(page.getByRole('heading', { name: '沉浸交互与外设联调', exact: true })).toBeVisible()
  521. await expect.poll(() => contract.count('GET', '/runs/run-immersive/assets')).toBeGreaterThan(0)
  522. await expect(page.locator('.immersive-scene-status')).toContainText('已加载“虚拟维修训练”发布场景', { timeout: 30_000 })
  523. await expect.poll(() => modelRequests).toBeGreaterThan(0)
  524. await expect(page.locator('.immersive-viewer canvas')).toBeVisible()
  525. await expect(page.locator('iframe')).toHaveCount(0)
  526. await expect(page.getByTestId('immersive-device-panel')).toBeVisible()
  527. await expect(page.getByTestId('immersive-calibration')).toBeVisible()
  528. await expect(page.getByTestId('immersive-preflight')).toBeVisible()
  529. await page.getByRole('button', { name: '启动桌面会话', exact: true }).click()
  530. await expect(page.getByRole('button', { name: '结束会话', exact: true })).toBeVisible()
  531. expect(contract.last('POST', '/runs/run-immersive/xr-sessions')?.body).toMatchObject({ mode: 'INLINE', referenceSpaceType: 'LOCAL' })
  532. await page.getByRole('button', { name: '结束会话', exact: true }).click()
  533. await expect(page.getByRole('button', { name: '结束会话', exact: true })).toHaveCount(0)
  534. expect(contract.count('PUT', '/xr-sessions/xr-session-1/end')).toBe(1)
  535. await captureScreenshot(page, testInfo, 'teaching-real-assets-and-xr-session')
  536. })
  537. test('数据中心查询分页安全明细,并以 Unix 秒提交时间筛选', async ({ page }, testInfo) => {
  538. const contract = new TeachingContractMock('teacher')
  539. await contract.install(page)
  540. await page.goto('/teaching/data-center')
  541. await expect(page.getByTestId('analytics-channel-summary')).toBeVisible()
  542. await page.getByTestId('analytics-tab-exam').click()
  543. await expect(page.getByText('虚拟维修正式考核', { exact: true })).toBeVisible()
  544. await page.locator('input[placeholder="搜索学员、编号或任务名称"]').fill('红方队长')
  545. await chooseSelectOption(page, page.locator('.teaching-v2-filter-toolbar'), '全部渠道', '虚拟仿真')
  546. await chooseSelectOption(page, page.locator('.teaching-v2-filter-toolbar'), '全部状态', '已评定')
  547. const toolbar = page.locator('.teaching-v2-filter-toolbar')
  548. await toolbar.getByRole('combobox', { name: '开始时间' }).fill('2026-08-01 00:00:00')
  549. await toolbar.getByRole('combobox', { name: '结束时间' }).fill('2026-08-12 00:00:00')
  550. await page.getByRole('button', { name: '搜索', exact: true }).click()
  551. await expect.poll(() => contract.count('GET', '/analytics/records')).toBeGreaterThan(1)
  552. const query = contract.last('GET', '/analytics/records')?.query
  553. expect(query?.get('keyword')).toBe('红方队长')
  554. expect(query?.get('channel')).toBe('VIRTUAL')
  555. // 页签在已授权的安全明细内做客户端分组;服务端组合筛选不再重复提交类型字段。
  556. expect(query?.get('assignmentKind')).toBeNull()
  557. expect(query?.get('status')).toBe('REVIEWED')
  558. expect(Number(query?.get('startAt'))).toBeLessThan(1_000_000_000_000)
  559. expect(Number(query?.get('endAt'))).toBeGreaterThan(Number(query?.get('startAt')))
  560. await page.getByRole('button', { name: '详情', exact: true }).click()
  561. const drawer = page.locator('.el-drawer:visible')
  562. await expect(drawer).toContainText('教学记录详情')
  563. await expect(drawer).toContainText('此处只展示服务端授权的安全明细')
  564. await expect(drawer).not.toContainText('checkpoint')
  565. await expect(drawer).not.toContainText('privatePayload')
  566. await captureScreenshot(page, testInfo, 'teaching-analytics-safe-records')
  567. })
  568. })