feat(Calendar): add multiple type (#5705)

This commit is contained in:
chenjiahan
2020-03-03 21:02:00 +08:00
parent c4be70c4e8
commit 6d19ad590b
9 changed files with 249 additions and 49 deletions
@@ -7,6 +7,10 @@ exports[`renders demo correctly 1`] = `
<div class="van-cell__title"><span>选择单个日期</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
<!----></i>
</div>
<div role="button" tabindex="0" class="van-cell van-cell--clickable">
<div class="van-cell__title"><span>选择多个日期</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
<!----></i>
</div>
<div role="button" tabindex="0" class="van-cell van-cell--clickable">
<div class="van-cell__title"><span>选择日期区间</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
<!----></i>
+34
View File
@@ -18,6 +18,10 @@ function formatRange([start, end]) {
return `${formatDate(start)}-${formatDate(end)}`;
}
function formatMultiple(dates) {
return dates.map(formatDate).join(',');
}
test('select event when type is single', async () => {
const wrapper = mount(Calendar, {
propsData: {
@@ -63,6 +67,36 @@ test('select event when type is range', async () => {
expect(formatRange(emittedSelect[3][0])).toEqual('2010/1/13-');
});
test('select event when type is multiple', async () => {
const wrapper = mount(Calendar, {
propsData: {
type: 'multiple',
minDate,
maxDate,
poppable: false,
},
});
await later();
const days = wrapper.findAll('.van-calendar__day');
days.at(15).trigger('click');
days.at(16).trigger('click');
await later();
days.at(15).trigger('click');
days.at(12).trigger('click');
const emittedSelect = wrapper.emitted('select');
expect(formatMultiple(emittedSelect[0][0])).toEqual('2010/1/10,2010/1/16');
expect(formatMultiple(emittedSelect[1][0])).toEqual(
'2010/1/10,2010/1/16,2010/1/17'
);
expect(formatMultiple(emittedSelect[2][0])).toEqual(
'2010/1/10,2010/1/17,2010/1/13'
);
});
test('should not trigger select event when click disabled day', async () => {
const wrapper = mount(Calendar, {
propsData: {