- 基于 grill-me Q1-Q61 决策 - Vitest 测试与 CI workflow - middleware: parseFilters 核心实现 - component: Vue3 TransForm 基础组件 + Storybook Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
applyFilters,
|
||||
buildFilters,
|
||||
createFieldState,
|
||||
groupRows,
|
||||
} from '../src/composables/useFilters.js';
|
||||
|
||||
const schema = [
|
||||
{
|
||||
row: 6,
|
||||
field: 'name',
|
||||
'field-name': '名称',
|
||||
'query-option': [{ value: 'EQ', label: '=' }],
|
||||
},
|
||||
{
|
||||
row: 6,
|
||||
logic: 'OR',
|
||||
field: 'status',
|
||||
'query-option': [{ value: 'NE', label: '≠' }],
|
||||
},
|
||||
];
|
||||
|
||||
describe('createFieldState', () => {
|
||||
it('initializes default query from first option', () => {
|
||||
const state = createFieldState(schema);
|
||||
expect(state.name.query).toBe('EQ');
|
||||
expect(state.status.logic).toBe('OR');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildFilters', () => {
|
||||
it('emits logic from second item onward', () => {
|
||||
const state = createFieldState(schema);
|
||||
state.name.value = 'alice';
|
||||
state.status.value = 'active';
|
||||
const filters = buildFilters(schema, state);
|
||||
expect(filters[0].logic).toBeUndefined();
|
||||
expect(filters[1].logic).toBe('OR');
|
||||
});
|
||||
|
||||
it('marks empty values', () => {
|
||||
const state = createFieldState(schema);
|
||||
const filters = buildFilters(schema, state);
|
||||
expect(filters[0].empty).toBe(true);
|
||||
expect(filters[0].value).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('applyFilters', () => {
|
||||
it('loads filters back into state', () => {
|
||||
const loaded = applyFilters(schema, [
|
||||
{ field: 'name', value: 'bob', query: 'EQ' },
|
||||
]);
|
||||
expect(loaded.name.value).toBe('bob');
|
||||
});
|
||||
});
|
||||
|
||||
describe('groupRows', () => {
|
||||
it('wraps when row spans exceed 12', () => {
|
||||
const groups = groupRows([
|
||||
{ row: 2, field: 'a' },
|
||||
{ row: 9, field: 'b' },
|
||||
{ row: 4, field: 'c' },
|
||||
]);
|
||||
expect(groups).toHaveLength(2);
|
||||
expect(groups[0]).toHaveLength(2);
|
||||
expect(groups[1]).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user