2026-10-14 09:11:33 +08:00
const assert = require ( 'node:assert/strict' )
const fs = require ( 'node:fs' )
const path = require ( 'node:path' )
const { chromium } = require ( './vue3-test-runtime.cjs' )
const base = process . env . VUE3 _URL || 'http://127.0.0.1:8088'
const out = path . resolve ( _ _dirname , '../../.codex-tmp/vue3-style-check' )
async function ready ( page , route ) {
await page . goto ( base + route , { waitUntil : 'domcontentloaded' } )
await page . locator ( '.desktop-viewport > .app-container' ) . waitFor ( )
await page . waitForFunction ( ( ) => ! [ ... document . querySelectorAll ( '.desktop-viewport .el-loading-mask' ) ] . some ( e => e . getClientRects ( ) . length ) )
}
; ( async ( ) => {
const login = await ( await fetch ( ( process . env . BACKEND _URL || 'http://127.0.0.1:8080' ) + '/login' , {
method : 'POST' , headers : { 'Content-Type' : 'application/json' } ,
body : JSON . stringify ( { username : process . env . TEST _USERNAME || 'admin' , password : process . env . TEST _PASSWORD || 'admin123' , code : '' , uuid : '' } )
} ) ) . json ( )
assert . equal ( login . code , 200 )
fs . mkdirSync ( out , { recursive : true } )
const browser = await chromium . launch ( { headless : true , args : [ '--disable-gpu' ] } )
const results = [ ] , errors = [ ] , warnings = [ ]
try {
const context = await browser . newContext ( { viewport : { width : 1440 , height : 900 } } )
await context . addCookies ( [ { name : 'Admin-Token' , value : login . token , url : base } , { name : 'size' , value : 'default' , url : base } ] )
await context . route ( '**/dev-api/**' , r => [ 'GET' , 'HEAD' ] . includes ( r . request ( ) . method ( ) ) ? r . continue ( ) : r . abort ( 'blockedbyclient' ) )
const page = await context . newPage ( )
page . on ( 'pageerror' , e => errors . push ( e . message ) )
page . on ( 'console' , m => { if ( m . type ( ) === 'warning' && /Invalid prop|Failed to resolve|Unhandled error/ . test ( m . text ( ) ) ) warnings . push ( m . text ( ) ) } )
for ( const route of [ '/index' , '/project/info' , '/procurement/details' , '/procurement/arrival' , '/warehouse/stock' , '/businessBasics/area' , '/businessBasics/products' , '/businessBasics/bom' , '/production/tasks' , '/system/user' ] ) {
await ready ( page , route )
const controls = await page . locator ( '.desktop-viewport .el-form--inline' ) . evaluateAll ( forms => forms . flatMap ( form => [ ... form . querySelectorAll ( '.el-input__wrapper,.el-select__wrapper,.el-button:not(.is-text):not(.el-button--text)' ) ] . filter ( e => e . getBoundingClientRect ( ) . width && ! e . closest ( '.el-table' ) ) . map ( e => ( { cls : e . className , h : e . getBoundingClientRect ( ) . height , font : getComputedStyle ( e ) . fontSize } ) ) ) )
for ( const c of controls ) { assert . ok ( Math . abs ( c . h - 32 ) < 1 , route + ' control height ' + JSON . stringify ( c ) ) ; assert . equal ( c . font , '14px' , route + ' control font ' + JSON . stringify ( c ) ) }
assert . equal ( await page . locator ( '.el-button--mini,.el-input--mini,.el-select--mini' ) . count ( ) , 0 )
const pagination = await page . locator ( '.pagination-container .el-select__wrapper' ) . evaluateAll ( es => es . filter ( e => e . getBoundingClientRect ( ) . width ) . map ( e => ( { h : e . getBoundingClientRect ( ) . height , font : getComputedStyle ( e ) . fontSize } ) ) )
pagination . forEach ( c => { assert . equal ( c . h , 32 ) ; assert . equal ( c . font , '14px' ) } )
results . push ( { route , controls : controls . length } )
await page . screenshot ( { path : path . join ( out , route . replaceAll ( '/' , '_' ) + '.png' ) } )
}
assert . equal ( ( await context . cookies ( ) ) . find ( c => c . name === 'size' ) . value , 'default' )
await ready ( page , '/businessBasics/products' )
const centers = await page . locator ( '.business-list-page__header .el-form' ) . evaluate ( form => [ ... form . querySelectorAll ( '.el-input__wrapper,.el-button' ) ] . map ( e => { const r = e . getBoundingClientRect ( ) ; return r . y + r . height / 2 } ) )
assert . ok ( Math . max ( ... centers ) - Math . min ( ... centers ) < 1 , 'product search baseline' )
const textButtonHeights = await page . locator ( '.el-table .el-button.is-link' ) . evaluateAll ( es => es . map ( e => e . getBoundingClientRect ( ) . height ) )
textButtonHeights . forEach ( h => assert . equal ( h , 24 ) )
await page . getByRole ( 'button' , { name : '新增' , exact : true } ) . click ( )
await page . locator ( '.el-dialog' ) . waitFor ( { state : 'visible' } )
const dialog = await page . locator ( '.el-dialog' ) . evaluate ( e => {
const title = e . querySelector ( '.el-dialog__title' ) . getBoundingClientRect ( ) , close = e . querySelector ( '.el-dialog__headerbtn' ) . getBoundingClientRect ( )
return { padding : getComputedStyle ( e ) . padding , offset : Math . abs ( title . y + title . height / 2 - close . y - close . height / 2 ) }
} )
assert . equal ( dialog . padding , '0px' ) ; assert . ok ( dialog . offset < 2 , JSON . stringify ( dialog ) )
const dialogButtons = await page . locator ( '.el-dialog__footer .el-button' ) . evaluateAll ( es => es . map ( e => ( { h : e . getBoundingClientRect ( ) . height , font : getComputedStyle ( e ) . fontSize } ) ) )
dialogButtons . forEach ( c => { assert . equal ( c . h , 32 ) ; assert . equal ( c . font , '14px' ) } )
await page . waitForTimeout ( 300 )
await page . screenshot ( { path : path . join ( out , 'dialog.png' ) } )
await page . getByRole ( 'button' , { name : '取消' , exact : true } ) . click ( )
// Ephemeral DOM/theme changes in this isolated browser validate native theme variables.
await page . evaluate ( ( ) => { document . documentElement . classList . add ( 'dark' ) ; document . documentElement . style . setProperty ( '--el-color-primary' , '#ff4500' ) } )
await page . waitForFunction ( ( ) => getComputedStyle ( document . querySelector ( '.business-list-page__header .el-form .el-button--primary' ) ) . backgroundColor === 'rgb(255, 69, 0)' )
const theme = await page . evaluate ( ( ) => ( { page : getComputedStyle ( document . querySelector ( '.app-container' ) ) . backgroundColor , label : getComputedStyle ( document . querySelector ( '.el-form-item__label' ) ) . color , primary : getComputedStyle ( document . querySelector ( '.business-list-page__header .el-form .el-button--primary' ) ) . backgroundColor } ) )
assert . notEqual ( theme . page , 'rgb(255, 255, 255)' ) ; assert . equal ( theme . primary , 'rgb(255, 69, 0)' )
await page . screenshot ( { path : path . join ( out , 'dark.png' ) } )
await ready ( page , '/index' )
await page . evaluate ( ( ) => document . documentElement . classList . add ( 'dark' ) )
const home = await page . locator ( '.home-panel' ) . first ( ) . evaluate ( e => ( { bg : getComputedStyle ( e ) . backgroundColor , text : getComputedStyle ( e . querySelector ( 'h3' ) ) . color } ) )
assert . notEqual ( home . bg , 'rgb(255, 255, 255)' )
await page . screenshot ( { path : path . join ( out , 'home-dark.png' ) } )
await page . evaluate ( ( ) => { document . documentElement . classList . remove ( 'dark' ) ; document . documentElement . style . removeProperty ( '--el-color-primary' ) ; localStorage . setItem ( 'layout-setting' , JSON . stringify ( { footerVisible : true } ) ) } )
await ready ( page , '/businessBasics/products' )
const footer = await page . evaluate ( ( ) => ( { pagination : document . querySelector ( '.pagination-container' ) . getBoundingClientRect ( ) . bottom , copyright : document . querySelector ( '.copyright' ) . getBoundingClientRect ( ) . top } ) )
assert . ok ( footer . pagination <= footer . copyright , JSON . stringify ( footer ) )
await page . screenshot ( { path : path . join ( out , 'footer.png' ) } )
await ready ( page , '/procurement/details' )
const opens = page . getByRole ( 'button' , { name : '打开' , exact : true } )
if ( await opens . count ( ) ) {
await opens . first ( ) . click ( ) ; await page . getByRole ( 'button' , { name : '编辑' , exact : true } ) . waitFor ( )
await page . getByRole ( 'button' , { name : '编辑' , exact : true } ) . click ( )
2026-10-15 11:30:55 +08:00
// Editors are mounted only for the active cell, not for every editable row.
await page . locator ( '.sheet-grid .sheet-cell.cell-editable' ) . first ( ) . click ( )
await page . locator ( '.sheet-grid .el-select__wrapper,.sheet-grid .el-input__inner' ) . first ( ) . waitFor ( { state : 'visible' } )
2026-10-14 09:11:33 +08:00
const fonts = await page . locator ( '.sheet-grid .el-select__wrapper,.sheet-grid .el-input__inner' ) . evaluateAll ( es => [ ... new Set ( es . map ( e => getComputedStyle ( e ) . fontSize ) ) ] )
assert . deepEqual ( fonts , [ '13px' ] )
const heights = await page . locator ( '.sheet-grid .el-select__wrapper,.sheet-grid .el-input__wrapper' ) . evaluateAll ( es => [ ... new Set ( es . map ( e => e . getBoundingClientRect ( ) . height ) ) ] )
assert . deepEqual ( heights , [ 28 ] )
await page . screenshot ( { path : path . join ( out , 'purchase-edit.png' ) } )
await page . getByRole ( 'button' , { name : '取消编辑' , exact : true } ) . click ( )
}
await page . setViewportSize ( { width : 412 , height : 860 } )
await page . goto ( base + '/mobile' )
await page . locator ( '.mobile-app' ) . waitFor ( )
await page . locator ( '.quick-panel button' ) . filter ( { hasText : '入库登记' } ) . click ( )
await page . locator ( '.mobile-dialog' ) . waitFor ( { state : 'visible' } )
const fields = await page . locator ( '.mobile-dialog .el-form-item' ) . evaluateAll ( es => es . filter ( e => e . getBoundingClientRect ( ) . width ) . map ( e => { const label = e . querySelector ( '.el-form-item__label' ) . getBoundingClientRect ( ) , content = e . querySelector ( '.el-form-item__content' ) . getBoundingClientRect ( ) ; return { x : content . x , labelBottom : label . bottom , contentTop : content . top } } ) )
assert . ok ( Math . max ( ... fields . map ( f => f . x ) ) - Math . min ( ... fields . map ( f => f . x ) ) < 1 )
fields . forEach ( f => assert . ok ( f . labelBottom <= f . contentTop + 1 ) )
await page . waitForTimeout ( 300 )
await page . screenshot ( { path : path . join ( out , 'mobile.png' ) } )
await context . addCookies ( [ { name : 'size' , value : 'medium' , url : base } ] )
await page . setViewportSize ( { width : 1366 , height : 768 } )
await ready ( page , '/businessBasics/products' )
assert . equal ( ( await context . cookies ( ) ) . find ( c => c . name === 'size' ) . value , 'default' )
assert . equal ( await page . locator ( '.el-button--medium,.el-input--medium' ) . count ( ) , 0 )
await page . screenshot ( { path : path . join ( out , 'desktop-1366.png' ) } )
assert . deepEqual ( errors , [ ] ) ; assert . deepEqual ( warnings , [ ] )
console . log ( 'STYLE PASS' , JSON . stringify ( { pages : results . length , dialog , theme , home , footer , fields : fields . length } ) )
fs . writeFileSync ( path . join ( out , 'result.json' ) , JSON . stringify ( { results , dialog , theme , home , footer , errors , warnings } , null , 2 ) )
} finally { await browser . close ( ) }
} ) ( ) . catch ( e => { console . error ( e ) ; process . exitCode = 1 } )