1
- import { describe , expect , it } from 'vitest' ;
1
+ import { describe , expect , it , vi } from 'vitest' ;
2
2
import {
3
3
add ,
4
4
addDays ,
@@ -20,10 +20,10 @@ import {
20
20
21
21
import { resetDateTime } from '@/utils/date-utils' ;
22
22
23
- import { clickCalendarDate , clickSelectBtn , getMonthName , openMenu , reOpenMenu } from '../utils' ;
23
+ import { clickCalendarDate , clickSelectBtn , getMonthName , hoverCalendarDate , openMenu , reOpenMenu } from '../utils' ;
24
24
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' ;
27
27
import { localToTz } from '@/utils/timezone' ;
28
28
29
29
describe ( 'It should validate various picker scenarios' , ( ) => {
@@ -78,6 +78,7 @@ describe('It should validate various picker scenarios', () => {
78
78
await clickCalendarDate ( dp , date ) ;
79
79
const emitted = dp . emitted ( ) ;
80
80
expect ( emitted ) . toHaveProperty ( 'update:model-value' , [ [ set ( date , { seconds : 0 , milliseconds : 0 } ) ] ] ) ;
81
+ dp . unmount ( ) ;
81
82
} ) ;
82
83
83
84
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', () => {
98
99
99
100
expect ( innerStartCell . classes ( ) ) . toContain ( 'dp__range_start' ) ;
100
101
expect ( innerEndCell . classes ( ) ) . toContain ( 'dp__range_end' ) ;
102
+ dp . unmount ( ) ;
101
103
} ) ;
102
104
103
105
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', () => {
106
108
const hours = getHours ( today ) ;
107
109
const minutes = getMinutes ( today ) ;
108
110
109
- const singleTime = `${ hours } : ${ minutes } ` ;
111
+ const singleTime = `${ hours < 10 ? `0 ${ hours } ` : hours } : ${ minutes < 10 ? `0 ${ minutes } ` : minutes } ` ;
110
112
111
113
const input = dp . find ( 'input' ) ;
112
114
await input . setValue ( singleTime ) ;
@@ -118,6 +120,7 @@ describe('It should validate various picker scenarios', () => {
118
120
expect ( dp . emitted ( ) ) . toHaveProperty ( 'invalid-select' , [
119
121
[ [ set ( new Date ( ) , { hours, minutes, seconds : 0 , milliseconds : 0 } ) ] ] ,
120
122
] ) ;
123
+ dp . unmount ( ) ;
121
124
} ) ;
122
125
123
126
it ( 'Should emit regular and zoned date value' , async ( ) => {
@@ -133,6 +136,7 @@ describe('It should validate various picker scenarios', () => {
133
136
134
137
expect ( emitted ) . toHaveProperty ( 'update:model-value' , [ [ value ] ] ) ;
135
138
expect ( emitted ) . toHaveProperty ( 'update:model-timezone-value' , [ [ localToTz ( value , timezone ) ] ] ) ;
139
+ dp . unmount ( ) ;
136
140
} ) ;
137
141
138
142
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', () => {
466
470
await dp . find ( `[data-test="select-button"]` ) . trigger ( 'click' ) ;
467
471
468
472
expect ( dp . emitted ( ) [ 'update:model-value' ] ) . toBeTruthy ( ) ;
473
+ dp . unmount ( ) ;
469
474
} ) ;
470
475
471
476
it ( 'Should select preset date on month picker' , async ( ) => {
@@ -479,5 +484,72 @@ describe('It should validate various picker scenarios', () => {
479
484
expect ( dp . emitted ( ) [ 'update:model-value' ] ) . toEqual ( [
480
485
[ { month : getMonth ( yearStart ) , year : getYear ( yearStart ) } ] ,
481
486
] ) ;
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 ) ;
482
554
} ) ;
483
555
} ) ;
0 commit comments