@loadsmart/loadsmart-ui 6.1.1 → 6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import renderer, { screen, fire } from '../../tests/renderer'
|
|
|
12
12
|
|
|
13
13
|
import type { DatePickerProps } from './DatePicker.types'
|
|
14
14
|
import type { CalendarMonthAlias } from '../Calendar'
|
|
15
|
+
import { formatDate } from './useDatePicker'
|
|
15
16
|
|
|
16
17
|
const { Playground } = composeStories(stories)
|
|
17
18
|
|
|
@@ -159,5 +160,15 @@ describe('DatePicker', () => {
|
|
|
159
160
|
|
|
160
161
|
expect(selectedDays).toHaveLength(0)
|
|
161
162
|
})
|
|
163
|
+
|
|
164
|
+
it('try to pass an invalid date', () => {
|
|
165
|
+
const date = '2022-32-33'
|
|
166
|
+
const formattedDate = formatDate(date)
|
|
167
|
+
|
|
168
|
+
setup({ value: formattedDate })
|
|
169
|
+
|
|
170
|
+
const datePickerInput = screen.getByLabelText('Select the date')
|
|
171
|
+
expect(datePickerInput).toHaveDisplayValue('') // invalid date is not applied
|
|
172
|
+
})
|
|
162
173
|
})
|
|
163
174
|
})
|
|
@@ -11,7 +11,7 @@ import type { DatePickerProps } from './DatePicker.types'
|
|
|
11
11
|
export const formatter = DateFormatHelper('MM/DD/YYYY')
|
|
12
12
|
|
|
13
13
|
export function formatDate(date?: number | string | null): string {
|
|
14
|
-
if (!date) {
|
|
14
|
+
if (!date || Number.isNaN(new Date(date).getTime())) {
|
|
15
15
|
return ''
|
|
16
16
|
}
|
|
17
17
|
|