Skip to content

Commit bf7aa53

Browse files
test(date-time-picker): boost coverage (#806)
* test(date-time-picker): cover Picker props (209–214) and boost coverage 95%+ Add MockPicker spec to hit header/footer/onConfirm/onCancel props wiring Add rerender path to cover “no header/footer and no handlers” falsy branches Add className/style specs to hit template literal trim branches Improve filter/renderLabel/array time-mode branch coverage Fix test stability by using rerender from render result Affected src/date-time-picker/tests/date-time-picker.test.tsx src/date-time-picker/DateTimePicker.tsx * fix: fix lint * fix: fix type error * test: update snapshots --------- Co-authored-by: anlyyao <[email protected]>
1 parent 22848d5 commit bf7aa53

File tree

7 files changed

+733
-36
lines changed

7 files changed

+733
-36
lines changed

site/test-coverage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
common: { statements: '82.75%', branches: '66.66%', functions: '83.33%', lines: '92%' },
1414
configProvider: { statements: '54.54%', branches: '0%', functions: '0%', lines: '54.54%' },
1515
countDown: { statements: '100%', branches: '90%', functions: '100%', lines: '100%' },
16-
dateTimePicker: { statements: '5.67%', branches: '0%', functions: '0%', lines: '6.06%' },
16+
dateTimePicker: { statements: '95.74%', branches: '90.75%', functions: '94.44%', lines: '95.45%' },
1717
dialog: { statements: '4.3%', branches: '0%', functions: '0%', lines: '4.49%' },
1818
divider: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
1919
drawer: { statements: '98.63%', branches: '100%', functions: '96.42%', lines: '100%' },
@@ -24,7 +24,7 @@ module.exports = {
2424
form: { statements: '2.8%', branches: '0%', functions: '0%', lines: '2.96%' },
2525
grid: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
2626
guide: { statements: '3.46%', branches: '0%', functions: '0%', lines: '3.77%' },
27-
hooks: { statements: '70.7%', branches: '44.7%', functions: '73.68%', lines: '70.66%' },
27+
hooks: { statements: '70.7%', branches: '45.88%', functions: '73.68%', lines: '70.66%' },
2828
image: { statements: '97.72%', branches: '100%', functions: '92.3%', lines: '97.61%' },
2929
imageViewer: { statements: '8.33%', branches: '2.83%', functions: '0%', lines: '8.69%' },
3030
indexes: { statements: '95.65%', branches: '69.81%', functions: '100%', lines: '96.94%' },
@@ -38,7 +38,7 @@ module.exports = {
3838
navbar: { statements: '12.9%', branches: '0%', functions: '0%', lines: '13.79%' },
3939
noticeBar: { statements: '6.38%', branches: '0%', functions: '0%', lines: '6.52%' },
4040
overlay: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
41-
picker: { statements: '5.71%', branches: '0%', functions: '0%', lines: '6.28%' },
41+
picker: { statements: '51.71%', branches: '29.69%', functions: '57.31%', lines: '52.51%' },
4242
popover: { statements: '100%', branches: '96.55%', functions: '100%', lines: '100%' },
4343
popup: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
4444
progress: { statements: '100%', branches: '97.36%', functions: '100%', lines: '100%' },

src/date-time-picker/DateTimePicker.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const DateTimePicker: FC<DateTimePickerProps> = (props) => {
2929

3030
const [innerValue, setDateTimePickerValue] = useDefault(props.value, props.defaultValue, props.onChange);
3131

32-
const confirmButtonText = props.confirmBtn || t(locale.confirm);
33-
const cancelButtonText = props.cancelBtn || t(locale.cancel);
32+
const confirmButtonText = props.confirmBtn || (t(locale.confirm) as string);
33+
const cancelButtonText = props.cancelBtn || (t(locale.cancel) as string);
3434

3535
const start = normalize(props.start, dayjs().subtract(10, 'year'));
3636
const end = normalize(props.end, dayjs().add(10, 'year'));
@@ -205,22 +205,22 @@ const DateTimePicker: FC<DateTimePickerProps> = (props) => {
205205
props.onCancel?.({ e: context.e });
206206
};
207207

208-
const onPick = (value: Array<PickerValue>, context: PickerContext) => {
209-
const { column, index } = context;
208+
const onPick = (value: Array<PickerValue>, { column, index }: PickerContext) => {
210209
const type = meaningColumn[column];
211210
const val = curDate.set(type as UnitType, parseInt(columns[column][index]?.value, 10));
212-
213-
setCurDate(rationalize(val));
214-
props.onPick?.(rationalize(val).format(props.format));
211+
const next = rationalize(val);
212+
setCurDate(next);
213+
props.onPick?.(next.format(props.format));
215214
};
216215

217216
return (
218217
<Picker
219-
className={dateTimePickerClass}
218+
className={`${dateTimePickerClass} ${props.className || ''}`.trim()}
219+
style={props.style}
220220
value={valueOfPicker}
221221
title={props.title}
222-
confirm-btn={confirmButtonText}
223-
cancel-btn={cancelButtonText}
222+
confirmBtn={confirmButtonText}
223+
cancelBtn={cancelButtonText}
224224
columns={columns}
225225
onConfirm={onConfirm}
226226
onCancel={onCancel}

0 commit comments

Comments
 (0)