| | |
| | | import assert from 'node:assert/strict' |
| | | import fs from 'node:fs' |
| | | import path from 'node:path' |
| | | import { readFileSync } from 'node:fs' |
| | | import test from 'node:test' |
| | | |
| | | const projectRoot = path.resolve(import.meta.dirname, '..') |
| | | const zhLocalePath = path.join(projectRoot, 'src', 'locales', 'langs', 'zh.json') |
| | | const enLocalePath = path.join(projectRoot, 'src', 'locales', 'langs', 'en.json') |
| | | const routerUtilsPath = path.join(projectRoot, 'src', 'utils', 'router.js') |
| | | const menuPagePath = path.join(projectRoot, 'src', 'views', 'system', 'menu', 'index.vue') |
| | | const menuPageSource = readFileSync( |
| | | new URL('../src/views/system/menu/index.vue', import.meta.url), |
| | | 'utf8' |
| | | ) |
| | | |
| | | test('current-system menu keys are available in rsf-design locales', () => { |
| | | const zhMessages = JSON.parse(fs.readFileSync(zhLocalePath, 'utf8')) |
| | | const enMessages = JSON.parse(fs.readFileSync(enLocalePath, 'utf8')) |
| | | const menuDialogSource = readFileSync( |
| | | new URL('../src/views/system/menu/modules/menu-dialog.vue', import.meta.url), |
| | | 'utf8' |
| | | ) |
| | | |
| | | assert.equal(zhMessages.menu?.system, '系统设置') |
| | | assert.equal(zhMessages.menu?.basicInfo, '基础信息') |
| | | assert.equal(zhMessages.menu?.aiParam, 'AI 参数') |
| | | const routerSource = readFileSync(new URL('../src/utils/router.js', import.meta.url), 'utf8') |
| | | const zhLocale = JSON.parse(readFileSync(new URL('../src/locales/langs/zh.json', import.meta.url), 'utf8')) |
| | | const enLocale = JSON.parse(readFileSync(new URL('../src/locales/langs/en.json', import.meta.url), 'utf8')) |
| | | |
| | | assert.equal(enMessages.menu?.system, 'System') |
| | | assert.equal(enMessages.menu?.basicInfo, 'BasicInfo') |
| | | assert.equal(enMessages.menu?.aiParam, 'AI Params') |
| | | test('menu page submit and delete handlers call the real backend menu APIs', () => { |
| | | assert.match(menuPageSource, /fetchSaveMenu/) |
| | | assert.match(menuPageSource, /fetchUpdateMenu/) |
| | | assert.match(menuPageSource, /fetchDeleteMenu/) |
| | | assert.doesNotMatch(menuPageSource, /console\.log\('提交数据:'/) |
| | | assert.match(menuPageSource, /const handleAddAuth = \(row\) =>/) |
| | | assert.match(menuPageSource, /const handleDeleteMenu = async \(row\) =>/) |
| | | assert.match(menuPageSource, /const handleDeleteAuth = async \(row\) =>/) |
| | | assert.match(menuPageSource, /await fetchDeleteMenu\(row\.id\)/) |
| | | }) |
| | | |
| | | test('formatMenuTitle recognizes current-system menu translation keys', () => { |
| | | const routerSource = fs.readFileSync(routerUtilsPath, 'utf8') |
| | | |
| | | assert.match(routerSource, /startsWith\('menu\.'\)|startsWith\("menu\."\)/) |
| | | test('menu dialog accepts edit data and parent menu options from the page', () => { |
| | | assert.match(menuDialogSource, /editData:/) |
| | | assert.match(menuDialogSource, /menuTreeOptions:/) |
| | | assert.match(menuDialogSource, /key: 'parentId'/) |
| | | assert.match(menuDialogSource, /type: 'treeselect'/) |
| | | }) |
| | | |
| | | test('menu management table shows icon preview and translated names', () => { |
| | | const menuPageSource = fs.readFileSync(menuPagePath, 'utf8') |
| | | |
| | | test('menu page renders Iconify preview and current-system translated menu names', () => { |
| | | assert.ok( |
| | | menuPageSource.indexOf("label: '菜单名称'") < menuPageSource.indexOf("label: '图标预览'"), |
| | | '菜单名称列应保持在图标预览列之前,避免树形展开箭头跑到图标列' |
| | | ) |
| | | assert.match(menuPageSource, /label:\s*'图标预览'/) |
| | | assert.match(menuPageSource, /ArtSvgIcon/) |
| | | assert.match(menuPageSource, /row\.meta\?\.title\s*\|\|\s*row\.name|item\.meta\?\.title\s*\|\|\s*item\.name/) |
| | | assert.match(menuPageSource, /rounded-md/) |
| | | assert.match(menuPageSource, /row\.meta\?\.title\s*\|\|\s*row\.name/) |
| | | assert.match(routerSource, /startsWith\('menu\.'\)|startsWith\("menu\."\)/) |
| | | assert.match(routerSource, /const fallbackTitle =/) |
| | | assert.match(routerSource, /title\.startsWith\('menus\.'\)/) |
| | | assert.match(routerSource, /i18n\.global\.te\(fallbackTitle\)/) |
| | | assert.equal(zhLocale.menu?.system, '系统设置') |
| | | assert.equal(zhLocale.menu?.basicInfo, '基础信息') |
| | | assert.equal(zhLocale.menu?.aiParam, 'AI 参数') |
| | | assert.equal(enLocale.menu?.system, 'System') |
| | | assert.equal(enLocale.menu?.basicInfo, 'BasicInfo') |
| | | assert.equal(enLocale.menu?.aiParam, 'AI Params') |
| | | }) |