chore: 版本 0.1.0 更新 默认 query-option 深拷贝导出与 schema 缺省回退
Node.js Build / build (push) Successful in 6s

This commit is contained in:
2026-08-07 16:42:01 +08:00
parent 23a7ebf668
commit e938118594
6 changed files with 212 additions and 6 deletions
+60
View File
@@ -0,0 +1,60 @@
import { afterEach, describe, expect, it } from 'vitest';
import { mount } from '@vue/test-utils';
import TransForm from '../src/TransForm.vue';
import { resetConfig, setConfig } from '../src/config.js';
// 每个用例后恢复全局配置,避免 setConfig 污染其它用例
afterEach(() => {
resetConfig();
});
describe('TransForm 操作符下拉(默认 query-option)', () => {
it('无 query-option 的字段渲染默认操作符列表(12 项,第一项 EQ)', () => {
const wrapper = mount(TransForm, {
props: { schema: [{ row: 12, field: 'name', 'field-name': '名称' }] },
});
const opts = wrapper.find('select').findAll('option');
expect(opts).toHaveLength(12);
expect(opts[0].text()).toBe('=');
expect(opts[0].attributes('value')).toBe('EQ');
expect(opts[11].text()).toBe('IS NOT NULL');
});
it('有 query-option 的字段仍渲染 schema 自己的选项(不被默认覆盖)', () => {
const wrapper = mount(TransForm, {
props: {
schema: [
{
row: 12,
field: 'status',
'field-name': '状态',
'query-option': [{ value: 'NE', label: '≠' }],
},
],
},
});
const opts = wrapper.find('select').findAll('option');
expect(opts).toHaveLength(1);
expect(opts[0].text()).toBe('≠');
expect(opts[0].attributes('value')).toBe('NE');
});
it('setConfig 自定义 queryOption 后,无 query-option 字段的下拉随之更新', () => {
setConfig({ queryOption: [{ value: 'GT', label: '>' }] });
const wrapper = mount(TransForm, {
props: { schema: [{ row: 12, field: 'age', 'field-name': '年龄' }] },
});
const opts = wrapper.find('select').findAll('option');
expect(opts).toHaveLength(1);
expect(opts[0].text()).toBe('>');
});
it('有 query-component 但无 query-option 的字段不套默认下拉(操作符由组件自己管理)', () => {
const wrapper = mount(TransForm, {
props: {
schema: [{ row: 12, field: 'custom', 'query-component': 'CustomQuery' }],
},
});
expect(wrapper.find('select').findAll('option')).toHaveLength(0);
});
});