import fs from 'node:fs' import {chromium,expect} from '@playwright/test' import {login,call} from './role-permissions-live.mjs' const session=await login('root'),checks=[] const browser=await chromium.launch({channel:'msedge',headless:true}) const page=await browser.newPage({viewport:{width:1920,height:1080}}) await page.addInitScript(s=>{sessionStorage.setItem('unreal-tran:web:access-token:v1',s.accessToken);sessionStorage.setItem('unreal-tran:web:refresh-token:v1',s.refreshToken)},session) let id try{ await page.goto('http://127.0.0.1:6180/content/ofd/templates') await page.locator('.library-heading button').click() await page.getByLabel('指导书名称',{exact:true}).fill('正式模板新建回归-20260911') const created=page.waitForResponse(r=>r.url().includes('/guide-templates/')&&r.url().endsWith('/projects')&&r.request().method()==='POST') await page.getByRole('button',{name:'创建并进入规划',exact:true}).click() const response=await created;const body=await response.json();id=String(body.data.project.id) checks.push({name:'模板新建实际进入正式内容服务',pass:response.ok()}) await page.waitForURL(/\/ofd\/\d+\/studio/) await page.goto(`http://127.0.0.1:6180/content/ofd/${id}/studio?view=editor`) await expect(page.locator('.ofd-view-editor')).toBeVisible({timeout:60000}) const before=await call(`tran/v1/content/projects/${id}`,session.accessToken) const save=page.waitForResponse(r=>r.url().endsWith(`/projects/${id}`)&&r.request().method()==='PUT') await page.locator('[data-action="save"]').click();const saved=await save checks.push({name:'模板初稿进入编辑器并保存',pass:saved.ok()}) const after=await call(`tran/v1/content/projects/${id}`,session.accessToken) checks.push({name:'模板章节和步骤不丢失',pass:JSON.stringify(before.data.currentVersion.content.chapters.map(c=>[c.id,c.title,c.steps.map(s=>[s.id,s.title])]))===JSON.stringify(after.data.currentVersion.content.chapters.map(c=>[c.id,c.title,c.steps.map(s=>[s.id,s.title])]))}) await page.screenshot({path:'reports/guide-formal-20260910/17-template-editor.png'}) }catch(e){checks.push({name:'模板编制闭环',pass:false,detail:e.message});process.exitCode=1;await page.screenshot({path:'reports/guide-formal-20260910/template-failure.png'})} finally{console.log(checks);fs.writeFileSync('reports/guide-formal-20260910/template.json',JSON.stringify({projectId:id,checks},null,2));await browser.close()}