1
1
import { describe , expect , it } from 'vitest'
2
2
3
+ import { nextTick } from 'vue'
3
4
import { useCron , type CronFormat } from '../cron-core'
4
5
5
6
type UseCronReturn = ReturnType < typeof useCron >
@@ -19,10 +20,11 @@ function cronToString({ selected: { value: selected }, period }: UseCronReturn):
19
20
}
20
21
21
22
describe ( 'useCron' , ( ) => {
22
- it ( 'renders properly' , ( ) => {
23
+ it ( 'renders properly' , async ( ) => {
23
24
const tests : {
24
25
format : CronFormat
25
26
value : string
27
+ period ?: string
26
28
expected : string
27
29
} [ ] = [
28
30
{
@@ -34,11 +36,36 @@ describe('useCron', () => {
34
36
format : 'quartz' ,
35
37
value : '* * * * * *' ,
36
38
expected : `Every Year in every month on every day and every day of the week at every hour : every minute : every second`
39
+ } ,
40
+ {
41
+ format : 'crontab' ,
42
+ value : '* * * * *' ,
43
+ period : 'hour' ,
44
+ expected : `Every Hour at every minute(s)`
45
+ } ,
46
+ {
47
+ format : 'quartz' ,
48
+ value : '* * * * * *' ,
49
+ period : 'q-hour' ,
50
+ expected : `Every Hour at every minute : every second`
51
+ } ,
52
+ {
53
+ format : 'quartz' ,
54
+ value : '0 15 10 * * ?' ,
55
+ period : 'month' ,
56
+ expected : `Every Month on every day and no specific day of the week at 10 : 15 : 00`
57
+ } ,
58
+ {
59
+ format : 'quartz' ,
60
+ value : '0 15 10 ? * *' ,
61
+ period : 'month' ,
62
+ expected : `Every Month on no specific day and every day of the week at 10 : 15 : 00`
37
63
}
38
64
]
39
65
40
66
for ( const t of tests ) {
41
- const cron = useCron ( { format : t . format , initialValue : t . value } )
67
+ const cron = useCron ( { format : t . format , initialValue : t . value , initialPeriod : t . period } )
68
+ await nextTick ( )
42
69
expect ( cronToString ( cron ) ) . toEqual ( t . expected )
43
70
}
44
71
} )
0 commit comments