mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-11-07 10:30:42 +00:00
- 日期类字段 change 时经 normalizeTimestampValue 把选择器输出收成秒级 number,避免 Element Plus 写出秒字符串导致校验失败 - Date/DateTime/Time/Daterange/Timerange 回填 model 时,valueFormat 为 X 直接使用秒级数字,不再拼接展示格式 - typeMatch 对 X 格式要求有限整数,示例值与报错文案区分秒级/毫秒级 - datetimeFormatter 支持 X 格式输出秒级数字 - 补充相应单元测试,并更新 docs/form-config/rules.md 中的校验规则说明
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
/*
|
|
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
*
|
|
* Copyright (C) 2025 Tencent.
|
|
*/
|
|
import { describe, expect, test } from 'vitest';
|
|
import { nextTick } from 'vue';
|
|
import { mount } from '@vue/test-utils';
|
|
import ElementPlus from 'element-plus';
|
|
|
|
import MagicForm, { MForm, MTimerange } from '@form/index';
|
|
|
|
const mountForm = (config: any[], initValues: any) =>
|
|
mount(MForm, {
|
|
global: { plugins: [ElementPlus as any, MagicForm as any] },
|
|
props: { config, initValues },
|
|
});
|
|
|
|
describe('Timerange', () => {
|
|
test('单 name 渲染', async () => {
|
|
const wrapper = mountForm([{ name: 'tr', type: 'timerange', text: 'tr' }], { tr: ['08:00:00', '20:00:00'] });
|
|
await nextTick();
|
|
expect(wrapper.findComponent(MTimerange).exists()).toBe(true);
|
|
});
|
|
|
|
test('双 names 渲染', async () => {
|
|
const wrapper = mountForm([{ name: 'tr', type: 'timerange', text: 'tr', names: ['start', 'end'] }], {
|
|
start: '08:00:00',
|
|
end: '20:00:00',
|
|
});
|
|
await nextTick();
|
|
expect(wrapper.findComponent(MTimerange).exists()).toBe(true);
|
|
});
|
|
|
|
test('valueFormat 为 X 时区间收成秒数字', async () => {
|
|
const wrapper = mountForm([{ name: 'tr', type: 'timerange', text: 'tr', valueFormat: 'X' }], {
|
|
tr: [1626507420, 1626593820],
|
|
});
|
|
|
|
await nextTick();
|
|
|
|
wrapper.findComponent({ name: 'TMTimePicker' }).vm.$emit('change', ['1626507420', '1626593820']);
|
|
await nextTick();
|
|
|
|
expect((wrapper.vm as any).values.tr).toEqual([1626507420, 1626593820]);
|
|
});
|
|
|
|
test('valueFormat 为 X 且 names 时分别写入秒数字', async () => {
|
|
const wrapper = mountForm([{ type: 'timerange', text: 'tr', names: ['start', 'end'], valueFormat: 'X' }], {
|
|
start: 1626507420,
|
|
end: 1626593820,
|
|
});
|
|
|
|
await nextTick();
|
|
|
|
wrapper.findComponent({ name: 'TMTimePicker' }).vm.$emit('change', ['1626507420', '1626593820']);
|
|
await nextTick();
|
|
|
|
expect((wrapper.vm as any).values.start).toBe(1626507420);
|
|
expect((wrapper.vm as any).values.end).toBe(1626593820);
|
|
});
|
|
});
|