2026-10-16 15:30:10 +08:00
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
2026-10-20 13:39:44 +08:00
test ( 'message center offers a keyboard-accessible, permission-gated announcement management entry even when empty' , ( ) => {
2026-10-16 15:30:10 +08:00
const source = readFileSync ( new URL ( '../../src/layout/components/HeaderNotice/index.vue' , import . meta . url ) , 'utf8' )
2026-10-20 13:39:44 +08:00
assert . match ( source , /@click="openCenter"/ )
assert . match ( source , /<button[^>]*aria-label="消息中心"/ )
assert . match ( source , /v-if="proxy\?\.\$can\(\['system:notice:list'\]\)" class="center-footer"/ )
2026-10-16 15:30:10 +08:00
assert . match ( source , />公告管理<\/el-button>/ )
assert . match ( source , /if \(!proxy\.\$can\(\['system:notice:list'\]\)\) return/ )
assert . match ( source , /router\.push\('\/system\/notice'\)/ )
assert . doesNotMatch ( source , /notice-footer[^>]*noticeList\.length/ )
} )
test ( 'notice management keeps native create, update and delete permission gates' , ( ) => {
const source = readFileSync ( new URL ( '../../src/views/system/notice/index.vue' , import . meta . url ) , 'utf8' )
for ( const permission of [ 'add' , 'edit' , 'remove' ] ) assert . ok ( source . includes ( ` $ can(['system:notice: ${ permission } ']) ` ) )
const navbar = readFileSync ( new URL ( '../../src/layout/components/Navbar.vue' , import . meta . url ) , 'utf8' )
const beforeNotice = navbar . slice ( 0 , navbar . indexOf ( '<header-notice' ) )
assert . ok ( beforeNotice . lastIndexOf ( '</template>' ) > beforeNotice . lastIndexOf ( ` appStore.device !== 'mobile' ` ) , 'The notice entry must not disappear on mobile' )
} )