20260903173038
This commit is contained in:
1 parent
c8940f6e03
commit
0faf44cffc
55 files changed
+3278
-208
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildQueryCondition,
|
||||
defaultQueryValue,
|
||||
formatDateValue,
|
||||
parseOptions,
|
||||
} from '@/components/fms-module-list/moduleListUtils'
|
||||
import { setMessages, translate } from '@/utils/translate'
|
||||
|
||||
function item(over = {}) {
|
||||
return {
|
||||
field: { b_field: 'amount', b_type: 'money', b_options: '' },
|
||||
config: { b_operator: 'eq', b_component: 'number' },
|
||||
...over,
|
||||
}
|
||||
}
|
||||
|
||||
describe('fms-module-list query utilities', () => {
|
||||
it('uses a standalone translation catalog and fallback text', () => {
|
||||
setMessages({ 'common.search': '查询' }, 'zh-CN')
|
||||
expect(translate('common.search', '搜索')).toBe('查询')
|
||||
expect(translate('common.reset', '重置')).toBe('重置')
|
||||
setMessages({})
|
||||
})
|
||||
|
||||
it('builds numeric and escaped text conditions', () => {
|
||||
expect(buildQueryCondition(item(), 12.5)).toBe('[amount] = 12.5')
|
||||
expect(
|
||||
buildQueryCondition(
|
||||
item({ field: { b_field: 'name', b_type: 'input' }, config: { b_operator: 'like' } }),
|
||||
"O'Reilly",
|
||||
),
|
||||
).toBe("[name] LIKE N'%O''Reilly%'")
|
||||
})
|
||||
|
||||
it('builds range and IN conditions while ignoring empty values', () => {
|
||||
expect(
|
||||
buildQueryCondition(
|
||||
item({ field: { b_field: 'created', b_type: 'date' }, config: { b_operator: 'between' } }),
|
||||
['2026-01-01', '2026-01-31'],
|
||||
),
|
||||
).toBe("[created] BETWEEN N'2026-01-01' AND N'2026-01-31'")
|
||||
expect(
|
||||
buildQueryCondition(
|
||||
item({ field: { b_field: 'status', b_type: 'input' }, config: { b_operator: 'in' } }),
|
||||
['a', '', 'b'],
|
||||
),
|
||||
).toBe("[status] IN (N'a', N'b')")
|
||||
})
|
||||
|
||||
it('parses options and normalizes defaults', () => {
|
||||
const parsed = parseOptions({ b_options: '{"options":[{"key":"1","name":"启用"},"2"]}' })
|
||||
expect(parsed.options).toEqual([
|
||||
{ key: '1', name: '启用', value: '1', label: '启用' },
|
||||
{ value: '2', label: '2' },
|
||||
])
|
||||
expect(
|
||||
defaultQueryValue(
|
||||
item({
|
||||
field: { b_field: 'status', b_type: 'input' },
|
||||
config: { b_operator: 'in', b_default_value: 'a,b' },
|
||||
}),
|
||||
),
|
||||
).toEqual(['a', 'b'])
|
||||
})
|
||||
|
||||
it('formats ISO dates consistently', () => {
|
||||
expect(formatDateValue('2026-08-01T12:34:56Z')).toMatch(/^2026-08-01/)
|
||||
expect(formatDateValue(null)).toBe('')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user