1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
| import assert from 'node:assert/strict'
| import fs from 'node:fs'
| import test from 'node:test'
| import { RoutesAlias } from '../src/router/routesAlias.js'
|
| test('adapts a backend menu tree using route for path and name for title', async () => {
| const { adaptBackendMenuTree } = await import('../src/router/adapters/backendMenuAdapter.js')
| const result = adaptBackendMenuTree([
| {
| id: 10,
| name: 'menu.system',
| parentId: 0,
| path: '1',
| route: '/system',
| type: 0,
| children: [
| {
| id: 11,
| name: 'menu.userLogin',
| parentId: 10,
| path: '1,10',
| route: 'user-login',
| component: 'userLogin',
| type: 0
| }
| ]
| }
| ])
|
| assert.equal(result[0].path, 'system')
| assert.equal(result[0].meta.title, '系统设置')
| assert.equal(result[0].children[0].path, 'user-login')
| assert.equal(result[0].children[0].meta.title, '登录日志')
| assert.equal(result[0].children[0].component, '/system/user-login')
| })
|
| test('keeps backend leaves by deriving component paths from the route hierarchy when no alias exists', async () => {
| const { adaptBackendMenuTree } = await import('../src/router/adapters/backendMenuAdapter.js')
| const result = adaptBackendMenuTree([
| {
| id: 1,
| name: 'menu.system',
| parentId: 0,
| path: '1',
| route: '/system',
| type: 0,
| children: [
| {
| id: 2,
| name: 'menu.userLogin',
| parentId: 1,
| path: '1,2',
| route: 'user-login',
| component: 'userLogin',
| type: 0
| },
| {
| id: 3,
| name: 'menu.host',
| parentId: 1,
| path: '1,3',
| route: 'host',
| component: 'host',
| type: 0
| }
| ]
| }
| ])
|
| assert.equal(result[0].children.length, 2)
| assert.equal(result[0].children[0].path, 'user-login')
| assert.equal(result[0].children[0].meta.title, '登录日志')
| assert.equal(result[0].children[0].component, '/system/user-login')
| assert.equal(result[0].children[1].path, 'host')
| assert.equal(result[0].children[1].meta.title, '机构管理')
| assert.equal(result[0].children[1].component, '/system/host')
| })
|
| test('filters non-menu nodes while keeping plain string titles unchanged', async () => {
| const { adaptBackendMenuTree } = await import('../src/router/adapters/backendMenuAdapter.js')
| const result = adaptBackendMenuTree([
| {
| id: 20,
| name: '系统设置',
| parentId: 0,
| path: '20',
| route: '/system',
| type: 0,
| children: [
| {
| id: 21,
| name: 'menu.user',
| parentId: 20,
| path: '20,21',
| route: 'user',
| component: 'user',
| type: 0
| },
| {
| id: 22,
| name: 'system:user:add',
| parentId: 20,
| path: '20,22',
| route: 'user/add',
| component: 'user',
| type: 1
| }
| ]
| }
| ])
|
| assert.equal(result[0].meta.title, '系统设置')
| assert.equal(result[0].children.length, 1)
| assert.equal(result[0].children[0].id, '21')
| assert.equal(result[0].children[0].component, '/system/user')
| })
|
| test('preserves absolute backend child routes instead of nesting them under the parent path', async () => {
| const { adaptBackendMenuTree } = await import('../src/router/adapters/backendMenuAdapter.js')
| const result = adaptBackendMenuTree([
| {
| id: 5318,
| name: 'AI管理中心',
| parentId: 0,
| route: '/AI',
| type: 0,
| children: [
| {
| id: 422,
| name: 'menu.aiParam',
| parentId: 5318,
| route: '/system/aiParam',
| component: 'aiParam',
| type: 0
| }
| ]
| }
| ])
|
| assert.equal(result[0].path, 'AI')
| assert.equal(result[0].children[0].path, '/system/aiParam')
| assert.equal(result[0].children[0].meta.title, 'AI 参数')
| assert.equal(result[0].children[0].component, '/system/aiParam')
| })
|
| test('keeps directory menus as layout nodes when they only group child routes', async () => {
| const { adaptBackendMenuTree } = await import('../src/router/adapters/backendMenuAdapter.js')
| const result = adaptBackendMenuTree([
| {
| id: 5318,
| name: 'AI管理中心',
| parentId: 0,
| route: '/AI',
| type: 0,
| children: [
| {
| id: 422,
| name: 'menu.aiParam',
| parentId: 5318,
| route: '/system/aiParam',
| component: 'aiParam',
| type: 0
| }
| ]
| }
| ])
|
| assert.equal(result[0].component, RoutesAlias.Layout)
| })
|
| test('maps legacy backend icon names into renderable Iconify icons', async () => {
| const { adaptBackendMenuTree } = await import('../src/router/adapters/backendMenuAdapter.js')
| const result = adaptBackendMenuTree([
| {
| id: 1,
| name: 'AI管理中心',
| route: '/ai',
| icon: 'SmartToy',
| type: 0,
| children: [
| {
| id: 2,
| name: 'menu.userLogin',
| route: 'user-login',
| component: 'userLogin',
| icon: 'Token',
| type: 0
| }
| ]
| }
| ])
|
| assert.equal(result[0].meta.icon, 'ri:robot-2-line')
| assert.equal(result[0].children[0].meta.icon, 'ri:key-2-line')
| })
|
| test('phase 1 resource mappings resolve to existing views and translatable menu labels', async () => {
| const { PHASE_1_COMPONENTS } = await import('../src/router/adapters/backendMenuAdapter.js')
|
| Object.entries(PHASE_1_COMPONENTS).forEach(([resourceKey, viewPath]) => {
| const normalizedPath = viewPath.replace(/^\//, '')
| const componentWithIndex = new URL(`../src/views/${normalizedPath}/index.vue`, import.meta.url)
| const singleFileComponent = new URL(`../src/views/${normalizedPath}.vue`, import.meta.url)
| const componentExists = fs.existsSync(componentWithIndex) || fs.existsSync(singleFileComponent)
|
| assert.equal(componentExists, true, `${resourceKey} should resolve to an existing view`)
| })
| })
|
|