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.
 
 
 
 

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