40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
const assert = require('node:assert/strict')
|
|
const test = require('node:test')
|
|
|
|
const { buildNavigation } = require('../src/layout/navigation.js')
|
|
|
|
test('selects the layout record when normalized routes contain duplicate root paths', () => {
|
|
const routes = [
|
|
{ path: '/', name: 'sense-dashboard', children: [], meta: { title: '工作台' } },
|
|
{ path: '/devices', name: 'sense-devices', children: [], meta: { title: '设备管理' } },
|
|
{
|
|
path: '/',
|
|
children: [
|
|
{ path: 'devices', meta: { title: '设备管理', permission: 'device.read', order: 10 } },
|
|
{ path: '', meta: { title: '工作台', order: 0 } },
|
|
{ path: 'users', meta: { title: '用户与权限', permission: 'identity.users.read', order: 90 } }
|
|
]
|
|
}
|
|
]
|
|
|
|
assert.deepEqual(buildNavigation(routes, ['device.read']), [
|
|
{ path: '/', title: '工作台', icon: undefined, order: 0 },
|
|
{ path: '/devices', title: '设备管理', icon: undefined, order: 10 }
|
|
])
|
|
})
|
|
|
|
test('returns no unauthorized or hidden entries', () => {
|
|
const routes = [{
|
|
path: '/',
|
|
children: [
|
|
{ path: '', meta: { title: '工作台' } },
|
|
{ path: 'users', meta: { title: '用户与权限', permission: 'identity.users.read' } },
|
|
{ path: 'internal', meta: { title: '内部页', hidden: true } }
|
|
]
|
|
}]
|
|
|
|
assert.deepEqual(buildNavigation(routes), [
|
|
{ path: '/', title: '工作台', icon: undefined, order: 0 }
|
|
])
|
|
})
|