20260923230500

This commit is contained in:
oneao committed 2026-09-23 23:05:01 +08:00
1 parent e6935b8fa4
commit 0405cd198a
36 files changed
+3668 -911

No files matched your search

@@ -3,6 +3,7 @@ import {
astToSql,
buildFilterStateAst,
buildKeywordAst,
buildKeywordPlaceholder,
buildQuickAst,
buildViewAst,
combineAst,
@@ -145,6 +146,26 @@ describe('查询入口 → AST(页签 / 关键词 / 快捷筛选 / 更多筛
expect(buildViewAst({ code: 'all' }, fields)).toBeNull()
})
it('页签条件为 SQL 片段时整段成组,优先于旧结构 conditions', () => {
const view = {
code: 'pending',
conditionSql: "b_status = N'1'",
conditions: [{ field: 'status', operator: 'eq', value: '失败' }],
}
expect(astToSql(buildViewAst(view, fields), fields)).toBe("(b_status = N'1')")
expect(buildViewAst({ code: 'all', conditionSql: ' ' }, fields)).toBeNull()
})
it('页签 SQL 与其他来源按「且」合并', () => {
const ast = combineAst(
buildViewAst({ code: 'pending', conditionSql: "b_status = N'1'" }, fields),
buildKeywordAst('东方', [{ field: fields.get('name'), config: {} }]),
)
expect(astToSql(ast, fields)).toBe(
"((b_status = N'1') AND ([name] LIKE N'%东方%'))",
)
})
it('关键词跨字段取「或」,空关键词不产生条件', () => {
const items = [
{ field: fields.get('name'), config: {} },
@@ -213,4 +234,22 @@ describe('查询入口 → AST(页签 / 关键词 / 快捷筛选 / 更多筛
expect(describeConditionText({ field: 'name', operator: 'like', value: '' }, items)).toBe('')
expect(describeConditionText({ field: 'ghost', operator: 'eq', value: 'x' }, items)).toBe('')
})
it('关键词占位文案按字段名生成:多于 5 个只列前 5 个加「等」', () => {
const makeItems = (labels) =>
labels.map((label, index) => ({
field: { b_field: `f${index}`, b_name: label, b_type: 'input' },
}))
expect(buildKeywordPlaceholder(makeItems(['单号', '客户']))).toBe('搜索 单号、客户')
expect(buildKeywordPlaceholder([])).toBe('')
expect(
buildKeywordPlaceholder(makeItems(['a', 'b', 'c', 'd', 'e', 'f'])),
).toBe('搜索 a、b、c、d、e 等')
// 传入翻译函数时前缀与「等」走多语言
expect(
buildKeywordPlaceholder(makeItems(['Order No']), (key, fallback) =>
key === 'common.keywordSearch' ? 'Search' : fallback,
),
).toBe('Search Order No')
})
})