20260915221013
This commit is contained in:
1 parent
1f56cc3efb
commit
dce29f250e
54 files changed
+3732
-574
No files matched your search
@@ -1,12 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildQueryCondition,
|
||||
defaultQueryValue,
|
||||
formatDateValue,
|
||||
parseOptions,
|
||||
} from '@/components/fms-module-list/moduleListUtils'
|
||||
import { buildConditionSql, defaultQueryValue } from '@/components/fms-module-common/queryUtils'
|
||||
import { formatDateValue, parseOptions } from '@/components/fms-module-common/fieldUtils'
|
||||
import { setMessages, translate } from '@/stores/i18n'
|
||||
|
||||
/** buildConditionSql 需要按字段名查到字段定义,b_type 决定字面量形式(数字裸写 / 文本 N'...') */
|
||||
function fieldMapOf(...fields) {
|
||||
return new Map(fields.map((field) => [field.b_field, field]))
|
||||
}
|
||||
|
||||
function item(over = {}) {
|
||||
return {
|
||||
field: { b_field: 'amount', b_type: 'money', b_options: '' },
|
||||
@@ -24,26 +25,31 @@ describe('fms-module-list query utilities', () => {
|
||||
})
|
||||
|
||||
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",
|
||||
buildConditionSql(
|
||||
{ field: 'amount', operator: 'eq', value: 12.5 },
|
||||
fieldMapOf({ b_field: 'amount', b_type: 'money' }),
|
||||
),
|
||||
).toBe('[amount] = 12.5')
|
||||
expect(
|
||||
buildConditionSql(
|
||||
{ field: 'name', operator: 'like', value: "O'Reilly" },
|
||||
fieldMapOf({ b_field: 'name', b_type: 'input' }),
|
||||
),
|
||||
).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'],
|
||||
buildConditionSql(
|
||||
{ field: 'created', operator: 'between', value: ['2026-01-01', '2026-01-31'] },
|
||||
fieldMapOf({ b_field: 'created', b_type: 'date' }),
|
||||
),
|
||||
).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'],
|
||||
buildConditionSql(
|
||||
{ field: 'status', operator: 'in', value: ['a', '', 'b'] },
|
||||
fieldMapOf({ b_field: 'status', b_type: 'input' }),
|
||||
),
|
||||
).toBe("[status] IN (N'a', N'b')")
|
||||
})
|
||||
@@ -68,4 +74,18 @@ describe('fms-module-list query utilities', () => {
|
||||
expect(formatDateValue('2026-08-01T12:34:56Z')).toMatch(/^2026-08-01/)
|
||||
expect(formatDateValue(null)).toBe('')
|
||||
})
|
||||
|
||||
/**
|
||||
* 时间契约:后端统一输出「显示格式」的墙钟串(见后端 DbUtils.normalizeJdbcValue,
|
||||
* 与旧项目读取 ResultSet 时格式化的做法一致):
|
||||
* date → "2026-09-15",datetime → "2026-09-15 21:16:47",即拿即显示、不做时区换算。
|
||||
* 展示层对标准输入应为透传;仅非标准输入(数字时间戳等)走 Date 兜底。
|
||||
*/
|
||||
it('passes through display-format strings without timezone math', () => {
|
||||
expect(formatDateValue('2026-09-15 21:16:47', true)).toBe('2026-09-15 21:16:47')
|
||||
expect(formatDateValue('2026-09-15 21:16:47', false)).toBe('2026-09-15')
|
||||
expect(formatDateValue('2026-09-15', false)).toBe('2026-09-15')
|
||||
// 非日期开头的输入(数字时间戳等)仍走 Date 兜底,按本地时间格式化
|
||||
expect(formatDateValue(1789471007000, true)).toMatch(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user