-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,104 @@ | ||
import React from 'react'; | ||
import {render, act} from '@testing-library/react-native'; | ||
import { | ||
render, | ||
act, | ||
fireEvent, | ||
waitFor, | ||
cleanup, | ||
} from '@testing-library/react-native'; | ||
import RBSheet from '../src'; | ||
|
||
describe('<RBSheet />', () => { | ||
describe('React Native Raw Bottom Sheet <RBSheet />', () => { | ||
let ref; | ||
let getByTestId; | ||
|
||
beforeEach(() => { | ||
ref = React.createRef(); | ||
getByTestId = render(<RBSheet ref={ref} />).getByTestId; | ||
}); | ||
|
||
it('should render correctly', () => { | ||
getByTestId = render(<RBSheet ref={ref} draggable />).getByTestId; | ||
|
||
act(() => { | ||
ref.current.open(); | ||
}); | ||
}); | ||
|
||
afterEach(cleanup); | ||
|
||
it('should render correctly', () => { | ||
expect(getByTestId('Modal')).toBeTruthy(); | ||
expect(getByTestId('KeyboardAvoidingView')).toBeTruthy(); | ||
expect(getByTestId('TouchableOpacity')).toBeTruthy(); | ||
expect(getByTestId('AnimatedView')).toBeTruthy(); | ||
}); | ||
|
||
it('should render draggable correctly', () => { | ||
getByTestId = render(<RBSheet ref={ref} draggable />).getByTestId; | ||
act(() => { | ||
ref.current.open(); | ||
}); | ||
expect(getByTestId('DraggableView')).toBeTruthy(); | ||
expect(getByTestId('DraggableIcon')).toBeTruthy(); | ||
}); | ||
|
||
it('should handle open and close method', async () => { | ||
expect(getByTestId('Modal')).toBeTruthy(); | ||
act(() => { | ||
ref.current.close(); | ||
}); | ||
await waitFor(() => | ||
expect(() => getByTestId('Modal')).toThrow( | ||
'Unable to find an element with testID: Modal', | ||
), | ||
); | ||
}); | ||
|
||
it('should handle open and close callbacks', async () => { | ||
const onOpen = jest.fn(); | ||
const onClose = jest.fn(); | ||
getByTestId = render( | ||
<RBSheet ref={ref} onOpen={onOpen} onClose={onClose} />, | ||
).getByTestId; | ||
act(() => { | ||
ref.current.open(); | ||
}); | ||
await waitFor(() => expect(onOpen).toHaveBeenCalled()); | ||
act(() => { | ||
ref.current.close(); | ||
}); | ||
await waitFor(() => expect(onClose).toHaveBeenCalled()); | ||
}); | ||
|
||
it('should not close on press mask', () => { | ||
fireEvent.press(getByTestId('TouchableOpacity')); | ||
expect(getByTestId('Modal')).toBeTruthy(); | ||
}); | ||
|
||
it('should close on press mask', async () => { | ||
getByTestId = render(<RBSheet ref={ref} closeOnPressMask />).getByTestId; | ||
act(() => { | ||
ref.current.open(); | ||
}); | ||
fireEvent.press(getByTestId('TouchableOpacity')); | ||
await waitFor(() => | ||
expect(() => getByTestId('Modal')).toThrow( | ||
'Unable to find an element with testID: Modal', | ||
), | ||
); | ||
}); | ||
|
||
it('should not close on press back', () => { | ||
fireEvent(getByTestId('Modal'), 'requestClose'); | ||
expect(getByTestId('Modal')).toBeTruthy(); | ||
}); | ||
|
||
it('should close on press back', async () => { | ||
getByTestId = render(<RBSheet ref={ref} closeOnPressBack />).getByTestId; | ||
act(() => { | ||
ref.current.open(); | ||
}); | ||
fireEvent(getByTestId('Modal'), 'requestClose'); | ||
await waitFor(() => | ||
expect(() => getByTestId('Modal')).toThrow( | ||
'Unable to find an element with testID: Modal', | ||
), | ||
); | ||
}); | ||
}); |