-
Notifications
You must be signed in to change notification settings - Fork 258
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
1 parent
0be39a8
commit 67c47fe
Showing
37 changed files
with
1,405 additions
and
192 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__tests__ | ||
**/__tests__/* |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Calin Tamas | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,11 @@ | ||
module.exports = { | ||
preset: 'react-native', | ||
testEnvironment: 'node', | ||
collectCoverage: true, | ||
collectCoverageFrom: ['src/**/*.{ts,tsx}'], | ||
setupFilesAfterEnv: [ | ||
'@testing-library/jest-native/extend-expect', | ||
'./jest.setup.js' | ||
], | ||
testPathIgnorePatterns: ['/__helpers__/'] | ||
}; |
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,3 @@ | ||
/* eslint-env jest */ | ||
|
||
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
GestureResponderHandlers, | ||
PanResponder, | ||
PanResponderCallbacks, | ||
PanResponderGestureState | ||
} from 'react-native'; | ||
|
||
export const mockGestureValues: PanResponderGestureState = { | ||
moveY: 0, | ||
moveX: 0, | ||
y0: 0, | ||
x0: 0, | ||
dx: 0, | ||
dy: 10, | ||
stateID: 123, | ||
vx: 0, | ||
vy: 0, | ||
numberActiveTouches: 1, | ||
_accountsForMovesUpTo: 1 | ||
}; | ||
|
||
export function mockPanResponder() { | ||
jest | ||
.spyOn(PanResponder, 'create') | ||
.mockImplementation( | ||
({ | ||
onMoveShouldSetPanResponder, | ||
onMoveShouldSetPanResponderCapture, | ||
onPanResponderMove, | ||
onPanResponderRelease | ||
}: PanResponderCallbacks) => ({ | ||
panHandlers: { | ||
onMoveShouldSetResponder: onMoveShouldSetPanResponder, | ||
onMoveShouldSetResponderCapture: onMoveShouldSetPanResponderCapture, | ||
onResponderMove: onPanResponderMove, | ||
onResponderRelease: onPanResponderRelease | ||
} as GestureResponderHandlers | ||
}) | ||
); | ||
} |
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,42 @@ | ||
/* eslint-env jest */ | ||
|
||
import { render } from '@testing-library/react-native'; | ||
import React from 'react'; | ||
import { act } from 'react-test-renderer'; | ||
|
||
import { Toast } from '../Toast'; | ||
import { ToastProps } from '../types'; | ||
|
||
const setup = (props?: Partial<ToastProps>) => { | ||
const utils = render(<Toast {...props} />); | ||
return { | ||
...utils | ||
}; | ||
}; | ||
|
||
describe('test Toast component', () => { | ||
it('creates imperative handle', () => { | ||
const onShow = jest.fn(); | ||
const onHide = jest.fn(); | ||
setup({ | ||
onShow, | ||
onHide | ||
}); | ||
expect(Toast.show).toBeDefined(); | ||
expect(Toast.hide).toBeDefined(); | ||
|
||
act(() => { | ||
Toast.show({ | ||
text1: 'test' | ||
}); | ||
}); | ||
|
||
expect(onShow).toHaveBeenCalled(); | ||
|
||
act(() => { | ||
Toast.hide(); | ||
}); | ||
|
||
expect(onHide).toHaveBeenCalled(); | ||
}); | ||
}); |
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,75 @@ | ||
/* eslint-env jest */ | ||
|
||
import { render } from '@testing-library/react-native'; | ||
import React from 'react'; | ||
|
||
import { ToastUI, ToastUIProps } from '../ToastUI'; | ||
import { DEFAULT_OPTIONS } from '../useToast'; | ||
|
||
const setup = (props?: Partial<ToastUIProps>) => { | ||
const show = jest.fn(); | ||
const hide = jest.fn(); | ||
|
||
const utils = render( | ||
<ToastUI | ||
isVisible | ||
options={DEFAULT_OPTIONS} | ||
data={{ | ||
text1: 'text1', | ||
text2: 'text2' | ||
}} | ||
show={show} | ||
hide={hide} | ||
{...props} | ||
/> | ||
); | ||
return { | ||
...utils | ||
}; | ||
}; | ||
|
||
describe('test ToastUI component', () => { | ||
it('renders defaults', () => { | ||
const { queryByText } = setup(); | ||
expect(queryByText('text1')).toBeDefined(); | ||
expect(queryByText('text2')).toBeDefined(); | ||
}); | ||
|
||
it('renders error type Toast', () => { | ||
const { queryByText } = setup({ | ||
options: { | ||
...DEFAULT_OPTIONS, | ||
type: 'error' | ||
} | ||
}); | ||
expect(queryByText('text1')).toBeDefined(); | ||
expect(queryByText('text2')).toBeDefined(); | ||
}); | ||
|
||
it('renders info type Toast', () => { | ||
const { queryByText } = setup({ | ||
options: { | ||
...DEFAULT_OPTIONS, | ||
type: 'info' | ||
} | ||
}); | ||
expect(queryByText('text1')).toBeDefined(); | ||
expect(queryByText('text2')).toBeDefined(); | ||
}); | ||
|
||
it('throws when trying to render an undefined Toast type', () => { | ||
const type = 'mock'; | ||
expect(() => | ||
setup({ | ||
options: { | ||
...DEFAULT_OPTIONS, | ||
type | ||
} | ||
}) | ||
).toThrow( | ||
new Error( | ||
`Toast type: '${type}' does not exist. You can add it via the 'config' prop on the Toast instance. Learn more: https://github.com/calintamas/react-native-toast-message/blob/master/README.md` | ||
) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.