Files
crawler-plugin/admin-frontend-vue/tests/align-locale.test.ts
T

43 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test'
import assert from 'node:assert/strict'
import { existsSync } from 'node:fs'
import { readSource } from './helpers.ts'
// 验收反馈:日期控件/分页组件需显示中文。
// 不变式:应用入口为 Element Plus 注册 zh-cn 全局 localedate-picker/pagination 全部跟随)。
test('align_locale_normal_primary_path', () => {
const main = readSource('src/main.ts')
assert.match(main, /zh-cn|zhCn/i, 'main.ts 应引入 element-plus 中文语言包')
assert.match(main, /locale\s*[:=]\s*zhCn|locale,\s*zhCn/, 'ElementPlus 注册需携带 locale 配置')
})
test('align_locale_normal_variant_input', () => {
// 语言包必须来自 element-plus 官方路径(es/locale 或 dist/locale),不接受自造空对象。
const main = readSource('src/main.ts')
assert.match(main, /element-plus\/(es|dist)\/locale/, 'locale 导入需指向 element-plus 语言包')
})
test('align_locale_boundary_empty_input', () => {
// 日期控件页面依赖全局 locale,不得在页面内再覆盖为 en。
const pages = [
'src/pages/asin/DedupeRegistryPage.vue',
'src/pages/records/RecordsHistoryPage.vue',
'src/pages/tasks/ImageVideoTasksPage.vue',
'src/pages/tasks/ShopDataTasksPage.vue',
]
for (const page of pages) {
const src = readSource(page)
assert.ok(!/locale\s*=\s*['"]en['"]/i.test(src), `${page} 不得局部覆盖英文 locale`)
}
})
test('align_locale_dependency_failure_returns_actionable_message', () => {
// zh-cn 语言包在 node_modules 中真实存在(安装依赖即有效)。
assert.ok(
existsSync('node_modules/element-plus/es/locale/lang/zh-cn.mjs') ||
existsSync('node_modules/element-plus/dist/locale/zh-cn.mjs'),
'element-plus zh-cn 语言包文件存在',
)
})