mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-14 06:07:23 +08:00
* feat(i18n): 优化i18n check脚本 * fix: 移除重复的代码行和错误信息 * fix: 重新排序 * fix: i18n sort * test * test * test * test * test * test * feat(i18n): 添加同步翻译脚本并重构检查脚本 重构 check-i18n 脚本为纯检查功能,不再自动修改翻译文件 新增 sync-i18n 脚本用于自动同步翻译文件结构 更新 package.json 添加 sync:i18n 命令 移除不再需要的 husky pre-commit.js 钩子 * docs(i18n): 移除未使用的测试翻译文本 * feat(scripts): 添加对象键名排序功能及测试 添加 lexicalSort 函数和 sortedObjectByKeys 函数用于按字典序排序对象键名 新增测试用例验证排序功能 * feat(i18n): 添加翻译文件键值排序检查功能 添加对i18n翻译文件键值字典序的检查功能,确保翻译文件保持一致的排序结构 * refactor(i18n): 优化同步逻辑并添加键排序功能 移除syncRecursively的返回值检查,简化同步流程 添加对翻译文件的键排序功能,使用sortedObjectByKeys工具 确保主模板和翻译文件在同步后都保持有序 * fix(i18n): 重新排序翻译文件 * style(scripts): 格式化sort.js * chore: 将 test:sort 重命名为 test:scripts
93 lines
2.6 KiB
TypeScript
93 lines
2.6 KiB
TypeScript
import { sortedObjectByKeys } from '../sort'
|
|
|
|
describe('sortedObjectByKeys', () => {
|
|
test('should sort keys of a flat object alphabetically', () => {
|
|
const obj = { b: 2, a: 1, c: 3 }
|
|
const sortedObj = { a: 1, b: 2, c: 3 }
|
|
expect(sortedObjectByKeys(obj)).toEqual(sortedObj)
|
|
})
|
|
|
|
test('should sort keys of nested objects alphabetically', () => {
|
|
const obj = {
|
|
c: { z: 3, y: 2, x: 1 },
|
|
a: 1,
|
|
b: { f: 6, d: 4, e: 5 }
|
|
}
|
|
const sortedObj = {
|
|
a: 1,
|
|
b: { d: 4, e: 5, f: 6 },
|
|
c: { x: 1, y: 2, z: 3 }
|
|
}
|
|
expect(sortedObjectByKeys(obj)).toEqual(sortedObj)
|
|
})
|
|
|
|
test('should handle empty objects', () => {
|
|
const obj = {}
|
|
expect(sortedObjectByKeys(obj)).toEqual({})
|
|
})
|
|
|
|
test('should handle objects with non-object values', () => {
|
|
const obj = { b: 'hello', a: 123, c: true }
|
|
const sortedObj = { a: 123, b: 'hello', c: true }
|
|
expect(sortedObjectByKeys(obj)).toEqual(sortedObj)
|
|
})
|
|
|
|
test('should handle objects with array values', () => {
|
|
const obj = { b: [2, 1], a: [1, 2] }
|
|
const sortedObj = { a: [1, 2], b: [2, 1] }
|
|
expect(sortedObjectByKeys(obj)).toEqual(sortedObj)
|
|
})
|
|
|
|
test('should handle objects with null values', () => {
|
|
const obj = { b: null, a: 1 }
|
|
const sortedObj = { a: 1, b: null }
|
|
expect(sortedObjectByKeys(obj)).toEqual(sortedObj)
|
|
})
|
|
|
|
test('should handle objects with undefined values', () => {
|
|
const obj = { b: undefined, a: 1 }
|
|
const sortedObj = { a: 1, b: undefined }
|
|
expect(sortedObjectByKeys(obj)).toEqual(sortedObj)
|
|
})
|
|
|
|
test('should not modify the original object', () => {
|
|
const obj = { b: 2, a: 1 }
|
|
sortedObjectByKeys(obj)
|
|
expect(obj).toEqual({ b: 2, a: 1 })
|
|
})
|
|
|
|
test('should handle objects read from i18n JSON files', () => {
|
|
const obj = {
|
|
translation: {
|
|
backup: {
|
|
progress: {
|
|
writing_data: '写入数据...',
|
|
preparing: '准备备份...',
|
|
completed: '备份完成'
|
|
}
|
|
},
|
|
agents: {
|
|
'delete.popup.content': '确定要删除此智能体吗?',
|
|
'edit.model.select.title': '选择模型'
|
|
}
|
|
}
|
|
}
|
|
const sortedObj = {
|
|
translation: {
|
|
agents: {
|
|
'delete.popup.content': '确定要删除此智能体吗?',
|
|
'edit.model.select.title': '选择模型'
|
|
},
|
|
backup: {
|
|
progress: {
|
|
completed: '备份完成',
|
|
preparing: '准备备份...',
|
|
writing_data: '写入数据...'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
expect(sortedObjectByKeys(obj)).toEqual(sortedObj)
|
|
})
|
|
})
|