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