-
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathutil.spec.tsx
More file actions
100 lines (91 loc) · 3.65 KB
/
util.spec.tsx
File metadata and controls
100 lines (91 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import momentGenerateConfig from '../src/generate/moment';
import { getLowerBoundTime, setTime, getLastDay } from '../src/utils/timeUtil';
import { toArray } from '../src/utils/miscUtil';
import { isSameTime, isSameDecade, isSameWeek } from '../src/utils/dateUtil';
import { getMoment } from './util/commonUtil';
describe('Picker.Util', () => {
it('toArray', () => {
expect(toArray(null)).toEqual([]);
expect(toArray(undefined)).toEqual([]);
expect(toArray([1])).toEqual([1]);
expect(toArray(1)).toEqual([1]);
});
// Time is only for time
it('isSameTime', () => {
expect(
isSameTime(momentGenerateConfig, getMoment('2000-01-01'), getMoment('1989-11-28')),
).toBeTruthy();
expect(isSameTime(momentGenerateConfig, null, getMoment('1989-11-28'))).toBeFalsy();
expect(isSameTime(momentGenerateConfig, null, null)).toBeTruthy();
});
it('isSameDecade', () => {
expect(isSameDecade(momentGenerateConfig, null, null)).toBeTruthy();
expect(isSameDecade(momentGenerateConfig, getMoment('2000-01-02'), null)).toBeFalsy();
expect(
isSameDecade(momentGenerateConfig, getMoment('1995-01-01'), getMoment('1999-01-01')),
).toBeTruthy();
});
describe('getLowerBoundTime', () => {
it('basic case', () => {
expect(getLowerBoundTime(23, 59, 59, 1, 1, 1)).toEqual([23, 59, 59]);
});
it('case to lower hour #1', () => {
expect(getLowerBoundTime(1, 4, 5, 4, 15, 15)).toEqual([0, 45, 45]);
});
it('case to lower hour #2', () => {
expect(getLowerBoundTime(3, 4, 5, 4, 15, 15)).toEqual([0, 45, 45]);
});
it('case to same hour, lower minute #1', () => {
expect(getLowerBoundTime(1, 31, 5, 1, 15, 15)).toEqual([1, 30, 45]);
});
it('case to same hour, lower minute #2', () => {
expect(getLowerBoundTime(1, 44, 5, 1, 15, 15)).toEqual([1, 30, 45]);
});
it('case to same hour, same minute, lower second #1', () => {
expect(getLowerBoundTime(1, 44, 5, 1, 1, 15)).toEqual([1, 44, 0]);
});
it('case to same hour, same minute, lower second #2', () => {
expect(getLowerBoundTime(1, 44, 14, 1, 1, 15)).toEqual([1, 44, 0]);
});
});
describe('setTime', () => {
expect(
isSameTime(
momentGenerateConfig,
setTime(momentGenerateConfig, getMoment('1995-01-01 00:00:00'), 8, 7, 6),
getMoment('1995-01-01 08:07:06'),
),
).toBeTruthy();
});
describe('getLastDay', () => {
expect(getLastDay(momentGenerateConfig, getMoment('2020-10-01'))).toEqual('2020-10-31');
});
it('isSameWeek', () => {
// 2024 CN first date === 2024-01-01 monday
expect(
isSameWeek(momentGenerateConfig, 'zh_CN', getMoment('2023-12-31'), getMoment('2024-01-01')),
).toBeFalsy();
expect(
isSameWeek(momentGenerateConfig, 'zh_CN', getMoment('2023-12-31'), getMoment('2024-12-31')),
).toBeFalsy();
expect(
isSameWeek(momentGenerateConfig, 'zh_CN', getMoment('2024-01-02'), getMoment('2024-01-01')),
).toBeTruthy();
expect(
isSameWeek(momentGenerateConfig, 'zh_CN', getMoment('2024-01-02'), getMoment('2024-03-01')),
).toBeFalsy();
// 2024 US first date === 2023-12-31 sunday
expect(
isSameWeek(momentGenerateConfig, 'en_US', getMoment('2023-12-31'), getMoment('2024-01-01')),
).toBeTruthy();
expect(
isSameWeek(momentGenerateConfig, 'en_US', getMoment('2023-12-31'), getMoment('2024-12-31')),
).toBeFalsy();
expect(
isSameWeek(momentGenerateConfig, 'en_US', getMoment('2024-01-02'), getMoment('2024-01-01')),
).toBeTruthy();
expect(
isSameWeek(momentGenerateConfig, 'en_US', getMoment('2024-01-02'), getMoment('2024-03-01')),
).toBeFalsy();
});
});