Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

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