forked from Meituan-Dianping/beeshell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.test.ts
More file actions
131 lines (106 loc) · 3.09 KB
/
Copy pathutils.test.ts
File metadata and controls
131 lines (106 loc) · 3.09 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { isLeapYear, range, hexToRgb, convert2Digit } from '../../src/common/utils'
import validator from '../../src/common/utils/validator'
import renderSafeArea from '../../src/common/utils/renderSafeArea'
import calendarUtils from '../../src/components/Calendar/utils'
import moment from 'moment'
describe('JS Utils', () => {
test('use correctly', () => {
/**
* 正常输入
*/
expect(isLeapYear(2000)).toBe(true)
expect(isLeapYear('2000')).toBe(true)
expect(isLeapYear(2001)).toBe(false)
/**
* 边界输入
*/
expect(isLeapYear(0)).toBe(true)
expect(isLeapYear(Infinity)).toBe(false)
/**
* 非法输入
*/
expect(isLeapYear('xx')).toBe(false)
expect(isLeapYear(false)).toBe(false)
expect(range(3)).toEqual([0, 1, 2])
expect(hexToRgb('#111111')).toEqual({ r: 17, g: 17, b: 17 })
expect(convert2Digit(2)).toBe('02')
expect(convert2Digit(20)).toBe('20')
const localeData = moment().locale('zh-cn').localeData()
expect(localeData.months(moment([2012, 0]))).toBe('一月')
localeData.monthsShort()
localeData.weekdays()
localeData.weekdaysShort()
localeData.weekdaysMin()
localeData.meridiemHour(null, '上午')
localeData.meridiemHour(12, '下午')
localeData.meridiem(1, 0)
localeData.meridiem(6, 0)
localeData.meridiem(9, 0)
localeData.meridiem(11, 0)
localeData.meridiem(12, 0)
localeData.meridiem(17, 0)
localeData.meridiem(19, 0)
localeData.calendar()
localeData.ordinal()
localeData.ordinal(1, 'D')
localeData.ordinal(1, 'M')
localeData.ordinal(1, 'W')
calendarUtils.CalendarDecorator
.trigger([[{dateModel: moment()}], [{dateModel: moment().add(1, 'days')}]])(calendarUtils.CalendarDecorator.decorator.targetMonth.bind(null, moment()))
calendarUtils.CalendarDecorator
.trigger([[{dateModel: moment()}], [{dateModel: moment().add(1, 'days')}]])(calendarUtils.CalendarDecorator.decorator.disabled.bind(null, moment(), moment()))
calendarUtils.changeDate(moment(), 'days', 'subtract')
const validate = validator.dispatch(
validator.register('name', (key, value, callback) => {
callback(ruleName(value, 'lulu'))
}),
validator.register('phone', (key, value, callback) => {
callback(rulePhone(value))
})
)
validate('name', 111, (tmp) => {
console.log(tmp)
})
validate('phone', 111, (tmp) => {
console.log(tmp)
})
renderSafeArea()
})
})
function ruleName(value: any, targetValue: any) {
if (!value) {
return {
valid: false,
msg: '请输入姓名'
}
}
value = String(value).toLowerCase()
if (value === targetValue) {
return {
valid: true
}
} else {
return {
valid: false,
msg: '输入姓名无效'
}
}
}
function rulePhone(value: any) {
if (!value) {
return {
valid: false,
msg: '请输入手机号码'
}
}
if (/^\d{11}$/.test(value)) {
return {
valid: true,
}
} else {
return {
valid: false,
msg: '请输入手机号码无效'
}
}
}