-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(blade): Trigger native select events in dropdown/ file upload / D…
…ate picker [FC-3151] (#2408) * chore: trigger native events * chore: trigger native events * fix: fireNativeEvents in case of dropdown * chore: remove extra code * chore: change value of fireNative events to unknown * chore: remove fireNativeEvent from autocompelte * chore: remove add fireNative event on remove , dissmiss * chore: remove logs * chore: code clean up * chore: minor change * chore: minor changes * chore: fix type * chore: fire native event is not supported on react-native * chore: change fire native event * chore: review change useFireNativeEvent * feat: added fireNativeEvent test * chore: test for fireNativeEvent react native * chore: update fireNativeEvent error * chore: add tests in AutoComplete * feat: add test for fire naitve event in DatePicker * feat: added test case for FileUpload * fix: failing build * chore: update snap * chore: add fixes to fireNativeEvent * chore: change throwBladeError to logger * chore: fix errors * chore: increase timeout
- Loading branch information
Showing
18 changed files
with
380 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/blade/src/components/DatePicker/__tests__/DatePicker.web.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import dayjs from 'dayjs'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { waitFor } from '@testing-library/react'; | ||
import { DatePicker as DatePickerComponent } from '..'; | ||
import { Box } from '~components/Box'; | ||
import renderWithTheme from '~utils/testing/renderWithTheme.web'; | ||
|
||
describe('<DatePicker/> ', () => { | ||
jest.setTimeout(10000); | ||
it('should fire native events like input and change', async () => { | ||
const handleInput = jest.fn(); | ||
const handleChange = jest.fn(); | ||
|
||
const DatePicker = (): React.ReactElement => { | ||
const ref = useRef<HTMLElement>(null); | ||
|
||
const addEventListeners = (): void => { | ||
if (ref.current) { | ||
ref.current.addEventListener('input', handleInput); | ||
ref.current.addEventListener('change', handleChange); | ||
} | ||
}; | ||
|
||
const removeEventListeners = (): void => { | ||
if (ref.current) { | ||
ref.current.removeEventListener('input', handleInput); | ||
ref.current.removeEventListener('change', handleChange); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
addEventListeners(); | ||
return removeEventListeners; | ||
}, []); | ||
|
||
return ( | ||
<Box ref={ref}> | ||
<DatePickerComponent accessibilityLabel="Select Date" /> | ||
</Box> | ||
); | ||
}; | ||
|
||
const user = userEvent.setup(); | ||
const { getByRole, queryByText } = renderWithTheme(<DatePicker />); | ||
|
||
const input = getByRole('combobox', { name: /Select Date/i }); | ||
await user.click(input); | ||
|
||
await waitFor(() => expect(queryByText('Sun')).toBeVisible()); | ||
|
||
const dateToSelect = dayjs().add(1, 'day'); | ||
const date = getByRole('button', { name: dateToSelect.format('DD MMMM YYYY') }); | ||
await user.click(date); | ||
|
||
const applyButton = getByRole('button', { name: /Apply/i }); | ||
await user.click(applyButton); | ||
expect(handleChange).toBeCalled(); | ||
expect(handleInput).toBeCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.