Skip to content

Commit 02810fd

Browse files
committed
test: Add test cases
1 parent 337ce14 commit 02810fd

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

tests/unit/behaviour.spec.ts

+77-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { describe, expect, it, vi } from 'vitest';
22
import {
33
add,
44
addDays,
@@ -20,10 +20,10 @@ import {
2020

2121
import { resetDateTime } from '@/utils/date-utils';
2222

23-
import { clickCalendarDate, clickSelectBtn, getMonthName, openMenu, reOpenMenu } from '../utils';
23+
import { clickCalendarDate, clickSelectBtn, getMonthName, hoverCalendarDate, openMenu, reOpenMenu } from '../utils';
2424
import { FlowStep } from '@/constants';
25-
import type { TimeModel, TimeType } from '@/interfaces';
26-
import type { VueWrapper } from '@vue/test-utils';
25+
import type { IMarker, TimeModel, TimeType } from '@/interfaces';
26+
import { type VueWrapper } from '@vue/test-utils';
2727
import { localToTz } from '@/utils/timezone';
2828

2929
describe('It should validate various picker scenarios', () => {
@@ -78,6 +78,7 @@ describe('It should validate various picker scenarios', () => {
7878
await clickCalendarDate(dp, date);
7979
const emitted = dp.emitted();
8080
expect(emitted).toHaveProperty('update:model-value', [[set(date, { seconds: 0, milliseconds: 0 })]]);
81+
dp.unmount();
8182
});
8283

8384
it('Should not switch calendars in 1 month range with multi-calendars enabled (#472)', async () => {
@@ -98,6 +99,7 @@ describe('It should validate various picker scenarios', () => {
9899

99100
expect(innerStartCell.classes()).toContain('dp__range_start');
100101
expect(innerEndCell.classes()).toContain('dp__range_end');
102+
dp.unmount();
101103
});
102104

103105
it('Should not enable partial range with text-input on time-picker (#505)', async () => {
@@ -106,7 +108,7 @@ describe('It should validate various picker scenarios', () => {
106108
const hours = getHours(today);
107109
const minutes = getMinutes(today);
108110

109-
const singleTime = `${hours}:${minutes}`;
111+
const singleTime = `${hours < 10 ? `0${hours}` : hours}:${minutes < 10 ? `0${minutes}` : minutes}`;
110112

111113
const input = dp.find('input');
112114
await input.setValue(singleTime);
@@ -118,6 +120,7 @@ describe('It should validate various picker scenarios', () => {
118120
expect(dp.emitted()).toHaveProperty('invalid-select', [
119121
[[set(new Date(), { hours, minutes, seconds: 0, milliseconds: 0 })]],
120122
]);
123+
dp.unmount();
121124
});
122125

123126
it('Should emit regular and zoned date value', async () => {
@@ -133,6 +136,7 @@ describe('It should validate various picker scenarios', () => {
133136

134137
expect(emitted).toHaveProperty('update:model-value', [[value]]);
135138
expect(emitted).toHaveProperty('update:model-timezone-value', [[localToTz(value, timezone)]]);
139+
dp.unmount();
136140
});
137141

138142
it('Should set predefined value in the time-picker and emit updated value', async () => {
@@ -466,6 +470,7 @@ describe('It should validate various picker scenarios', () => {
466470
await dp.find(`[data-test="select-button"]`).trigger('click');
467471

468472
expect(dp.emitted()['update:model-value']).toBeTruthy();
473+
dp.unmount();
469474
});
470475

471476
it('Should select preset date on month picker', async () => {
@@ -479,5 +484,72 @@ describe('It should validate various picker scenarios', () => {
479484
expect(dp.emitted()['update:model-value']).toEqual([
480485
[{ month: getMonth(yearStart), year: getYear(yearStart) }],
481486
]);
487+
dp.unmount();
488+
});
489+
490+
it('Should trigger customPosition function on the marker #933', async () => {
491+
const customPosition = vi.fn();
492+
const start = resetDateTime(startOfMonth(new Date()));
493+
const valid = start;
494+
const invalid = addDays(start, 1);
495+
const notCustom = addDays(start, 2);
496+
497+
const markers: IMarker[] = [
498+
{ date: valid, type: 'dot', tooltip: [{ text: 'my tooltip' }], customPosition },
499+
{ date: invalid, type: 'dot', customPosition },
500+
{ date: notCustom, type: 'dot', tooltip: [{ text: 'my tooltip' }] },
501+
];
502+
503+
const dp = await openMenu({ markers });
504+
505+
await hoverCalendarDate(dp, valid);
506+
expect(customPosition.mock.calls.length).toEqual(1);
507+
await hoverCalendarDate(dp, invalid);
508+
expect(customPosition.mock.calls.length).toEqual(1);
509+
await hoverCalendarDate(dp, notCustom);
510+
expect(customPosition.mock.calls.length).toEqual(1);
511+
dp.unmount();
512+
});
513+
514+
it('Should not close menu on auto-apply and partial flow #936', async () => {
515+
const flow = [FlowStep.calendar, FlowStep.time];
516+
const today = new Date();
517+
const dp = await openMenu({ flow, partialFlow: true, autoApply: true });
518+
await clickCalendarDate(dp, today);
519+
const overlay = dp.find('[aria-label="Time picker"]');
520+
expect(dp.emitted()).toHaveProperty('update:model-value');
521+
expect(overlay.exists()).toBeTruthy();
522+
dp.unmount();
523+
});
524+
525+
it('Should keep proper years when selecting auto-range on multi-calendars #909', async () => {
526+
const start = startOfMonth(new Date());
527+
const nextYear = getYear(addMonths(start, 1));
528+
const dp = await openMenu({ range: { autoRange: 5 }, multiCalendars: true });
529+
await clickCalendarDate(dp, start);
530+
const nextYearText = dp.find('[data-test="year-toggle-overlay-1"]').text();
531+
expect(nextYear).toEqual(+nextYearText);
532+
dp.unmount();
533+
});
534+
535+
it('Should toggle menu on text-input click if set #905', async () => {
536+
const dp = await openMenu({ textInput: { openMenu: 'toggle' } });
537+
await dp.find('[data-test="dp-input"]').trigger('click');
538+
const menu = dp.find('[role="dialog"]');
539+
expect(menu.exists()).toBeFalsy();
540+
await reOpenMenu(dp, { textInput: { openMenu: 'open' } });
541+
await dp.find('[data-test="dp-input"]').trigger('click');
542+
const menuShown = dp.find('[role="dialog"]');
543+
expect(menuShown.exists()).toBeTruthy();
544+
});
545+
546+
it('Should trigger @text-input event when typing date #909', async () => {
547+
const dp = await openMenu({ textInput: { openMenu: 'toggle' } });
548+
await dp.find('[data-test="dp-input"]').setValue('1');
549+
expect(dp.emitted()).toHaveProperty('text-input');
550+
expect(dp.emitted()['text-input']).toHaveLength(1);
551+
await dp.find('[data-test="dp-input"]').setValue('02');
552+
expect(dp.emitted()).toHaveProperty('text-input');
553+
expect(dp.emitted()['text-input']).toHaveLength(2);
482554
});
483555
});

tests/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export const clickCalendarDate = async (dp: VueWrapper<any>, date: Date) => {
3434
await dp.find(`[data-test="${resetDateTime(date)}"]`).trigger('click');
3535
};
3636

37+
export const hoverCalendarDate = async (dp: VueWrapper<any>, date: Date) => {
38+
await dp.find(`[data-test="${resetDateTime(date)}"]`).trigger('mouseenter');
39+
};
40+
3741
export const clickSelectBtn = async (dp: VueWrapper<any>) => {
3842
await dp.find(`[data-test="select-button"]`).trigger('click');
3943
};

0 commit comments

Comments
 (0)