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.
 
 
 
 

46 line
4.3 KiB

  1. import fs from 'node:fs';
  2. import assert from 'node:assert/strict';
  3. import {chromium,expect} from '@playwright/test';
  4. import {login,call} from './role-permissions-live.mjs';
  5. const dir='reports/bridge-tools-authoring-20260924';fs.mkdirSync(dir,{recursive:true});
  6. const fixture=JSON.parse(fs.readFileSync('reports/bridge-content-authoring-20260924/fixture.json','utf8'));
  7. const session=await login('root'),checks=[],errors=[];
  8. const browser=await chromium.launch({channel:'msedge',headless:true,args:['--enable-unsafe-swiftshader']});
  9. const page=await browser.newPage({viewport:{width:1440,height:1000}});
  10. await page.addInitScript(s=>{sessionStorage.setItem('unreal-tran:web:access-token:v1',s.accessToken);sessionStorage.setItem('unreal-tran:web:refresh-token:v1',s.refreshToken);localStorage.setItem('unreal-tran:web:preferences:v1',JSON.stringify({themeMode:'light'}));},session);
  11. page.on('pageerror',e=>errors.push(e.message));
  12. const api=async ep=>{const r=await call('tran/v1/'+ep,session.accessToken);assert.equal(r.status,200);return r.data;};
  13. const ready=()=>expect(page.getByRole('button',{name:'播放动作',exact:true})).toBeEnabled({timeout:120000});
  14. try{
  15. const before=new Map();for(const item of fixture.items)before.set(item.taskId,(await api('teaching/assignments/'+item.taskId)).definitionSnapshot);
  16. for(const item of fixture.items){
  17. if(process.env.PREVIEW_ONLY==='1'&&!['88','89'].includes(item.taskId))continue;
  18. await page.goto('http://127.0.0.1:6180/content/models/'+item.modelProjectId+'/production');await ready();
  19. const model=await api('content/projects/'+item.modelProjectId),actions=model.currentVersion.content.productionActions;
  20. const chosen=actions.findIndex(a=>/bolt-1$/.test(a.targetId));
  21. await page.locator('.production-action-item').nth(Math.max(0,chosen)).click();
  22. await expect(page.getByText('学员操作',{exact:true})).toBeVisible();
  23. if(chosen>=0){
  24. await expect(page.getByText('所需工具',{exact:true})).toBeVisible();
  25. await expect(page.getByText('工具作用部件',{exact:true})).toBeVisible();
  26. await page.getByRole('button',{name:'播放动作',exact:true}).click();await page.waitForTimeout(600);
  27. await page.screenshot({path:dir+'/'+item.taskCode+'-tool-preview.png'});await ready();
  28. }
  29. if(process.env.PREVIEW_ONLY==='1'){checks.push({task:item.taskCode,preview:true});continue;}
  30. // Publish only the authoring chain. The existing task points at its old fixed
  31. // snapshot; the assertion below protects all four active simulations.
  32. await page.getByRole('button',{name:'发布并进入场景',exact:true}).click();await expect(page).toHaveURL(new RegExp('/scenes/'+item.sceneProjectId+'/production'));await ready();
  33. await page.getByRole('button',{name:'发布并进入编排',exact:true}).click();await expect(page).toHaveURL(new RegExp('/training-projects/'+item.trainingProjectId+'/production'));await ready();
  34. await page.getByRole('button',{name:'发布训练内容',exact:true}).click();await expect(page.getByText('训练内容已发布;现有仿真仍保持固定版本')).toBeVisible();
  35. const training=await api('content/projects/'+item.trainingProjectId);
  36. const bindings=training.currentVersion.content.steps.flatMap(s=>s.modelActions||[]);
  37. assert.equal(bindings.length,item.actions);assert.ok(bindings.every(a=>a.toolAction&&a.toolAction.trigger));
  38. if(chosen>=0)assert.ok(bindings.some(a=>a.toolAction.trigger==='tool-drop'));
  39. await page.screenshot({path:dir+'/'+item.taskCode+'-training.png'});
  40. checks.push({task:item.taskCode,bindings:bindings.length,modelProject:item.modelProjectId,sceneProject:item.sceneProjectId,trainingProject:item.trainingProjectId,version:training.project.publishedVersionId});
  41. console.log(item.taskCode+' authoring tools published');
  42. }
  43. for(const item of fixture.items)assert.deepEqual((await api('teaching/assignments/'+item.taskId)).definitionSnapshot,before.get(item.taskId),'fixed simulation unchanged');
  44. assert.deepEqual(errors,[]);fs.writeFileSync(dir+(process.env.PREVIEW_ONLY==='1'?'/preview-result.json':'/result.json'),JSON.stringify({pass:true,checks,errors,existingTasksUnchanged:true},null,2));
  45. }catch(error){await page.screenshot({path:dir+'/failure.png'}).catch(()=>{});fs.writeFileSync(dir+'/result.json',JSON.stringify({pass:false,error:error.message,checks,errors},null,2));throw error;}finally{await browser.close();}