28 lines
1.9 KiB
JavaScript
28 lines
1.9 KiB
JavaScript
|
|
import test from 'node:test'
|
||
|
|
import assert from 'node:assert/strict'
|
||
|
|
import {hasHomePermission,isHomePath,visibleHomeRoutes,homeLandingPath} from '../../src/utils/home-access.js'
|
||
|
|
|
||
|
|
const routes=[{path:'',redirect:'/index',children:[{path:'/index',meta:{homePage:true,affix:true}}]},{path:'/login',hidden:true},{path:'/',children:[{path:'project-archive',meta:{title:'项目资料'}}]}]
|
||
|
|
test('an archive-only manager has no homepage route and lands directly on project documents',()=>{
|
||
|
|
assert.equal(hasHomePermission(['archive:project:list']),false)
|
||
|
|
const visible=visibleHomeRoutes(routes,false)
|
||
|
|
assert.equal(visible.some(r=>r.children?.some(c=>c.meta?.homePage)),false)
|
||
|
|
assert.equal(homeLandingPath(visible,false),'/project-archive')
|
||
|
|
assert.equal(routes[0].children.length,1)
|
||
|
|
})
|
||
|
|
test('homepage permission is explicit, administrator wildcard works, and no-menu accounts have a safe fallback',()=>{
|
||
|
|
assert.equal(hasHomePermission(['warehouse:stock:list']),false)
|
||
|
|
assert.equal(hasHomePermission(['business:home:view']),true)
|
||
|
|
assert.equal(hasHomePermission(['business:home:view'],'project'),false)
|
||
|
|
assert.equal(hasHomePermission(['*:*:*'],'todo'),true)
|
||
|
|
assert.equal(homeLandingPath(routes,true),'/index')
|
||
|
|
assert.equal(homeLandingPath([{path:'/hidden',hidden:true},{path:'https://example.com'},{path:'/record/:id'}],false),'/user/profile')
|
||
|
|
for(const path of ['/index','/index/','/redirect/index?x=1','/'])assert.equal(isHomePath(path),true)
|
||
|
|
assert.equal(isHomePath('/project-archive'),false)
|
||
|
|
})
|
||
|
|
test('the database authorization menu never registers a duplicate Index route',()=>{
|
||
|
|
const dynamic=[{path:'/',children:[{path:'index',component:'businessHome/index'}]},{path:'/system',children:[{path:'user',component:'system/user/index'}]}]
|
||
|
|
assert.deepEqual(visibleHomeRoutes(dynamic,true,true),[dynamic[1]])
|
||
|
|
assert.equal(homeLandingPath(visibleHomeRoutes(dynamic,false,true),false),'/system/user')
|
||
|
|
})
|