Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
fix(calendar): render marks in months other than the current month
Browse files Browse the repository at this point in the history
  • Loading branch information
b2nil committed Mar 5, 2021
1 parent 276517e commit 5772de5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ exports[`AtCalendar should render default calendar -- h5 1`] = `
<view class="container-text">27</view>
</view>
<view class="flex__item-extra extra">
<!---->
<view class="extra-marks"><text class="mark">2020-11-27</text></view>
</view>
</view>
<view class="flex__item flex__item--now">
Expand Down Expand Up @@ -323,7 +323,7 @@ exports[`AtCalendar should render default calendar -- h5 1`] = `
<view class="container-text">1</view>
</view>
<view class="flex__item-extra extra">
<!---->
<view class="extra-marks"><text class="mark">2020-12-01</text></view>
</view>
</view>
<view class="flex__item flex__item--next flex__item--blur">
Expand Down Expand Up @@ -383,7 +383,7 @@ exports[`AtCalendar should render default calendar -- h5 1`] = `
<view class="container-text">1</view>
</view>
<view class="flex__item-extra extra">
<!---->
<view class="extra-marks"><text class="mark">2020-12-01</text></view>
</view>
</view>
<view class="flex__item flex__item--now">
Expand Down Expand Up @@ -610,7 +610,7 @@ exports[`AtCalendar should render default calendar -- h5 1`] = `
<!---->
</view>
</view>
<view class="flex__item flex__item--now flex__item--today">
<view class="flex__item flex__item--now">
<view class="flex__item-container">
<view class="container-text">30</view>
</view>
Expand Down
21 changes: 14 additions & 7 deletions src/components/calendar/__tests__/calendar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import { mountFactory } from '@/tests/helper'
import AtCalendar from '../index'
import Taro from '@tarojs/taro'

const today = new Date()
const dString = today.toISOString().substring(0, 7)

describe('AtCalendar', () => {
it('should render default calendar -- h5', () => {
const wrapper = mountFactory(AtCalendar, undefined, { currentDate: '2020-12-27' })
const wrapper = mountFactory(AtCalendar, undefined, {
currentDate: '2020-12-27',
marks: [{ value: "2020-11-27" }, { value: "2020-12-01" }]
})
expect(wrapper.html()).toMatchSnapshot()
expect(wrapper.find('.main > .main__body > .body__slider--pre').exists()).toBeTruthy()
expect(wrapper.find('.main > .main__body > .body__slider--now').exists()).toBeTruthy()
Expand Down Expand Up @@ -81,12 +87,13 @@ describe('AtCalendar', () => {
})

it('should render marks', async () => {
const wrapper = mountFactory(AtCalendar)
expect(wrapper.findAll('.mark').length).toBe(0)

await wrapper.setProps({ marks: [{ value: '2020-12-27' }, { value: '2020-12-28' }] })
today.setDate(today.getDate() - 28)
const prevM = new Date(today).toISOString().substring(0, 10)
const wrapper = mountFactory(AtCalendar, undefined, { marks: [{ value: prevM }] })
expect(wrapper.findAll('.mark').length).toBe(1)
await wrapper.setProps({ marks: [{ value: `${dString}-21` }, { value: prevM }, { value: `${dString}-23` }] })
wrapper.vm.$nextTick()
expect(wrapper.findAll('.mark').length).toBe(2)
expect(wrapper.findAll('.mark').length).toBe(3)
})

it('should render minDate and maxDate', () => {
Expand Down Expand Up @@ -124,7 +131,7 @@ describe('AtCalendar', () => {

it('should render valid dates', () => {
const wrapper = mountFactory(AtCalendar, undefined, {
validDates: [{ value: '2020-12-27' }, { value: '2020-12-28' }]
validDates: [{ value: `${dString}-21` }, { value: `${dString}-25` }]
})

expect(
Expand Down
6 changes: 6 additions & 0 deletions src/components/calendar/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ function getFullItem(
selectedDate: Calendar.SelectedDate,
isShowStatus?: boolean
) {
if (options.marks.find(x => x.value === item.value)) {
(item.marks as Array<Calendar.Mark>) = [{
value: item.value as string
}]
}

if (!isShowStatus) return item

const bindedPlugins = plugins.map(fn =>
Expand Down
2 changes: 1 addition & 1 deletion src/components/calendar/ui/date-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const AtCalendarList = defineComponent({
h(Text, {
key: key,
class: 'mark'
}, { default: () => String(mark) })
}, { default: () => mark.value })
))
})
)
Expand Down

0 comments on commit 5772de5

Please sign in to comment.