@ledgerhq/lumen-ui-rnative 0.1.63 → 0.1.65

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 (165) hide show
  1. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.js +19 -11
  2. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.js.map +1 -1
  3. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.test.js +113 -4
  4. package/dist/module/lib/Components/core/AmountDisplay/AmountDisplay.test.js.map +1 -1
  5. package/dist/module/lib/Components/core/BottomSheet/BottomSheet.stories.js +51 -0
  6. package/dist/module/lib/Components/core/BottomSheet/BottomSheet.stories.js.map +1 -1
  7. package/dist/module/lib/Components/core/CardButton/CardButton.js +2 -0
  8. package/dist/module/lib/Components/core/CardButton/CardButton.js.map +1 -1
  9. package/dist/module/lib/Components/core/CardButton/CardButton.mdx +4 -0
  10. package/dist/module/lib/Components/core/CardButton/CardButton.stories.js +1 -0
  11. package/dist/module/lib/Components/core/CardButton/CardButton.stories.js.map +1 -1
  12. package/dist/module/lib/Components/core/Link/Link.figma.js +2 -1
  13. package/dist/module/lib/Components/core/Link/Link.figma.js.map +1 -1
  14. package/dist/module/lib/Components/core/Link/Link.js +5 -3
  15. package/dist/module/lib/Components/core/Link/Link.js.map +1 -1
  16. package/dist/module/lib/Components/core/Link/Link.mdx +3 -2
  17. package/dist/module/lib/Components/core/Link/Link.stories.js +4 -1
  18. package/dist/module/lib/Components/core/Link/Link.stories.js.map +1 -1
  19. package/dist/module/lib/Components/core/Link/Link.test.js +2 -2
  20. package/dist/module/lib/Components/core/Link/Link.test.js.map +1 -1
  21. package/dist/module/lib/Components/core/MenuList/MenuList.js +93 -7
  22. package/dist/module/lib/Components/core/MenuList/MenuList.js.map +1 -1
  23. package/dist/module/lib/Components/core/MenuList/MenuList.mdx +14 -1
  24. package/dist/module/lib/Components/core/MenuList/MenuList.stories.js +39 -2
  25. package/dist/module/lib/Components/core/MenuList/MenuList.stories.js.map +1 -1
  26. package/dist/module/lib/Components/core/MenuList/MenuList.test.js +60 -2
  27. package/dist/module/lib/Components/core/MenuList/MenuList.test.js.map +1 -1
  28. package/dist/module/lib/Components/core/SegmentedControl/SegmentedControl.js +1 -1
  29. package/dist/module/lib/Components/core/SegmentedControl/SegmentedControl.js.map +1 -1
  30. package/dist/module/lib/Components/core/Stepper/Stepper.js +76 -30
  31. package/dist/module/lib/Components/core/Stepper/Stepper.js.map +1 -1
  32. package/dist/module/lib/Components/core/Stepper/Stepper.mdx +37 -16
  33. package/dist/module/lib/Components/core/Stepper/Stepper.stories.js +102 -2
  34. package/dist/module/lib/Components/core/Stepper/Stepper.stories.js.map +1 -1
  35. package/dist/module/lib/Components/core/Stepper/Stepper.test.js +32 -1
  36. package/dist/module/lib/Components/core/Stepper/Stepper.test.js.map +1 -1
  37. package/dist/module/lib/Components/core/Timeline/Timeline.figma.js +83 -0
  38. package/dist/module/lib/Components/core/Timeline/Timeline.figma.js.map +1 -0
  39. package/dist/module/lib/Components/core/Timeline/Timeline.js +464 -0
  40. package/dist/module/lib/Components/core/Timeline/Timeline.js.map +1 -0
  41. package/dist/module/lib/Components/core/Timeline/Timeline.mdx +49 -0
  42. package/dist/module/lib/Components/core/Timeline/Timeline.stories.js +289 -0
  43. package/dist/module/lib/Components/core/Timeline/Timeline.stories.js.map +1 -0
  44. package/dist/module/lib/Components/core/Timeline/Timeline.test.js +234 -0
  45. package/dist/module/lib/Components/core/Timeline/Timeline.test.js.map +1 -0
  46. package/dist/module/lib/Components/core/Timeline/index.js +5 -0
  47. package/dist/module/lib/Components/core/Timeline/index.js.map +1 -0
  48. package/dist/module/lib/Components/core/Timeline/types.js +4 -0
  49. package/dist/module/lib/Components/core/Timeline/types.js.map +1 -0
  50. package/dist/module/lib/Components/core/Toast/Toast.figma.js +39 -0
  51. package/dist/module/lib/Components/core/Toast/Toast.figma.js.map +1 -0
  52. package/dist/module/lib/Components/core/Toast/Toast.js +138 -0
  53. package/dist/module/lib/Components/core/Toast/Toast.js.map +1 -0
  54. package/dist/module/lib/Components/core/Toast/Toast.mdx +203 -0
  55. package/dist/module/lib/Components/core/Toast/Toast.stories.js +238 -0
  56. package/dist/module/lib/Components/core/Toast/Toast.stories.js.map +1 -0
  57. package/dist/module/lib/Components/core/Toast/Toast.test.js +203 -0
  58. package/dist/module/lib/Components/core/Toast/Toast.test.js.map +1 -0
  59. package/dist/module/lib/Components/core/Toast/Toaster.js +147 -0
  60. package/dist/module/lib/Components/core/Toast/Toaster.js.map +1 -0
  61. package/dist/module/lib/Components/core/Toast/Toaster.test.js +732 -0
  62. package/dist/module/lib/Components/core/Toast/Toaster.test.js.map +1 -0
  63. package/dist/module/lib/Components/core/Toast/hooks/useToastAccessibility.js +70 -0
  64. package/dist/module/lib/Components/core/Toast/hooks/useToastAccessibility.js.map +1 -0
  65. package/dist/module/lib/Components/core/Toast/hooks/useToastCollapse.js +33 -0
  66. package/dist/module/lib/Components/core/Toast/hooks/useToastCollapse.js.map +1 -0
  67. package/dist/module/lib/Components/core/Toast/hooks/useToastGesture.js +224 -0
  68. package/dist/module/lib/Components/core/Toast/hooks/useToastGesture.js.map +1 -0
  69. package/dist/module/lib/Components/core/Toast/hooks/useToastMotion.js +82 -0
  70. package/dist/module/lib/Components/core/Toast/hooks/useToastMotion.js.map +1 -0
  71. package/dist/module/lib/Components/core/Toast/hooks/useToastViewportStyles.js +21 -0
  72. package/dist/module/lib/Components/core/Toast/hooks/useToastViewportStyles.js.map +1 -0
  73. package/dist/module/lib/Components/core/Toast/index.js +7 -0
  74. package/dist/module/lib/Components/core/Toast/index.js.map +1 -0
  75. package/dist/module/lib/Components/core/Toast/types.js +4 -0
  76. package/dist/module/lib/Components/core/Toast/types.js.map +1 -0
  77. package/dist/module/lib/Components/core/index.js +2 -0
  78. package/dist/module/lib/Components/core/index.js.map +1 -1
  79. package/dist/typescript/src/lib/Components/core/AmountDisplay/AmountDisplay.d.ts.map +1 -1
  80. package/dist/typescript/src/lib/Components/core/CardButton/CardButton.d.ts +2 -0
  81. package/dist/typescript/src/lib/Components/core/CardButton/CardButton.d.ts.map +1 -1
  82. package/dist/typescript/src/lib/Components/core/Link/Link.d.ts +1 -1
  83. package/dist/typescript/src/lib/Components/core/Link/Link.d.ts.map +1 -1
  84. package/dist/typescript/src/lib/Components/core/Link/types.d.ts +1 -1
  85. package/dist/typescript/src/lib/Components/core/Link/types.d.ts.map +1 -1
  86. package/dist/typescript/src/lib/Components/core/MenuList/MenuList.d.ts +12 -2
  87. package/dist/typescript/src/lib/Components/core/MenuList/MenuList.d.ts.map +1 -1
  88. package/dist/typescript/src/lib/Components/core/MenuList/types.d.ts +26 -7
  89. package/dist/typescript/src/lib/Components/core/MenuList/types.d.ts.map +1 -1
  90. package/dist/typescript/src/lib/Components/core/Stepper/Stepper.d.ts +4 -3
  91. package/dist/typescript/src/lib/Components/core/Stepper/Stepper.d.ts.map +1 -1
  92. package/dist/typescript/src/lib/Components/core/Stepper/types.d.ts +12 -2
  93. package/dist/typescript/src/lib/Components/core/Stepper/types.d.ts.map +1 -1
  94. package/dist/typescript/src/lib/Components/core/Timeline/Timeline.d.ts +56 -0
  95. package/dist/typescript/src/lib/Components/core/Timeline/Timeline.d.ts.map +1 -0
  96. package/dist/typescript/src/lib/Components/core/Timeline/index.d.ts +3 -0
  97. package/dist/typescript/src/lib/Components/core/Timeline/index.d.ts.map +1 -0
  98. package/dist/typescript/src/lib/Components/core/Timeline/types.d.ts +109 -0
  99. package/dist/typescript/src/lib/Components/core/Timeline/types.d.ts.map +1 -0
  100. package/dist/typescript/src/lib/Components/core/Toast/Toast.d.ts +24 -0
  101. package/dist/typescript/src/lib/Components/core/Toast/Toast.d.ts.map +1 -0
  102. package/dist/typescript/src/lib/Components/core/Toast/Toaster.d.ts +35 -0
  103. package/dist/typescript/src/lib/Components/core/Toast/Toaster.d.ts.map +1 -0
  104. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastAccessibility.d.ts +17 -0
  105. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastAccessibility.d.ts.map +1 -0
  106. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastCollapse.d.ts +19 -0
  107. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastCollapse.d.ts.map +1 -0
  108. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastGesture.d.ts +14 -0
  109. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastGesture.d.ts.map +1 -0
  110. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastMotion.d.ts +15 -0
  111. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastMotion.d.ts.map +1 -0
  112. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastViewportStyles.d.ts +21 -0
  113. package/dist/typescript/src/lib/Components/core/Toast/hooks/useToastViewportStyles.d.ts.map +1 -0
  114. package/dist/typescript/src/lib/Components/core/Toast/index.d.ts +5 -0
  115. package/dist/typescript/src/lib/Components/core/Toast/index.d.ts.map +1 -0
  116. package/dist/typescript/src/lib/Components/core/Toast/types.d.ts +75 -0
  117. package/dist/typescript/src/lib/Components/core/Toast/types.d.ts.map +1 -0
  118. package/dist/typescript/src/lib/Components/core/index.d.ts +2 -0
  119. package/dist/typescript/src/lib/Components/core/index.d.ts.map +1 -1
  120. package/package.json +3 -3
  121. package/src/lib/Components/core/AmountDisplay/AmountDisplay.test.tsx +138 -4
  122. package/src/lib/Components/core/AmountDisplay/AmountDisplay.tsx +13 -6
  123. package/src/lib/Components/core/BottomSheet/BottomSheet.stories.tsx +51 -0
  124. package/src/lib/Components/core/CardButton/CardButton.mdx +4 -0
  125. package/src/lib/Components/core/CardButton/CardButton.stories.tsx +1 -0
  126. package/src/lib/Components/core/CardButton/CardButton.tsx +2 -0
  127. package/src/lib/Components/core/Link/Link.figma.tsx +1 -0
  128. package/src/lib/Components/core/Link/Link.mdx +3 -2
  129. package/src/lib/Components/core/Link/Link.stories.tsx +3 -2
  130. package/src/lib/Components/core/Link/Link.test.tsx +2 -0
  131. package/src/lib/Components/core/Link/Link.tsx +3 -1
  132. package/src/lib/Components/core/Link/types.ts +1 -1
  133. package/src/lib/Components/core/MenuList/MenuList.mdx +14 -1
  134. package/src/lib/Components/core/MenuList/MenuList.stories.tsx +30 -2
  135. package/src/lib/Components/core/MenuList/MenuList.test.tsx +72 -2
  136. package/src/lib/Components/core/MenuList/MenuList.tsx +94 -11
  137. package/src/lib/Components/core/MenuList/types.ts +29 -7
  138. package/src/lib/Components/core/SegmentedControl/SegmentedControl.tsx +1 -1
  139. package/src/lib/Components/core/Stepper/Stepper.mdx +37 -16
  140. package/src/lib/Components/core/Stepper/Stepper.stories.tsx +50 -2
  141. package/src/lib/Components/core/Stepper/Stepper.test.tsx +29 -1
  142. package/src/lib/Components/core/Stepper/Stepper.tsx +73 -32
  143. package/src/lib/Components/core/Stepper/types.ts +12 -2
  144. package/src/lib/Components/core/Timeline/Timeline.figma.tsx +79 -0
  145. package/src/lib/Components/core/Timeline/Timeline.mdx +49 -0
  146. package/src/lib/Components/core/Timeline/Timeline.stories.tsx +250 -0
  147. package/src/lib/Components/core/Timeline/Timeline.test.tsx +275 -0
  148. package/src/lib/Components/core/Timeline/Timeline.tsx +576 -0
  149. package/src/lib/Components/core/Timeline/index.ts +2 -0
  150. package/src/lib/Components/core/Timeline/types.ts +124 -0
  151. package/src/lib/Components/core/Toast/Toast.figma.tsx +36 -0
  152. package/src/lib/Components/core/Toast/Toast.mdx +203 -0
  153. package/src/lib/Components/core/Toast/Toast.stories.tsx +260 -0
  154. package/src/lib/Components/core/Toast/Toast.test.tsx +181 -0
  155. package/src/lib/Components/core/Toast/Toast.tsx +163 -0
  156. package/src/lib/Components/core/Toast/Toaster.test.tsx +687 -0
  157. package/src/lib/Components/core/Toast/Toaster.tsx +157 -0
  158. package/src/lib/Components/core/Toast/hooks/useToastAccessibility.ts +82 -0
  159. package/src/lib/Components/core/Toast/hooks/useToastCollapse.ts +38 -0
  160. package/src/lib/Components/core/Toast/hooks/useToastGesture.ts +83 -0
  161. package/src/lib/Components/core/Toast/hooks/useToastMotion.ts +71 -0
  162. package/src/lib/Components/core/Toast/hooks/useToastViewportStyles.ts +45 -0
  163. package/src/lib/Components/core/Toast/index.ts +4 -0
  164. package/src/lib/Components/core/Toast/types.ts +94 -0
  165. package/src/lib/Components/core/index.ts +2 -0
@@ -0,0 +1,732 @@
1
+ "use strict";
2
+
3
+ import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals';
4
+ import { ledgerLiveThemes } from '@ledgerhq/lumen-design-core';
5
+ import { toast, toastStore, EXIT_ANIMATION_MS } from '@ledgerhq/lumen-utils-shared';
6
+ import { act, fireEvent, render, screen } from '@testing-library/react-native';
7
+ import { useLayoutEffect } from 'react';
8
+ import { AccessibilityInfo, Platform } from 'react-native';
9
+ import { SafeAreaProvider } from 'react-native-safe-area-context';
10
+ import { ThemeProvider } from "../ThemeProvider/ThemeProvider.js";
11
+ import { Toaster } from "./Toaster.js";
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ const initialMetrics = {
14
+ frame: {
15
+ x: 0,
16
+ y: 0,
17
+ width: 320,
18
+ height: 640
19
+ },
20
+ insets: {
21
+ top: 0,
22
+ left: 0,
23
+ right: 0,
24
+ bottom: 0
25
+ }
26
+ };
27
+ const TestProviders = ({
28
+ children
29
+ }) => /*#__PURE__*/_jsx(SafeAreaProvider, {
30
+ initialMetrics: initialMetrics,
31
+ children: /*#__PURE__*/_jsx(ThemeProvider, {
32
+ themes: ledgerLiveThemes,
33
+ colorScheme: "dark",
34
+ locale: "en",
35
+ children: children
36
+ })
37
+ });
38
+ const renderToaster = props => render(/*#__PURE__*/_jsx(TestProviders, {
39
+ children: /*#__PURE__*/_jsx(Toaster, {
40
+ ...props
41
+ })
42
+ }));
43
+ const clearToastItems = () => {
44
+ for (const {
45
+ id
46
+ } of toastStore.getSnapshot()) {
47
+ toastStore.dismiss(id);
48
+ toastStore.dismiss(id);
49
+ }
50
+ };
51
+ const flushExit = () => {
52
+ act(() => {
53
+ jest.advanceTimersByTime(EXIT_ANIMATION_MS);
54
+ });
55
+ };
56
+ describe('Toaster', () => {
57
+ beforeEach(() => {
58
+ clearToastItems();
59
+ });
60
+ describe('Timing', () => {
61
+ beforeEach(() => {
62
+ jest.useFakeTimers();
63
+ });
64
+ afterEach(() => {
65
+ act(() => {
66
+ jest.runOnlyPendingTimers();
67
+ });
68
+ jest.useRealTimers();
69
+ });
70
+ it('should render a toast on notify', () => {
71
+ renderToaster();
72
+ act(() => {
73
+ toast.info({
74
+ title: 'Hello'
75
+ });
76
+ });
77
+ screen.getByText('Hello');
78
+ });
79
+ it('should show a toast that was notified before the toaster mounted', () => {
80
+ act(() => {
81
+ toast.info({
82
+ title: 'Queued early'
83
+ });
84
+ });
85
+ renderToaster();
86
+ screen.getByText('Queued early');
87
+ });
88
+ it('should apply Toaster props to toasts fired before its effects run', () => {
89
+ const EarlyNotifier = () => {
90
+ useLayoutEffect(() => {
91
+ toast.info({
92
+ title: 'First'
93
+ });
94
+ toast.info({
95
+ title: 'Second'
96
+ });
97
+ }, []);
98
+ return null;
99
+ };
100
+ render(/*#__PURE__*/_jsxs(TestProviders, {
101
+ children: [/*#__PURE__*/_jsx(EarlyNotifier, {}), /*#__PURE__*/_jsx(Toaster, {
102
+ maxItems: 1,
103
+ durations: {
104
+ info: 1000
105
+ }
106
+ })]
107
+ }));
108
+ expect(screen.queryByText('Second')).toBeNull();
109
+ act(() => {
110
+ jest.advanceTimersByTime(1000);
111
+ });
112
+ flushExit();
113
+ expect(screen.queryByText('First')).toBeNull();
114
+ screen.getByText('Second');
115
+ });
116
+ it('should auto-dismiss info after the default 5s', () => {
117
+ renderToaster();
118
+ act(() => {
119
+ toast.info({
120
+ title: 'Hello'
121
+ });
122
+ });
123
+ act(() => {
124
+ jest.advanceTimersByTime(4999);
125
+ });
126
+ screen.getByText('Hello');
127
+ act(() => {
128
+ jest.advanceTimersByTime(1);
129
+ });
130
+ flushExit();
131
+ expect(screen.queryByText('Hello')).toBeNull();
132
+ });
133
+ it('should keep warning toasts until dismissed', () => {
134
+ renderToaster();
135
+ act(() => {
136
+ toast.warning({
137
+ title: 'Careful'
138
+ });
139
+ });
140
+ act(() => {
141
+ jest.advanceTimersByTime(60000);
142
+ });
143
+ screen.getByText('Careful');
144
+ });
145
+ it('should queue items past maxItems and promote them as slots free', () => {
146
+ renderToaster({
147
+ maxItems: 1
148
+ });
149
+ act(() => {
150
+ toast.info({
151
+ title: 'First'
152
+ });
153
+ toast.info({
154
+ title: 'Second'
155
+ });
156
+ });
157
+ screen.getByText('First');
158
+ expect(screen.queryByText('Second')).toBeNull();
159
+ act(() => {
160
+ jest.advanceTimersByTime(5000);
161
+ });
162
+ flushExit();
163
+ expect(screen.queryByText('First')).toBeNull();
164
+ screen.getByText('Second');
165
+ });
166
+ it('should not keep a per-item duration across an update that omits it', () => {
167
+ renderToaster();
168
+ let id = '';
169
+ act(() => {
170
+ id = toast.loading({
171
+ title: 'Loading',
172
+ duration: 10000
173
+ }).id;
174
+ });
175
+ act(() => {
176
+ toast.update(id, {
177
+ appearance: 'success',
178
+ loading: false,
179
+ title: 'Done'
180
+ });
181
+ });
182
+ act(() => {
183
+ jest.advanceTimersByTime(5000);
184
+ });
185
+ flushExit();
186
+ expect(screen.queryByText('Done')).toBeNull();
187
+ });
188
+ it('should pause the timer while held and resume remaining time on release', () => {
189
+ const {
190
+ getByTestId
191
+ } = renderToaster();
192
+ act(() => {
193
+ toast.info({
194
+ title: 'Hold me'
195
+ });
196
+ });
197
+ act(() => {
198
+ jest.advanceTimersByTime(2000);
199
+ });
200
+ const entry = getByTestId('toast-entry');
201
+ act(() => {
202
+ entry.props.onTouchesDown();
203
+ });
204
+ act(() => {
205
+ jest.advanceTimersByTime(60000);
206
+ });
207
+ screen.getByText('Hold me');
208
+ act(() => {
209
+ entry.props.onTouchesUp({
210
+ numberOfTouches: 0
211
+ });
212
+ });
213
+ act(() => {
214
+ jest.advanceTimersByTime(2999);
215
+ });
216
+ screen.getByText('Hold me');
217
+ act(() => {
218
+ jest.advanceTimersByTime(1);
219
+ });
220
+ flushExit();
221
+ expect(screen.queryByText('Hold me')).toBeNull();
222
+ });
223
+ it('should stay paused while swiping and resume once the toast springs back', () => {
224
+ const {
225
+ getByTestId
226
+ } = renderToaster();
227
+ act(() => {
228
+ toast.info({
229
+ title: 'Swipe me'
230
+ });
231
+ });
232
+ act(() => {
233
+ jest.advanceTimersByTime(2000);
234
+ });
235
+ const entry = getByTestId('toast-entry');
236
+ act(() => {
237
+ entry.props.onTouchesDown();
238
+ entry.props.onUpdate({
239
+ translationX: 40
240
+ });
241
+ });
242
+ act(() => {
243
+ jest.advanceTimersByTime(60000);
244
+ });
245
+ screen.getByText('Swipe me');
246
+ act(() => {
247
+ entry.props.onEnd({
248
+ translationX: 20
249
+ });
250
+ entry.props.onFinalize();
251
+ });
252
+ act(() => {
253
+ jest.advanceTimersByTime(2999);
254
+ });
255
+ screen.getByText('Swipe me');
256
+ act(() => {
257
+ jest.advanceTimersByTime(1);
258
+ });
259
+ flushExit();
260
+ expect(screen.queryByText('Swipe me')).toBeNull();
261
+ });
262
+ it('should restart the timer when a loading toast becomes a success', () => {
263
+ renderToaster();
264
+ let id = '';
265
+ act(() => {
266
+ id = toast.loading({
267
+ title: 'Loading'
268
+ }).id;
269
+ });
270
+ act(() => {
271
+ jest.advanceTimersByTime(60000);
272
+ });
273
+ screen.getByText('Loading');
274
+ act(() => {
275
+ toast.update(id, {
276
+ appearance: 'success',
277
+ loading: false,
278
+ title: 'Done'
279
+ });
280
+ });
281
+ screen.getByText('Done');
282
+ act(() => {
283
+ jest.advanceTimersByTime(5000);
284
+ });
285
+ flushExit();
286
+ expect(screen.queryByText('Done')).toBeNull();
287
+ });
288
+ });
289
+ describe('Defaults', () => {
290
+ it('should default maxItems to 1', () => {
291
+ renderToaster();
292
+ act(() => {
293
+ toast.info({
294
+ title: 'First'
295
+ });
296
+ toast.info({
297
+ title: 'Second'
298
+ });
299
+ });
300
+ screen.getByText('First');
301
+ expect(screen.queryByText('Second')).toBeNull();
302
+ });
303
+ it('should default position to bottom', () => {
304
+ const {
305
+ getByTestId
306
+ } = renderToaster();
307
+ const viewport = getByTestId('toast-viewport');
308
+ expect(viewport.props.style.bottom).toBeDefined();
309
+ expect(viewport.props.style.top).toBeUndefined();
310
+ });
311
+ it('should anchor the viewport to the top when position is top', () => {
312
+ const {
313
+ getByTestId
314
+ } = renderToaster({
315
+ position: 'top'
316
+ });
317
+ const viewport = getByTestId('toast-viewport');
318
+ expect(viewport.props.style.top).toBeDefined();
319
+ expect(viewport.props.style.bottom).toBeUndefined();
320
+ });
321
+ it('should default insets to 0 and still apply the breathing-room gap', () => {
322
+ const {
323
+ getByTestId
324
+ } = renderToaster();
325
+ expect(getByTestId('toast-viewport').props.style.bottom).toBe(24);
326
+ });
327
+ it('adds a custom bottom inset to the gap instead of replacing it', () => {
328
+ const {
329
+ getByTestId
330
+ } = renderToaster({
331
+ insets: {
332
+ bottom: 80
333
+ }
334
+ });
335
+ expect(getByTestId('toast-viewport').props.style.bottom).toBe(104);
336
+ });
337
+ });
338
+ describe('Dismissal', () => {
339
+ beforeEach(() => {
340
+ jest.useFakeTimers();
341
+ });
342
+ afterEach(() => {
343
+ act(() => {
344
+ jest.runOnlyPendingTimers();
345
+ });
346
+ jest.useRealTimers();
347
+ });
348
+ it('should collapse the stack slot while exiting', () => {
349
+ renderToaster();
350
+ let id = '';
351
+ act(() => {
352
+ id = toast.warning({
353
+ title: 'Careful'
354
+ }).id;
355
+ });
356
+ act(() => {
357
+ toast.dismiss(id);
358
+ });
359
+ expect(screen.getByTestId('toast-collapse')).toHaveStyle({
360
+ height: 0
361
+ });
362
+ flushExit();
363
+ expect(screen.queryByText('Careful')).toBeNull();
364
+ });
365
+ it('should dismiss a single item by id and dismiss all', () => {
366
+ renderToaster({
367
+ maxItems: 2
368
+ });
369
+ let first = '';
370
+ act(() => {
371
+ first = toast.warning({
372
+ title: 'A'
373
+ }).id;
374
+ toast.warning({
375
+ title: 'B'
376
+ });
377
+ });
378
+ act(() => {
379
+ toast.dismiss(first);
380
+ });
381
+ screen.getByText('A');
382
+ flushExit();
383
+ expect(screen.queryByText('A')).toBeNull();
384
+ screen.getByText('B');
385
+ act(() => {
386
+ toast.dismissAll();
387
+ });
388
+ flushExit();
389
+ expect(screen.queryByText('B')).toBeNull();
390
+ });
391
+ it('should dismiss on a swipe past the threshold', () => {
392
+ const {
393
+ getByTestId
394
+ } = renderToaster();
395
+ act(() => {
396
+ toast.warning({
397
+ title: 'Swipe me'
398
+ });
399
+ });
400
+ const entry = getByTestId('toast-entry');
401
+ act(() => {
402
+ entry.props.onEnd({
403
+ translationX: 150
404
+ });
405
+ });
406
+ flushExit();
407
+ expect(screen.queryByText('Swipe me')).toBeNull();
408
+ });
409
+ it('should spring back and stay visible on a swipe under the threshold', () => {
410
+ const {
411
+ getByTestId
412
+ } = renderToaster();
413
+ act(() => {
414
+ toast.warning({
415
+ title: 'Stays put'
416
+ });
417
+ });
418
+ const entry = getByTestId('toast-entry');
419
+ act(() => {
420
+ entry.props.onEnd({
421
+ translationX: 20
422
+ });
423
+ });
424
+ screen.getByText('Stays put');
425
+ });
426
+ it('should stay visible when swiped past the threshold if not dismissible', () => {
427
+ const {
428
+ getByTestId
429
+ } = renderToaster();
430
+ act(() => {
431
+ toast.warning({
432
+ title: 'Locked',
433
+ dismissible: false
434
+ });
435
+ });
436
+ const entry = getByTestId('toast-entry');
437
+ act(() => {
438
+ entry.props.onEnd({
439
+ translationX: 150
440
+ });
441
+ });
442
+ flushExit();
443
+ screen.getByText('Locked');
444
+ });
445
+ });
446
+ describe('Accessibility', () => {
447
+ beforeEach(() => {
448
+ jest.useFakeTimers();
449
+ });
450
+ afterEach(() => {
451
+ act(() => {
452
+ jest.runOnlyPendingTimers();
453
+ });
454
+ jest.useRealTimers();
455
+ });
456
+ it('should expose the toast as one element labelled by its title', () => {
457
+ renderToaster();
458
+ act(() => {
459
+ toast.info({
460
+ title: 'Saved'
461
+ });
462
+ });
463
+ const entry = screen.getByTestId('toast-entry');
464
+ expect(entry.props.accessible).toBe(true);
465
+ expect(entry.props.accessibilityLabel).toBe('Saved');
466
+ });
467
+ it('should dismiss through the dismiss accessibility action', () => {
468
+ renderToaster();
469
+ act(() => {
470
+ toast.warning({
471
+ title: 'Dismiss me'
472
+ });
473
+ });
474
+ expect(screen.getByTestId('toast-entry').props.accessibilityActions).toContainEqual({
475
+ name: 'dismiss',
476
+ label: 'Close'
477
+ });
478
+ fireEvent(screen.getByTestId('toast-entry'), 'accessibilityAction', {
479
+ nativeEvent: {
480
+ actionName: 'dismiss'
481
+ }
482
+ });
483
+ flushExit();
484
+ expect(screen.queryByText('Dismiss me')).toBeNull();
485
+ });
486
+ it('should dismiss on the iOS escape gesture', () => {
487
+ renderToaster();
488
+ act(() => {
489
+ toast.warning({
490
+ title: 'Escape me'
491
+ });
492
+ });
493
+ fireEvent(screen.getByTestId('toast-entry'), 'accessibilityEscape');
494
+ flushExit();
495
+ expect(screen.queryByText('Escape me')).toBeNull();
496
+ });
497
+ it('should expose the inline action as an accessibility action', () => {
498
+ const onAction = jest.fn();
499
+ renderToaster();
500
+ act(() => {
501
+ toast.warning({
502
+ title: 'Deleted',
503
+ action: {
504
+ label: 'Undo',
505
+ onAction
506
+ }
507
+ });
508
+ });
509
+ const entry = screen.getByTestId('toast-entry');
510
+ expect(entry.props.accessibilityActions).toContainEqual({
511
+ name: 'toastAction',
512
+ label: 'Undo'
513
+ });
514
+ fireEvent(entry, 'accessibilityAction', {
515
+ nativeEvent: {
516
+ actionName: 'toastAction'
517
+ }
518
+ });
519
+ expect(onAction).toHaveBeenCalledTimes(1);
520
+ screen.getByText('Deleted');
521
+ });
522
+ it('should not offer dismissal for a non-dismissible toast', () => {
523
+ renderToaster();
524
+ act(() => {
525
+ toast.info({
526
+ title: 'Locked',
527
+ dismissible: false
528
+ });
529
+ });
530
+ const entry = screen.getByTestId('toast-entry');
531
+ expect(entry.props.accessibilityActions).toEqual([]);
532
+ expect(entry.props.onAccessibilityEscape).toBeUndefined();
533
+ });
534
+ describe('on iOS', () => {
535
+ const originalOS = Platform.OS;
536
+ beforeEach(() => {
537
+ Platform.OS = 'ios';
538
+ });
539
+ afterEach(() => {
540
+ Platform.OS = originalOS;
541
+ });
542
+ it('should announce the title, interrupting only for warning and error', () => {
543
+ const announce = jest.spyOn(AccessibilityInfo, 'announceForAccessibilityWithOptions').mockImplementation(() => undefined);
544
+ renderToaster({
545
+ maxItems: 2
546
+ });
547
+ act(() => {
548
+ toast.info({
549
+ title: 'Heads up'
550
+ });
551
+ toast.error({
552
+ title: 'Failed'
553
+ });
554
+ });
555
+ expect(announce).toHaveBeenCalledWith('Heads up', {
556
+ queue: true
557
+ });
558
+ expect(announce).toHaveBeenCalledWith('Failed', {
559
+ queue: false
560
+ });
561
+ announce.mockRestore();
562
+ });
563
+ it('should announce again when the title changes', () => {
564
+ const announce = jest.spyOn(AccessibilityInfo, 'announceForAccessibilityWithOptions').mockImplementation(() => undefined);
565
+ renderToaster();
566
+ let id = '';
567
+ act(() => {
568
+ id = toast.info({
569
+ title: 'Uploading',
570
+ loading: true
571
+ }).id;
572
+ });
573
+ act(() => {
574
+ toast.update(id, {
575
+ title: 'Uploaded',
576
+ appearance: 'success'
577
+ });
578
+ });
579
+ expect(announce).toHaveBeenLastCalledWith('Uploaded', {
580
+ queue: true
581
+ });
582
+ announce.mockRestore();
583
+ });
584
+ });
585
+ });
586
+ describe('promise', () => {
587
+ it('should move the toast from loading to success', async () => {
588
+ renderToaster();
589
+ let resolveFn = () => {};
590
+ const promise = new Promise(resolve => {
591
+ resolveFn = resolve;
592
+ });
593
+ act(() => {
594
+ toast.promise(promise, {
595
+ loading: {
596
+ title: 'Saving'
597
+ },
598
+ success: {
599
+ title: 'Saved'
600
+ },
601
+ error: {
602
+ title: 'Failed'
603
+ }
604
+ });
605
+ });
606
+ screen.getByText('Saving');
607
+ resolveFn('ok');
608
+ expect(await screen.findByText('Saved')).toBeTruthy();
609
+ });
610
+ it('should drop the loading action when success omits it', async () => {
611
+ renderToaster();
612
+ let resolveFn = () => {};
613
+ const promise = new Promise(resolve => {
614
+ resolveFn = resolve;
615
+ });
616
+ act(() => {
617
+ toast.promise(promise, {
618
+ loading: {
619
+ title: 'Saving',
620
+ action: {
621
+ label: 'Cancel',
622
+ onAction: () => {}
623
+ }
624
+ },
625
+ success: {
626
+ title: 'Saved'
627
+ },
628
+ error: {
629
+ title: 'Failed'
630
+ }
631
+ });
632
+ });
633
+ screen.getByText('Cancel');
634
+ resolveFn('ok');
635
+ expect(await screen.findByText('Saved')).toBeTruthy();
636
+ expect(screen.queryByText('Cancel')).toBeNull();
637
+ });
638
+ it('should drop the loading action when error omits it', async () => {
639
+ renderToaster();
640
+ let rejectFn = () => {};
641
+ const promise = new Promise((_resolve, reject) => {
642
+ rejectFn = reject;
643
+ });
644
+ act(() => {
645
+ toast.promise(promise, {
646
+ loading: {
647
+ title: 'Saving',
648
+ action: {
649
+ label: 'Cancel',
650
+ onAction: () => {}
651
+ }
652
+ },
653
+ success: {
654
+ title: 'Saved'
655
+ },
656
+ error: {
657
+ title: 'Failed'
658
+ }
659
+ });
660
+ });
661
+ screen.getByText('Cancel');
662
+ rejectFn(new Error('nope'));
663
+ expect(await screen.findByText('Failed')).toBeTruthy();
664
+ expect(screen.queryByText('Cancel')).toBeNull();
665
+ });
666
+ it('should restore dismissal when error omits dismissible', async () => {
667
+ renderToaster();
668
+ let rejectFn = () => {};
669
+ const promise = new Promise((_resolve, reject) => {
670
+ rejectFn = reject;
671
+ });
672
+ act(() => {
673
+ toast.promise(promise, {
674
+ loading: {
675
+ title: 'Saving',
676
+ dismissible: false
677
+ },
678
+ success: {
679
+ title: 'Saved'
680
+ },
681
+ error: {
682
+ title: 'Failed'
683
+ }
684
+ });
685
+ });
686
+ expect(screen.getByTestId('toast-entry').props.onAccessibilityEscape).toBeUndefined();
687
+ rejectFn(new Error('nope'));
688
+ expect(await screen.findByText('Failed')).toBeTruthy();
689
+ expect(screen.getByTestId('toast-entry').props.accessibilityActions).toContainEqual(expect.objectContaining({
690
+ name: 'dismiss'
691
+ }));
692
+ });
693
+ it('should move the toast from loading to error on rejection', async () => {
694
+ renderToaster();
695
+ let rejectFn = () => {};
696
+ const promise = new Promise((_resolve, reject) => {
697
+ rejectFn = reject;
698
+ });
699
+ act(() => {
700
+ toast.promise(promise, {
701
+ loading: {
702
+ title: 'Saving'
703
+ },
704
+ success: {
705
+ title: 'Saved'
706
+ },
707
+ error: {
708
+ title: 'Failed'
709
+ }
710
+ });
711
+ });
712
+ screen.getByText('Saving');
713
+ rejectFn(new Error('nope'));
714
+ expect(await screen.findByText('Failed')).toBeTruthy();
715
+ });
716
+ });
717
+ describe('Multiple instances', () => {
718
+ it('warns when a second Toaster mounts while one is already mounted', () => {
719
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {
720
+ return;
721
+ });
722
+ const first = renderToaster();
723
+ expect(warnSpy).not.toHaveBeenCalled();
724
+ const second = renderToaster();
725
+ expect(warnSpy).toHaveBeenCalledTimes(1);
726
+ first.unmount();
727
+ second.unmount();
728
+ warnSpy.mockRestore();
729
+ });
730
+ });
731
+ });
732
+ //# sourceMappingURL=Toaster.test.js.map