fix(datepicker): set correct date ranges (#1021)

This commit is contained in:
kolaente 2025-06-25 13:26:39 +02:00 committed by GitHub
parent 58ebd52520
commit 0724c4b3e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 4 deletions

View File

@ -0,0 +1,39 @@
import {describe, it, expect, beforeEach} from 'vitest'
import {mount} from '@vue/test-utils'
import {setActivePinia, createPinia} from 'pinia'
import {createI18n} from 'vue-i18n'
import DatepickerWithRange from './DatepickerWithRange.vue'
import en from '@/i18n/lang/en.json'
const i18n = createI18n({legacy: false, locale: 'en', messages: {en}})
function mountPicker() {
return mount(DatepickerWithRange, {
props: {modelValue: {dateFrom: '', dateTo: ''}},
global: {
plugins: [i18n],
stubs: ['RouterLink', 'Modal', 'XButton', 'BaseButton', 'Popup', 'flat-pickr'],
},
})
}
describe('DatepickerWithRange predefined ranges', () => {
beforeEach(() => {
setActivePinia(createPinia())
})
it('selects Last Week range', async () => {
const wrapper = mountPicker()
;(wrapper.vm as any).setDateRange(['now/w-1w', 'now/w'])
await wrapper.vm.$nextTick()
const last = wrapper.emitted('update:modelValue')?.pop()?.[0]
expect(last).toEqual({dateFrom: 'now/w-1w', dateTo: 'now/w'})
})
it('selects Last Month range', async () => {
const wrapper = mountPicker()
;(wrapper.vm as any).setDateRange(['now/M-1M', 'now/M'])
await wrapper.vm.$nextTick()
const last = wrapper.emitted('update:modelValue')?.pop()?.[0]
expect(last).toEqual({dateFrom: 'now/M-1M', dateTo: 'now/M'})
})
})

View File

@ -4,13 +4,13 @@ export const DATE_RANGES = {
// is the "from" date, the second one is the "to" date.
'today': ['now/d', 'now/d+1d'],
'lastWeek': ['now/w-1w', 'now/w-2w'],
'lastWeek': ['now/w-1w', 'now/w'],
'thisWeek': ['now/w', 'now/w+1w'],
'restOfThisWeek': ['now', 'now/w+1w'],
'nextWeek': ['now/w+1w', 'now/w+2w'],
'next7Days': ['now', 'now+7d'],
'lastMonth': ['now/M-1M', 'now/M-2M'],
'lastMonth': ['now/M-1M', 'now/M'],
'thisMonth': ['now/M', 'now/M+1M'],
'restOfThisMonth': ['now', 'now/M+1M'],
'nextMonth': ['now/M+1M', 'now/M+2M'],
@ -26,7 +26,7 @@ export const DATE_VALUES = {
'endOfToday': 'now/d+1d',
'beginningOflastWeek': 'now/w-1w',
'endOfLastWeek': 'now/w-2w',
'endOfLastWeek': 'now/w',
'beginningOfThisWeek': 'now/w',
'endOfThisWeek': 'now/w+1w',
'startOfNextWeek': 'now/w+1w',
@ -34,7 +34,7 @@ export const DATE_VALUES = {
'in7Days': 'now+7d',
'beginningOfLastMonth': 'now/M-1M',
'endOfLastMonth': 'now/M-2M',
'endOfLastMonth': 'now/M',
'startOfThisMonth': 'now/M',
'endOfThisMonth': 'now/M+1M',
'startOfNextMonth': 'now/M+1M',