mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(TimePicker): should update modelValue correctly (#11804)
This commit is contained in:
parent
9105243850
commit
f3fa7e7bd5
@ -1,4 +1,4 @@
|
||||
import { extend, padZero, makeArrayProp } from '../utils';
|
||||
import { extend, padZero, makeArrayProp, clamp } from '../utils';
|
||||
import { pickerSharedProps } from '../picker/Picker';
|
||||
import type { PropType } from 'vue';
|
||||
import type { PickerOption } from '../picker';
|
||||
@ -58,10 +58,9 @@ export const formatValueRange = (values: string[], columns: PickerOption[]) =>
|
||||
values.map((value, index) => {
|
||||
const column = columns[index];
|
||||
if (column.length) {
|
||||
const minValue = +column[0].value!;
|
||||
const maxValue = +column[column.length - 1].value!;
|
||||
if (+value > maxValue) {
|
||||
return String(maxValue);
|
||||
}
|
||||
return padZero(clamp(+value, minValue, maxValue));
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
@ -20,18 +20,59 @@ test('should format initial value correctly', () => {
|
||||
expect(onUpdate.mock.calls[0]).toEqual([['22', '58']]);
|
||||
});
|
||||
|
||||
test('should update modelValue correctly when using max-hour and max-minute prop', () => {
|
||||
const onUpdate = jest.fn();
|
||||
mount(TimePicker, {
|
||||
props: {
|
||||
modelValue: ['23', '59'],
|
||||
maxHour: 2,
|
||||
maxMinute: 2,
|
||||
'onUpdate:modelValue': onUpdate,
|
||||
},
|
||||
describe('should update modelValue correctly', () => {
|
||||
test('basic', async () => {
|
||||
const onUpdate = jest.fn();
|
||||
const wrapper = mount(TimePicker, {
|
||||
props: {
|
||||
modelValue: ['-10', '-10'],
|
||||
'onUpdate:modelValue': onUpdate,
|
||||
},
|
||||
});
|
||||
|
||||
await wrapper.setProps({ modelValue: ['30', '80'] });
|
||||
await wrapper.setProps({ modelValue: ['2', '2'] });
|
||||
|
||||
expect(onUpdate.mock.calls[0]).toEqual([['00', '00']]);
|
||||
expect(onUpdate.mock.calls[1]).toEqual([['23', '59']]);
|
||||
expect(onUpdate.mock.calls[2]).toEqual([['02', '02']]);
|
||||
});
|
||||
|
||||
expect(onUpdate.mock.calls[0]).toEqual([['00', '00']]);
|
||||
test('when using max-hour and max-minute prop', async () => {
|
||||
const onUpdate = jest.fn();
|
||||
const wrapper = mount(TimePicker, {
|
||||
props: {
|
||||
modelValue: ['23', '59'],
|
||||
maxHour: 2,
|
||||
maxMinute: 2,
|
||||
'onUpdate:modelValue': onUpdate,
|
||||
},
|
||||
});
|
||||
|
||||
await wrapper.setProps({ maxHour: 12, maxMinute: 12 });
|
||||
await wrapper.setProps({ modelValue: ['23', '59'] });
|
||||
|
||||
expect(onUpdate.mock.calls[0]).toEqual([['02', '02']]);
|
||||
expect(onUpdate.mock.calls[1]).toEqual([['12', '12']]);
|
||||
});
|
||||
|
||||
test('when using min-hour and min-minute prop', async () => {
|
||||
const onUpdate = jest.fn();
|
||||
const wrapper = mount(TimePicker, {
|
||||
props: {
|
||||
modelValue: ['00', '00'],
|
||||
minHour: 2,
|
||||
minMinute: 2,
|
||||
'onUpdate:modelValue': onUpdate,
|
||||
},
|
||||
});
|
||||
|
||||
await wrapper.setProps({ minHour: 12, minMinute: 12 });
|
||||
await wrapper.setProps({ modelValue: ['00', '00'] });
|
||||
|
||||
expect(onUpdate.mock.calls[0]).toEqual([['02', '02']]);
|
||||
expect(onUpdate.mock.calls[1]).toEqual([['12', '12']]);
|
||||
});
|
||||
});
|
||||
|
||||
test('should filter options when using filter prop', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user