20260919211702
This commit is contained in:
1 parent
f56e70b050
commit
f4bfc1ddfc
97 files changed
+6059
-1712
No files matched your search
@@ -1,16 +1,15 @@
|
||||
/**
|
||||
* 删除规则编辑弹窗(ModuleRuleEditModal):
|
||||
* - 勾条件 → predicate 存 {"kind":"dsl","expr":AST};写 SQL → predicate 存文本;
|
||||
* - 两种类型各自的必填校验(无条件 / 缺提示文案)不通过时不提交;
|
||||
* - 打开时按 predicate 三态回显类型与内容;标题按新增/编辑切换。
|
||||
* 删除 SQL 规则编辑弹窗(ModuleRuleEditModal):
|
||||
* - 只编辑 b_sql + b_message:SQL 必填、必须只读、必须含 :ids;提示文案必填;
|
||||
* - 校验不通过时不提交(不 emit ok);
|
||||
* - 打开时按当前行回显 SQL 与文案;标题按新增/编辑切换。
|
||||
*/
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { nextTick } from 'vue'
|
||||
import ModuleRuleEditModal from '@/views/module/module-management/ModuleRuleEditModal.vue'
|
||||
import { buildRuleQueryItems } from '@/views/module/module-management/ruleUtils'
|
||||
import { IDS_PLACEHOLDER } from '@/views/module/module-management/ruleUtils'
|
||||
|
||||
vi.mock('@/services/api', () => ({ loadDataApi: vi.fn() }))
|
||||
|
||||
@@ -28,32 +27,21 @@ beforeAll(() => {
|
||||
})
|
||||
})
|
||||
|
||||
const ITEMS = buildRuleQueryItems(
|
||||
[
|
||||
{ b_field: 'b_status', b_name: '状态', b_type: 'select', b_canuse: 1 },
|
||||
{ b_field: 'b_no', b_name: '单号', b_type: 'input', b_canuse: 1 },
|
||||
],
|
||||
{},
|
||||
)
|
||||
|
||||
const ruleRow = () => ({
|
||||
_rowKey: '-1',
|
||||
b_id: '1900000000000000001',
|
||||
b_scope_type: 'module',
|
||||
b_scope_id: 'order',
|
||||
b_hook: 'delete.pre',
|
||||
b_predicate: null,
|
||||
b_message: null,
|
||||
b_module_id: 'order',
|
||||
b_sql: `select b_id from bill where b_id in (${IDS_PLACEHOLDER})`,
|
||||
b_message: '单据已销账,不能删除',
|
||||
b_canuse: 1,
|
||||
b_xh: 10,
|
||||
})
|
||||
|
||||
async function mountModal(row = ruleRow(), isNew = false) {
|
||||
const pinia = createPinia()
|
||||
pinia.install({ provide() {}, config: { globalProperties: {} } })
|
||||
setActivePinia(pinia)
|
||||
const wrapper = mount(ModuleRuleEditModal, {
|
||||
props: { open: true, row, isNew, items: ITEMS },
|
||||
props: { open: true, row, isNew },
|
||||
global: { plugins: [pinia] },
|
||||
attachTo: document.body,
|
||||
})
|
||||
@@ -66,57 +54,9 @@ beforeEach(() => {
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
|
||||
describe('删除规则编辑弹窗', () => {
|
||||
it('勾条件:没有条件时不提交,选了条件后按 AST 组装 predicate', async () => {
|
||||
const row = ruleRow()
|
||||
const wrapper = await mountModal(row)
|
||||
|
||||
await wrapper.vm.onOk()
|
||||
expect(wrapper.vm.conditionError).toBe('勾条件规则至少要有一个条件')
|
||||
expect(wrapper.emitted('ok')).toBeFalsy()
|
||||
|
||||
wrapper.vm.conditionState = {
|
||||
nodes: [{ id: 'n1', at: 1, join: 'and', field: 'b_status', operator: 'eq', value: 'audit' }],
|
||||
groups: [],
|
||||
}
|
||||
await nextTick()
|
||||
expect(wrapper.vm.conditionSummary).toBe('状态 等于 audit')
|
||||
|
||||
await wrapper.vm.onOk()
|
||||
const saved = wrapper.emitted('ok')?.[0]?.[0]
|
||||
expect(saved.b_hook).toBe('delete.pre')
|
||||
const predicate = JSON.parse(saved.b_predicate)
|
||||
expect(predicate.kind).toBe('dsl')
|
||||
expect(predicate.expr.children[0]).toMatchObject({
|
||||
type: 'condition',
|
||||
field: 'b_status',
|
||||
operator: 'eq',
|
||||
value: 'audit',
|
||||
})
|
||||
expect(wrapper.emitted('update:open')?.at(-1)).toEqual([false])
|
||||
})
|
||||
|
||||
it('写 SQL:缺提示文案不提交,填好后原样存文本', async () => {
|
||||
const row = ruleRow()
|
||||
const wrapper = await mountModal(row)
|
||||
wrapper.vm.ruleType = 'sql'
|
||||
wrapper.vm.sqlText = 'select b_id from bill where b_id in (:ids) and b_settled = 1'
|
||||
await nextTick()
|
||||
|
||||
await wrapper.vm.onOk()
|
||||
expect(wrapper.vm.sqlError).toBe('写 SQL 的规则必须填写提示文案')
|
||||
expect(wrapper.emitted('ok')).toBeFalsy()
|
||||
|
||||
row.b_message = '单据已销账,不能删除'
|
||||
await wrapper.vm.onOk()
|
||||
expect(wrapper.emitted('ok')?.[0]?.[0].b_predicate).toBe(
|
||||
'select b_id from bill where b_id in (:ids) and b_settled = 1',
|
||||
)
|
||||
})
|
||||
|
||||
it('写 SQL:SQL 为空时不提交', async () => {
|
||||
const wrapper = await mountModal(ruleRow())
|
||||
wrapper.vm.ruleType = 'sql'
|
||||
describe('删除 SQL 规则编辑弹窗', () => {
|
||||
it('SQL 为空时不提交', async () => {
|
||||
const wrapper = await mountModal()
|
||||
wrapper.vm.sqlText = ' '
|
||||
await nextTick()
|
||||
|
||||
@@ -125,15 +65,59 @@ describe('删除规则编辑弹窗', () => {
|
||||
expect(wrapper.emitted('ok')).toBeFalsy()
|
||||
})
|
||||
|
||||
it('回显与标题:SQL 类型直接进 SQL 分支;新增/编辑标题不同', async () => {
|
||||
const row = { ...ruleRow(), b_predicate: 'select 1 as b_id' }
|
||||
const wrapper = await mountModal(row, true)
|
||||
it('SQL 非只读时不提交', async () => {
|
||||
const wrapper = await mountModal()
|
||||
wrapper.vm.sqlText = `delete from bill where b_id in (${IDS_PLACEHOLDER})`
|
||||
await nextTick()
|
||||
|
||||
expect(wrapper.vm.ruleType).toBe('sql')
|
||||
expect(wrapper.vm.sqlText).toBe('select 1 as b_id')
|
||||
await wrapper.vm.onOk()
|
||||
expect(wrapper.vm.sqlError).toBe('规则 SQL 必须是只读查询(以 select 或 with 开头)')
|
||||
expect(wrapper.emitted('ok')).toBeFalsy()
|
||||
})
|
||||
|
||||
it('SQL 缺少 :ids 标记时不提交', async () => {
|
||||
const wrapper = await mountModal()
|
||||
wrapper.vm.sqlText = 'select b_id from bill'
|
||||
await nextTick()
|
||||
|
||||
await wrapper.vm.onOk()
|
||||
expect(wrapper.vm.sqlError).toBe('规则 SQL 必须包含 :ids 标记,用于限定本次待删记录')
|
||||
expect(wrapper.emitted('ok')).toBeFalsy()
|
||||
})
|
||||
|
||||
it('缺提示文案时不提交,填好后原样存 SQL 与文案', async () => {
|
||||
const row = { ...ruleRow(), b_message: '' }
|
||||
const wrapper = await mountModal(row)
|
||||
wrapper.vm.sqlText = `select b_id from bill where b_id in (${IDS_PLACEHOLDER}) and b_settled = 1`
|
||||
await nextTick()
|
||||
|
||||
await wrapper.vm.onOk()
|
||||
expect(wrapper.vm.messageError).toBe('请填写提示文案')
|
||||
expect(wrapper.emitted('ok')).toBeFalsy()
|
||||
|
||||
wrapper.vm.messageText = '单据已销账,不能删除'
|
||||
await nextTick()
|
||||
await wrapper.vm.onOk()
|
||||
|
||||
const saved = wrapper.emitted('ok')?.[0]?.[0]
|
||||
expect(saved.b_sql).toBe(
|
||||
`select b_id from bill where b_id in (${IDS_PLACEHOLDER}) and b_settled = 1`,
|
||||
)
|
||||
expect(saved.b_message).toBe('单据已销账,不能删除')
|
||||
// 旧字段不再写入
|
||||
expect(saved.b_predicate).toBeUndefined()
|
||||
expect(saved.b_hook).toBeUndefined()
|
||||
expect(wrapper.emitted('update:open')?.at(-1)).toEqual([false])
|
||||
})
|
||||
|
||||
it('回显与标题:按当前行还原 SQL 与文案;新增/编辑标题不同', async () => {
|
||||
const wrapper = await mountModal({ ...ruleRow() }, true)
|
||||
|
||||
expect(wrapper.vm.sqlText).toBe(`select b_id from bill where b_id in (${IDS_PLACEHOLDER})`)
|
||||
expect(wrapper.vm.messageText).toBe('单据已销账,不能删除')
|
||||
expect(wrapper.vm.modalTitle).toBe('新增删除规则')
|
||||
|
||||
const editWrapper = await mountModal({ ...ruleRow() }, false)
|
||||
const editWrapper = await mountModal(ruleRow(), false)
|
||||
expect(editWrapper.vm.modalTitle).toBe('编辑删除规则')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user