react-native-toast-message 2.2.0-beta.1 → 2.2.0

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.
Files changed (61) hide show
  1. package/README.md +3 -3
  2. package/lib/src/Toast.d.ts +1 -1
  3. package/lib/src/Toast.js +3 -5
  4. package/lib/src/ToastUI.js +6 -4
  5. package/lib/src/components/AnimatedContainer.d.ts +2 -1
  6. package/lib/src/components/AnimatedContainer.js +6 -5
  7. package/lib/src/contexts/index.d.ts +1 -4
  8. package/lib/src/contexts/index.js +1 -2
  9. package/lib/src/hooks/usePanResponder.d.ts +2 -1
  10. package/lib/src/hooks/usePanResponder.js +9 -3
  11. package/lib/src/hooks/useSlideAnimation.d.ts +2 -6
  12. package/lib/src/hooks/useSlideAnimation.js +10 -35
  13. package/lib/src/types/index.d.ts +18 -12
  14. package/lib/src/useToast.js +7 -1
  15. package/lib/src/utils/array.d.ts +2 -0
  16. package/lib/src/utils/array.js +4 -0
  17. package/package.json +9 -19
  18. package/lib/src/__helpers__/PanResponder.d.ts +0 -3
  19. package/lib/src/__helpers__/PanResponder.js +0 -26
  20. package/lib/src/__helpers__/testing-library/react-hooks.d.ts +0 -9
  21. package/lib/src/__helpers__/testing-library/react-hooks.js +0 -13
  22. package/lib/src/__helpers__/testing-library/react-native.d.ts +0 -9
  23. package/lib/src/__helpers__/testing-library/react-native.js +0 -13
  24. package/lib/src/__mocks__/EnvironmentProviderMock.d.ts +0 -7
  25. package/lib/src/__mocks__/EnvironmentProviderMock.js +0 -9
  26. package/lib/src/__tests__/Toast.test.d.ts +0 -1
  27. package/lib/src/__tests__/Toast.test.js +0 -190
  28. package/lib/src/__tests__/ToastUI.test.d.ts +0 -1
  29. package/lib/src/__tests__/ToastUI.test.js +0 -52
  30. package/lib/src/__tests__/useToast.test.d.ts +0 -1
  31. package/lib/src/__tests__/useToast.test.js +0 -142
  32. package/lib/src/components/__tests__/AnimatedContainer.test.d.ts +0 -1
  33. package/lib/src/components/__tests__/AnimatedContainer.test.js +0 -147
  34. package/lib/src/components/__tests__/BaseToast.test.d.ts +0 -1
  35. package/lib/src/components/__tests__/BaseToast.test.js +0 -81
  36. package/lib/src/components/__tests__/ErrorToast.test.d.ts +0 -1
  37. package/lib/src/components/__tests__/ErrorToast.test.js +0 -20
  38. package/lib/src/components/__tests__/InfoToast.test.d.ts +0 -1
  39. package/lib/src/components/__tests__/InfoToast.test.js +0 -20
  40. package/lib/src/components/__tests__/SuccessToast.test.d.ts +0 -1
  41. package/lib/src/components/__tests__/SuccessToast.test.js +0 -20
  42. package/lib/src/contexts/EnvironmentContext.d.ts +0 -8
  43. package/lib/src/contexts/EnvironmentContext.js +0 -22
  44. package/lib/src/contexts/__tests__/EnvironmentContext.test.d.ts +0 -1
  45. package/lib/src/contexts/__tests__/EnvironmentContext.test.js +0 -29
  46. package/lib/src/contexts/__tests__/LoggerContext.test.d.ts +0 -1
  47. package/lib/src/contexts/__tests__/LoggerContext.test.js +0 -35
  48. package/lib/src/hooks/__tests__/useKeyboard.test.d.ts +0 -1
  49. package/lib/src/hooks/__tests__/useKeyboard.test.js +0 -60
  50. package/lib/src/hooks/__tests__/usePanResponder.test.d.ts +0 -1
  51. package/lib/src/hooks/__tests__/usePanResponder.test.js +0 -112
  52. package/lib/src/hooks/__tests__/useSlideAnimation.test.d.ts +0 -1
  53. package/lib/src/hooks/__tests__/useSlideAnimation.test.js +0 -88
  54. package/lib/src/hooks/__tests__/useTimeout.test.d.ts +0 -1
  55. package/lib/src/hooks/__tests__/useTimeout.test.js +0 -54
  56. package/lib/src/hooks/__tests__/useViewDimensions.test.d.ts +0 -1
  57. package/lib/src/hooks/__tests__/useViewDimensions.test.js +0 -51
  58. package/lib/src/utils/__tests__/number.test.d.ts +0 -1
  59. package/lib/src/utils/__tests__/number.test.js +0 -15
  60. package/lib/src/utils/__tests__/obj.test.d.ts +0 -1
  61. package/lib/src/utils/__tests__/obj.test.js +0 -21
@@ -1,190 +0,0 @@
1
- /* eslint-env jest */
2
- import React from 'react';
3
- import { Button, Modal, Text } from 'react-native';
4
- import { act, fireEvent, render, waitFor } from '~/__helpers__/testing-library/react-native';
5
- import { Toast } from '../Toast';
6
- /*
7
- The Modal component is automatically mocked by RN and apparently contains a bug which makes the Modal
8
- (and its children) to always be visible in the test tree.
9
-
10
- This fixes the issue:
11
- */
12
- jest.mock('react-native/Libraries/Modal/Modal', () => {
13
- const ActualModal = jest.requireActual('react-native/Libraries/Modal/Modal');
14
- return (props) => <ActualModal {...props}/>;
15
- });
16
- jest.mock('react-native/Libraries/LogBox/LogBox');
17
- describe('test Toast component', () => {
18
- it('creates imperative handle', () => {
19
- const onShow = jest.fn();
20
- const onHide = jest.fn();
21
- render(<Toast onShow={onShow} onHide={onHide}/>);
22
- expect(Toast.show).toBeDefined();
23
- expect(Toast.hide).toBeDefined();
24
- act(() => {
25
- Toast.show({
26
- text1: 'test'
27
- });
28
- });
29
- expect(onShow).toHaveBeenCalled();
30
- act(() => {
31
- Toast.hide();
32
- });
33
- expect(onHide).toHaveBeenCalled();
34
- });
35
- it('shows Toast inside a Modal', async () => {
36
- const onShow = jest.fn();
37
- const onHide = jest.fn();
38
- const onShowInsideModal = jest.fn();
39
- const onHideInsideModal = jest.fn();
40
- const ModalWrapper = () => {
41
- const [isVisible, setIsVisible] = React.useState(false);
42
- return (<>
43
- <Toast onShow={onShow} onHide={onHide}/>
44
- <Text>Outside modal</Text>
45
- <Button title='Show modal' onPress={() => setIsVisible(true)}/>
46
- <Modal visible={isVisible}>
47
- <Text>Inside modal</Text>
48
- <Button title='Hide modal' onPress={() => setIsVisible(false)}/>
49
- <Toast onShow={onShowInsideModal} onHide={onHideInsideModal}/>
50
- </Modal>
51
- </>);
52
- };
53
- const utils = render(<ModalWrapper />);
54
- expect(utils.queryByText('Outside modal')).toBeTruthy();
55
- expect(Toast.show).toBeDefined();
56
- expect(Toast.hide).toBeDefined();
57
- // Test the Toast instance that's outside the Modal
58
- act(() => {
59
- Toast.show({
60
- text1: 'test'
61
- });
62
- });
63
- expect(onShow).toHaveBeenCalled();
64
- act(() => {
65
- Toast.hide();
66
- });
67
- expect(onHide).toHaveBeenCalled();
68
- // Show the Modal
69
- const showModalButton = utils.getByText('Show modal');
70
- expect(showModalButton).toBeTruthy();
71
- fireEvent.press(showModalButton);
72
- await waitFor(() => {
73
- expect(utils.queryByText('Inside modal')).toBeTruthy();
74
- });
75
- // Test the Toast instance that's inside the Modal
76
- act(() => {
77
- Toast.show({
78
- text1: 'test'
79
- });
80
- });
81
- expect(onShowInsideModal).toHaveBeenCalled();
82
- act(() => {
83
- Toast.hide();
84
- });
85
- expect(onHideInsideModal).toHaveBeenCalled();
86
- // Hide modal
87
- const hideModalButton = utils.getByText('Hide modal');
88
- expect(hideModalButton).toBeTruthy();
89
- fireEvent.press(hideModalButton);
90
- await waitFor(() => {
91
- expect(utils.queryByText('Inside modal')).toBeFalsy();
92
- });
93
- // Now that the Modal is hidden, the the outside Toast instance again
94
- act(() => {
95
- Toast.show({
96
- text1: 'test'
97
- });
98
- });
99
- expect(onShow).toHaveBeenCalledTimes(2);
100
- expect(onShowInsideModal).toHaveBeenCalledTimes(1);
101
- act(() => {
102
- Toast.hide();
103
- });
104
- expect(onHide).toHaveBeenCalledTimes(2);
105
- expect(onHideInsideModal).toHaveBeenCalledTimes(1);
106
- });
107
- it(`doesn't show a Toast if there is no active ref`, () => {
108
- const onShow = jest.fn();
109
- const onHide = jest.fn();
110
- const ModalWrapper = () => (<>
111
- <Modal visible={false}>
112
- <Text>Inside modal</Text>
113
- <Toast onShow={onShow} onHide={onHide}/>
114
- </Modal>
115
- </>);
116
- render(<ModalWrapper />);
117
- act(() => {
118
- Toast.show({
119
- text1: 'test'
120
- });
121
- });
122
- expect(onShow).not.toHaveBeenCalled();
123
- });
124
- it('when autoHide: true, the Toast only hides when timer reaches visibilityTime', () => {
125
- jest.useFakeTimers();
126
- const onShow = jest.fn();
127
- const onHide = jest.fn();
128
- const visibilityTime = 1500;
129
- render(<Toast onShow={onShow} onHide={onHide} autoHide={true} visibilityTime={visibilityTime}/>);
130
- act(() => {
131
- Toast.show({
132
- text1: 'I am auto hiding, by default'
133
- });
134
- });
135
- expect(onShow).toHaveBeenCalled();
136
- // Advance time by 1/4 visibilityTime
137
- // Toast should not hide yet
138
- jest.advanceTimersByTime(visibilityTime / 4);
139
- expect(onHide).not.toHaveBeenCalled();
140
- // Do it again 1/4 visibilityTime
141
- // Toast should still be visible
142
- jest.advanceTimersByTime(visibilityTime / 4);
143
- expect(onHide).not.toHaveBeenCalled();
144
- // Advance time by the remaining 1/2 visibilityTime
145
- act(() => {
146
- jest.advanceTimersByTime(visibilityTime / 2);
147
- });
148
- // Now the Toast should hide
149
- expect(onHide).toHaveBeenCalled();
150
- jest.useRealTimers();
151
- });
152
- it('clears previous autoHide: true timer when a new Toast is presented with autoHide: false', () => {
153
- jest.useFakeTimers();
154
- const onShow = jest.fn();
155
- const onHide = jest.fn();
156
- const visibilityTime = 1500;
157
- render(<Toast onShow={onShow} onHide={onHide} autoHide={true} visibilityTime={visibilityTime}/>);
158
- act(() => {
159
- Toast.show({
160
- text1: 'I am auto hiding, by default'
161
- });
162
- });
163
- expect(onShow).toHaveBeenCalled();
164
- // Advance by 1/2 visibilityTime
165
- // Toast should not hide
166
- jest.advanceTimersByTime(visibilityTime / 2);
167
- expect(onHide).not.toHaveBeenCalled();
168
- // Now, show another Toast, before the previous one has the chance to hide
169
- act(() => {
170
- Toast.show({
171
- text1: 'I am NOT auto hiding',
172
- autoHide: false
173
- });
174
- });
175
- // Advance time to the end of visibilityTime
176
- act(() => {
177
- jest.advanceTimersByTime(visibilityTime / 2);
178
- });
179
- // The new Toast should NOT hide
180
- // (the previous timer should have been cleared before reaching the end)
181
- expect(onHide).not.toHaveBeenCalled();
182
- // And even go beyond visibilityTime
183
- act(() => {
184
- jest.advanceTimersByTime(1000);
185
- });
186
- // The new Toast should still not hide
187
- expect(onHide).not.toHaveBeenCalled();
188
- jest.useRealTimers();
189
- });
190
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,52 +0,0 @@
1
- /* eslint-env jest */
2
- import React from 'react';
3
- import { render } from '~/__helpers__/testing-library/react-native';
4
- import { ToastUI } from '../ToastUI';
5
- import { DEFAULT_OPTIONS } from '../useToast';
6
- const setup = (props) => {
7
- const show = jest.fn();
8
- const hide = jest.fn();
9
- const utils = render(<ToastUI isVisible options={DEFAULT_OPTIONS} data={{
10
- text1: 'text1',
11
- text2: 'text2'
12
- }} show={show} hide={hide} {...props}/>);
13
- return {
14
- ...utils
15
- };
16
- };
17
- describe('test ToastUI component', () => {
18
- it('renders defaults', () => {
19
- const { queryByText } = setup();
20
- expect(queryByText('text1')).toBeDefined();
21
- expect(queryByText('text2')).toBeDefined();
22
- });
23
- it('renders error type Toast', () => {
24
- const { queryByText } = setup({
25
- options: {
26
- ...DEFAULT_OPTIONS,
27
- type: 'error'
28
- }
29
- });
30
- expect(queryByText('text1')).toBeDefined();
31
- expect(queryByText('text2')).toBeDefined();
32
- });
33
- it('renders info type Toast', () => {
34
- const { queryByText } = setup({
35
- options: {
36
- ...DEFAULT_OPTIONS,
37
- type: 'info'
38
- }
39
- });
40
- expect(queryByText('text1')).toBeDefined();
41
- expect(queryByText('text2')).toBeDefined();
42
- });
43
- it('throws when trying to render an undefined Toast type', () => {
44
- const type = 'mock';
45
- expect(() => setup({
46
- options: {
47
- ...DEFAULT_OPTIONS,
48
- type
49
- }
50
- })).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/HEAD/docs/custom-layouts.md`));
51
- });
52
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,142 +0,0 @@
1
- /* eslint-env jest */
2
- import { act, renderHook } from '~/__helpers__/testing-library/react-hooks';
3
- import { DEFAULT_DATA, DEFAULT_OPTIONS, useToast } from '../useToast';
4
- const setup = () => {
5
- const utils = renderHook(() => useToast({
6
- defaultOptions: DEFAULT_OPTIONS
7
- }));
8
- return {
9
- ...utils
10
- };
11
- };
12
- describe('test useToast hook', () => {
13
- it('returns defaults', () => {
14
- const { result } = setup();
15
- const { isVisible, data, options, show, hide } = result.current;
16
- expect(isVisible).toBe(false);
17
- expect(data).toEqual(DEFAULT_DATA);
18
- expect(options).toEqual(DEFAULT_OPTIONS);
19
- expect(show).toBeDefined();
20
- expect(hide).toBeDefined();
21
- });
22
- it('set isVisible: true when show is called', () => {
23
- const { result } = setup();
24
- act(() => {
25
- result.current.show({
26
- text1: 'test'
27
- });
28
- });
29
- expect(result.current.isVisible).toBe(true);
30
- expect(result.current.data.text1).toBe('test');
31
- });
32
- it('calls onShow when Toast is shown', () => {
33
- const { result } = setup();
34
- const onShow = jest.fn();
35
- act(() => {
36
- result.current.show({
37
- text1: 'test',
38
- onShow
39
- });
40
- });
41
- expect(result.current.isVisible).toBe(true);
42
- expect(result.current.data.text1).toBe('test');
43
- expect(onShow).toHaveBeenCalled();
44
- });
45
- it('set isVisible: false when hide is called', () => {
46
- const { result } = setup();
47
- act(() => {
48
- result.current.show({
49
- text1: 'test'
50
- });
51
- });
52
- expect(result.current.isVisible).toBe(true);
53
- expect(result.current.data.text1).toBe('test');
54
- act(() => {
55
- result.current.hide();
56
- });
57
- expect(result.current.isVisible).toBe(false);
58
- });
59
- it('calls onHide when Toast is shown', () => {
60
- const { result } = setup();
61
- const onHide = jest.fn();
62
- act(() => {
63
- result.current.show({
64
- text1: 'test',
65
- onHide
66
- });
67
- });
68
- expect(result.current.isVisible).toBe(true);
69
- expect(result.current.data.text1).toBe('test');
70
- act(() => {
71
- result.current.hide();
72
- });
73
- expect(result.current.isVisible).toBe(false);
74
- expect(onHide).toHaveBeenCalled();
75
- });
76
- it('sets data values on show', () => {
77
- const { result } = setup();
78
- act(() => {
79
- result.current.show({
80
- text1: 'text1',
81
- text2: 'text2'
82
- });
83
- });
84
- expect(result.current.isVisible).toBe(true);
85
- expect(result.current.data.text1).toBe('text1');
86
- expect(result.current.data.text2).toBe('text2');
87
- });
88
- it('sets option values on show', () => {
89
- const { result } = setup();
90
- const options = {
91
- type: 'info',
92
- position: 'bottom',
93
- autoHide: false,
94
- visibilityTime: 20,
95
- topOffset: 120,
96
- bottomOffset: 130,
97
- keyboardOffset: 5,
98
- onShow: jest.fn(),
99
- onHide: jest.fn(),
100
- onPress: jest.fn(),
101
- props: {
102
- foo: 'bar'
103
- }
104
- };
105
- act(() => {
106
- result.current.show({
107
- text1: 'test',
108
- ...options
109
- });
110
- });
111
- expect(result.current.isVisible).toBe(true);
112
- expect(result.current.options).toEqual(options);
113
- });
114
- it('automatically hides when autoHide: true', () => {
115
- jest.useFakeTimers();
116
- const { result } = setup();
117
- const onHide = jest.fn();
118
- act(() => {
119
- result.current.show({
120
- text1: 'test',
121
- autoHide: true,
122
- onHide
123
- });
124
- });
125
- expect(result.current.isVisible).toBe(true);
126
- act(() => {
127
- jest.runAllTimers();
128
- });
129
- expect(result.current.isVisible).toBe(false);
130
- expect(onHide).toHaveBeenCalled();
131
- });
132
- it('shows using only text2', () => {
133
- const { result } = setup();
134
- act(() => {
135
- result.current.show({
136
- text2: 'text2'
137
- });
138
- });
139
- expect(result.current.isVisible).toBe(true);
140
- expect(result.current.data.text2).toBe('text2');
141
- });
142
- });
@@ -1,147 +0,0 @@
1
- /* eslint-env jest */
2
- import React from 'react';
3
- import { Dimensions, View } from 'react-native';
4
- import { render, waitFor } from '~/__helpers__/testing-library/react-native';
5
- import { mockGestureValues, mockPanResponder } from '../../__helpers__/PanResponder';
6
- import { AnimatedContainer, animatedValueFor, dampingFor } from '../AnimatedContainer';
7
- const setup = (props) => {
8
- const onHide = jest.fn();
9
- const defaultProps = {
10
- isVisible: false,
11
- position: 'top',
12
- topOffset: 40,
13
- bottomOffset: 40,
14
- keyboardOffset: 10,
15
- onHide
16
- };
17
- const utils = render(<AnimatedContainer {...defaultProps} {...props}>
18
- <View testID='childView'/>
19
- </AnimatedContainer>);
20
- return {
21
- ...utils
22
- };
23
- };
24
- const defaultStyles = {
25
- position: 'absolute',
26
- left: 0,
27
- right: 0,
28
- alignItems: 'center',
29
- justifyContent: 'center',
30
- top: 0
31
- };
32
- describe('test AnimatedContainer component', () => {
33
- it('is hidden by default', () => {
34
- const { queryByTestId } = setup();
35
- expect(queryByTestId('toastAnimatedContainer')).toHaveStyle({
36
- ...defaultStyles,
37
- opacity: 0
38
- });
39
- expect(queryByTestId('childView')).not.toBe(null);
40
- });
41
- it('shows when isVisible is true', async () => {
42
- const { queryByTestId } = setup({
43
- isVisible: true
44
- });
45
- await waitFor(() => expect(queryByTestId('toastAnimatedContainer')).toHaveStyle({
46
- ...defaultStyles,
47
- opacity: 1
48
- }));
49
- expect(queryByTestId('childView')).not.toBe(null);
50
- });
51
- it('restores toast position on pan (if gesture is higher than threshold)', async () => {
52
- mockPanResponder();
53
- const onRestorePosition = jest.fn();
54
- const { queryByTestId } = setup({
55
- isVisible: true,
56
- onRestorePosition
57
- });
58
- await waitFor(() => expect(queryByTestId('toastAnimatedContainer')).toHaveStyle({
59
- ...defaultStyles,
60
- opacity: 1
61
- }));
62
- const panHandler = queryByTestId('toastAnimatedContainer');
63
- const gesture = {
64
- ...mockGestureValues,
65
- moveY: 100,
66
- dy: 10
67
- };
68
- panHandler?.props.onResponderMove(undefined, gesture);
69
- panHandler?.props.onResponderRelease(undefined, gesture);
70
- expect(onRestorePosition).toHaveBeenCalled();
71
- });
72
- it('dismisses toast on pan (if gesture is lower than threshold)', async () => {
73
- mockPanResponder();
74
- const onHide = jest.fn();
75
- const { queryByTestId } = setup({
76
- isVisible: true,
77
- onHide
78
- });
79
- await waitFor(() => expect(queryByTestId('toastAnimatedContainer')).toHaveStyle({
80
- ...defaultStyles,
81
- opacity: 1
82
- }));
83
- const panHandler = queryByTestId('toastAnimatedContainer');
84
- const gesture = {
85
- ...mockGestureValues,
86
- moveY: 5,
87
- dy: -78
88
- };
89
- panHandler?.props.onResponderMove(undefined, gesture);
90
- panHandler?.props.onResponderRelease(undefined, gesture);
91
- expect(onHide).toHaveBeenCalled();
92
- });
93
- });
94
- jest.spyOn(Dimensions, 'get').mockImplementation(() => ({
95
- height: 600,
96
- width: 200,
97
- scale: 1,
98
- fontScale: 1
99
- }));
100
- describe('test dampingFor function', () => {
101
- const gesture = {
102
- ...mockGestureValues,
103
- moveY: 100
104
- };
105
- it('returns damping for position: bottom', () => {
106
- const position = 'bottom';
107
- expect(dampingFor(gesture, position)).toBe(500);
108
- });
109
- it('returns damping for position: top', () => {
110
- const position = 'top';
111
- expect(dampingFor(gesture, position)).toBe(100);
112
- });
113
- it('throws if position is not implemented', () => {
114
- try {
115
- dampingFor(gesture, 'foo');
116
- }
117
- catch (err) {
118
- expect(err).toBeDefined();
119
- }
120
- });
121
- });
122
- describe('test animatedValueFor function', () => {
123
- const gesture = {
124
- ...mockGestureValues,
125
- dy: 10
126
- };
127
- it('returns animated value for position: bottom', () => {
128
- const position = 'bottom';
129
- const damping = 100;
130
- expect(animatedValueFor(gesture, position, damping)).toBe(0.9);
131
- });
132
- it('returns animated value for position: top', () => {
133
- const position = 'top';
134
- const damping = 100;
135
- expect(animatedValueFor(gesture, position, damping)).toBe(1.1);
136
- });
137
- it('throws if position is not implemented', () => {
138
- try {
139
- const position = 'foo';
140
- const damping = 100;
141
- animatedValueFor(gesture, position, damping);
142
- }
143
- catch (err) {
144
- expect(err).toBeDefined();
145
- }
146
- });
147
- });
@@ -1 +0,0 @@
1
- import '@testing-library/jest-native';
@@ -1,81 +0,0 @@
1
- /* eslint-env jest */
2
- import '@testing-library/jest-native';
3
- import React from 'react';
4
- import { Image } from 'react-native';
5
- import { fireEvent, render } from '~/__helpers__/testing-library/react-native';
6
- import { BaseToast } from '../BaseToast';
7
- const setup = (props) => {
8
- const utils = render(<BaseToast {...props}/>);
9
- return {
10
- ...utils
11
- };
12
- };
13
- describe('test BaseToast component', () => {
14
- it('renders defaults', () => {
15
- const { queryByTestId } = setup();
16
- expect(queryByTestId('toastTouchableContainer')).not.toBe(null);
17
- expect(queryByTestId('toastContentContainer')).not.toBe(null);
18
- expect(queryByTestId('toastText1')).toBe(null);
19
- expect(queryByTestId('toastText2')).toBe(null);
20
- });
21
- it('renders text1 and text2', () => {
22
- const { queryByTestId, queryByText } = setup({
23
- text1: 'Hello',
24
- text2: 'World'
25
- });
26
- expect(queryByTestId('toastText1')).not.toBe(null);
27
- expect(queryByTestId('toastText2')).not.toBe(null);
28
- expect(queryByText('Hello')).not.toBe(null);
29
- expect(queryByText('World')).not.toBe(null);
30
- });
31
- it('renders only text1', () => {
32
- const { queryByTestId, queryByText } = setup({
33
- text1: 'Hello'
34
- });
35
- expect(queryByTestId('toastText1')).not.toBe(null);
36
- expect(queryByTestId('toastText2')).toBe(null);
37
- expect(queryByText('Hello')).not.toBe(null);
38
- });
39
- it('renders only text2', () => {
40
- const { queryByTestId, queryByText } = setup({
41
- text2: 'World'
42
- });
43
- expect(queryByTestId('toastText1')).toBe(null);
44
- expect(queryByTestId('toastText2')).not.toBe(null);
45
- expect(queryByText('World')).not.toBe(null);
46
- });
47
- it('fires onPress', () => {
48
- const onPress = jest.fn();
49
- const { queryByTestId } = setup({
50
- onPress
51
- });
52
- const touchableContainer = queryByTestId('toastTouchableContainer');
53
- expect(touchableContainer).not.toBe(null);
54
- fireEvent.press(touchableContainer);
55
- expect(onPress).toHaveBeenCalled();
56
- });
57
- it('adds custom style to toastTouchableContainer', () => {
58
- const { queryByTestId } = setup({
59
- style: {
60
- borderRadius: 20
61
- }
62
- });
63
- const touchableContainer = queryByTestId('toastTouchableContainer');
64
- expect(touchableContainer).not.toBe(null);
65
- expect(touchableContainer).toHaveStyle({
66
- borderRadius: 20
67
- });
68
- });
69
- it('renders leading icon', () => {
70
- const { queryByTestId } = setup({
71
- renderLeadingIcon: () => (<Image source={{ uri: 'testUri' }} testID='leadingIcon'/>)
72
- });
73
- expect(queryByTestId('leadingIcon')).not.toBe(null);
74
- });
75
- it('renders trailing icon', () => {
76
- const { queryByTestId } = setup({
77
- renderTrailingIcon: () => (<Image source={{ uri: 'testUri' }} testID='trailingIcon'/>)
78
- });
79
- expect(queryByTestId('trailingIcon')).not.toBe(null);
80
- });
81
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- /* eslint-env jest */
2
- import React from 'react';
3
- import { render } from '~/__helpers__/testing-library/react-native';
4
- import { ErrorToast } from '../ErrorToast';
5
- const setup = (props) => {
6
- const utils = render(<ErrorToast {...props}/>);
7
- return {
8
- ...utils
9
- };
10
- };
11
- describe('test ErrorToast component', () => {
12
- it('renders default style', () => {
13
- const { queryByTestId } = setup();
14
- const touchableContainer = queryByTestId('toastTouchableContainer');
15
- expect(touchableContainer).not.toBe(null);
16
- expect(touchableContainer).toHaveStyle({
17
- borderLeftColor: '#FE6301'
18
- });
19
- });
20
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- /* eslint-env jest */
2
- import React from 'react';
3
- import { render } from '~/__helpers__/testing-library/react-native';
4
- import { InfoToast } from '../InfoToast';
5
- const setup = (props) => {
6
- const utils = render(<InfoToast {...props}/>);
7
- return {
8
- ...utils
9
- };
10
- };
11
- describe('test ErrorToast component', () => {
12
- it('renders default style', () => {
13
- const { queryByTestId } = setup();
14
- const touchableContainer = queryByTestId('toastTouchableContainer');
15
- expect(touchableContainer).not.toBe(null);
16
- expect(touchableContainer).toHaveStyle({
17
- borderLeftColor: '#87CEFA'
18
- });
19
- });
20
- });
@@ -1 +0,0 @@
1
- export {};