cpk-ui 0.5.5 → 0.7.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 (130) hide show
  1. package/README.md +80 -147
  2. package/components/modals/AlertDialog/AlertDialog.d.ts.map +1 -1
  3. package/components/modals/AlertDialog/AlertDialog.js +14 -7
  4. package/components/modals/Snackbar/Snackbar.d.ts.map +1 -1
  5. package/components/modals/Snackbar/Snackbar.js +20 -17
  6. package/components/uis/Accordion/AccordionItem.d.ts.map +1 -1
  7. package/components/uis/Accordion/AccordionItem.js +41 -17
  8. package/components/uis/Button/Button.d.ts.map +1 -1
  9. package/components/uis/Button/Button.js +10 -10
  10. package/components/uis/Card/Card.d.ts +2 -1
  11. package/components/uis/Card/Card.d.ts.map +1 -1
  12. package/components/uis/Card/Card.js +12 -3
  13. package/components/uis/Checkbox/Checkbox.d.ts.map +1 -1
  14. package/components/uis/Checkbox/Checkbox.js +1 -1
  15. package/components/uis/CustomPressable/CustomPressable.d.ts.map +1 -1
  16. package/components/uis/CustomPressable/CustomPressable.js +6 -6
  17. package/components/uis/EditText/EditText.d.ts.map +1 -1
  18. package/components/uis/EditText/EditText.js +17 -12
  19. package/components/uis/Fab/Fab.d.ts +2 -2
  20. package/components/uis/Fab/Fab.d.ts.map +1 -1
  21. package/components/uis/Fab/Fab.js +22 -4
  22. package/components/uis/Icon/Icon.d.ts.map +1 -1
  23. package/components/uis/Icon/Icon.js +6 -3
  24. package/components/uis/IconButton/IconButton.d.ts.map +1 -1
  25. package/components/uis/IconButton/IconButton.js +43 -41
  26. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts +2 -1
  27. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts.map +1 -1
  28. package/components/uis/LoadingIndicator/LoadingIndicator.js +4 -4
  29. package/components/uis/RadioGroup/RadioButton.d.ts.map +1 -1
  30. package/components/uis/RadioGroup/RadioButton.js +1 -1
  31. package/components/uis/RadioGroup/RadioGroup.d.ts.map +1 -1
  32. package/components/uis/RadioGroup/RadioGroup.js +16 -3
  33. package/components/uis/Rating/Rating.d.ts.map +1 -1
  34. package/components/uis/Rating/Rating.js +23 -19
  35. package/components/uis/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  36. package/components/uis/SegmentedControl/SegmentedControl.js +1 -1
  37. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts +2 -2
  38. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts.map +1 -1
  39. package/components/uis/StatusbarBrightness/StatusBarBrightness.js +1 -1
  40. package/components/uis/SwitchToggle/SwitchToggle.d.ts.map +1 -1
  41. package/components/uis/SwitchToggle/SwitchToggle.js +1 -1
  42. package/hooks/useHoverState.d.ts +8 -0
  43. package/hooks/useHoverState.d.ts.map +1 -0
  44. package/hooks/useHoverState.js +16 -0
  45. package/package.json +18 -6
  46. package/providers/ThemeProvider.d.ts.map +1 -1
  47. package/providers/ThemeProvider.js +0 -1
  48. package/providers/index.d.ts.map +1 -1
  49. package/providers/index.js +3 -2
  50. package/components/uis/Icon/selection.json +0 -1
  51. package/src/components/common/ErrorBoundary/ErrorBoundary.tsx +0 -75
  52. package/src/components/modals/AlertDialog/AlertDialog.stories.tsx +0 -216
  53. package/src/components/modals/AlertDialog/AlertDialog.test.tsx +0 -251
  54. package/src/components/modals/AlertDialog/AlertDialog.tsx +0 -356
  55. package/src/components/modals/Snackbar/Snackbar.stories.tsx +0 -182
  56. package/src/components/modals/Snackbar/Snackbar.test.tsx +0 -319
  57. package/src/components/modals/Snackbar/Snackbar.tsx +0 -260
  58. package/src/components/modals/Snackbar/const.ts +0 -4
  59. package/src/components/uis/Accordion/Accordion.stories.tsx +0 -167
  60. package/src/components/uis/Accordion/Accordion.test.tsx +0 -272
  61. package/src/components/uis/Accordion/Accordion.tsx +0 -109
  62. package/src/components/uis/Accordion/AccordionItem.tsx +0 -306
  63. package/src/components/uis/Button/Button.stories.tsx +0 -218
  64. package/src/components/uis/Button/Button.test.tsx +0 -694
  65. package/src/components/uis/Button/Button.tsx +0 -440
  66. package/src/components/uis/Card/Card.test.tsx +0 -146
  67. package/src/components/uis/Card/Card.tsx +0 -102
  68. package/src/components/uis/Checkbox/Checkbox.stories.tsx +0 -216
  69. package/src/components/uis/Checkbox/Checkbox.test.tsx +0 -267
  70. package/src/components/uis/Checkbox/Checkbox.tsx +0 -225
  71. package/src/components/uis/CustomPressable/CustomPressable.tsx +0 -48
  72. package/src/components/uis/EditText/EditText.stories.tsx +0 -124
  73. package/src/components/uis/EditText/EditText.test.tsx +0 -477
  74. package/src/components/uis/EditText/EditText.tsx +0 -593
  75. package/src/components/uis/Fab/Fab.stories.tsx +0 -133
  76. package/src/components/uis/Fab/Fab.test.tsx +0 -110
  77. package/src/components/uis/Fab/Fab.tsx +0 -168
  78. package/src/components/uis/Hr/Hr.test.tsx +0 -26
  79. package/src/components/uis/Hr/Hr.tsx +0 -19
  80. package/src/components/uis/Icon/Icon.stories.tsx +0 -98
  81. package/src/components/uis/Icon/Icon.test.tsx +0 -49
  82. package/src/components/uis/Icon/Icon.tsx +0 -3819
  83. package/src/components/uis/IconButton/IconButton.test.tsx +0 -204
  84. package/src/components/uis/IconButton/IconButton.tsx +0 -279
  85. package/src/components/uis/LoadingIndicator/LoadingIndicator.tsx +0 -126
  86. package/src/components/uis/LoadingIndicator/LodingIndicator.stories.tsx +0 -81
  87. package/src/components/uis/PinchZoom/PinchZoom.stories.tsx +0 -266
  88. package/src/components/uis/PinchZoom/PinchZoom.test.tsx +0 -113
  89. package/src/components/uis/PinchZoom/PinchZoom.tsx +0 -424
  90. package/src/components/uis/RadioGroup/RadioButton.tsx +0 -193
  91. package/src/components/uis/RadioGroup/RadioGroup.stories.tsx +0 -188
  92. package/src/components/uis/RadioGroup/RadioGroup.test.tsx +0 -354
  93. package/src/components/uis/RadioGroup/RadioGroup.tsx +0 -109
  94. package/src/components/uis/Rating/Rating.test.tsx +0 -98
  95. package/src/components/uis/Rating/Rating.tsx +0 -200
  96. package/src/components/uis/SegmentedControl/SegmentedControl.stories.tsx +0 -546
  97. package/src/components/uis/SegmentedControl/SegmentedControl.test.tsx +0 -274
  98. package/src/components/uis/SegmentedControl/SegmentedControl.tsx +0 -232
  99. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.test.tsx +0 -41
  100. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.tsx +0 -26
  101. package/src/components/uis/Styled/StyledComponents.tsx +0 -217
  102. package/src/components/uis/SwitchToggle/SwitchToggle.stories.tsx +0 -75
  103. package/src/components/uis/SwitchToggle/SwitchToggle.test.tsx +0 -149
  104. package/src/components/uis/SwitchToggle/SwitchToggle.tsx +0 -309
  105. package/src/components/uis/Typography/Typography.stories.tsx +0 -149
  106. package/src/components/uis/Typography/Typography.test.tsx +0 -58
  107. package/src/components/uis/Typography/Typography.tsx +0 -386
  108. package/src/hooks/index.ts +0 -2
  109. package/src/hooks/useAnimations.ts +0 -71
  110. package/src/hooks/useDebouncedColorScheme.tsx +0 -30
  111. package/src/hooks/useOptimizedStyles.ts +0 -22
  112. package/src/hooks/usePerformance.ts +0 -93
  113. package/src/index.tsx +0 -38
  114. package/src/providers/ThemeProvider.tsx +0 -177
  115. package/src/providers/index.tsx +0 -130
  116. package/src/test/testUtils.tsx +0 -101
  117. package/src/types/common.ts +0 -77
  118. package/src/types/index.ts +0 -1
  119. package/src/types/kstyled.d.ts +0 -6
  120. package/src/utils/accessibility.ts +0 -110
  121. package/src/utils/colors.ts +0 -151
  122. package/src/utils/createCtx.tsx +0 -26
  123. package/src/utils/guards.ts +0 -93
  124. package/src/utils/index.ts +0 -2
  125. package/src/utils/performanceTest.ts +0 -174
  126. package/src/utils/platform.ts +0 -69
  127. package/src/utils/theme.ts +0 -38
  128. package/test/testUtils.d.ts +0 -113
  129. package/test/testUtils.d.ts.map +0 -1
  130. package/test/testUtils.js +0 -65
@@ -1,694 +0,0 @@
1
- import '@testing-library/jest-native/extend-expect';
2
-
3
- import React, {type ReactElement} from 'react';
4
- import {Text} from 'react-native';
5
- import {css} from 'kstyled';
6
- import type {RenderAPI} from '@testing-library/react-native';
7
- import {fireEvent, render} from '@testing-library/react-native';
8
-
9
- import {createComponent} from '../../../../test/testUtils';
10
- import {Button} from './Button';
11
- import {LoadingIndicator} from '../LoadingIndicator/LoadingIndicator';
12
- import type {Props as ButtonProps} from './Button';
13
- import {ThemeType, ThemeProvider} from '../../../providers/ThemeProvider';
14
- import {dark, light} from '../../../utils/colors';
15
-
16
- let testingLib: RenderAPI;
17
-
18
- jest.mock('react-native-web-hooks', () => ({
19
- useHover: () => true,
20
- }));
21
-
22
- const Component = ({
23
- props,
24
- themeType,
25
- }: {
26
- props?: ButtonProps;
27
- themeType?: ThemeType;
28
- }): ReactElement =>
29
- createComponent(<Button onPress={jest.fn} {...props} />, themeType);
30
-
31
- describe('[Button]', () => {
32
- it('should render without crashing', () => {
33
- testingLib = render(Component({}));
34
-
35
- const json = testingLib.toJSON();
36
- expect(json).toBeTruthy();
37
- });
38
-
39
- describe('Index', () => {
40
- it('should render loading status', () => {
41
- testingLib = render(Component({props: {loading: true}}));
42
-
43
- expect(LoadingIndicator).toBeDefined();
44
- expect(testingLib.getByTestId('loading-view')).toBeTruthy();
45
- });
46
-
47
- it('should render default disabled style when disabled', () => {
48
- testingLib = render(Component({props: {disabled: true}}));
49
-
50
- const loadingView = testingLib.getByTestId('button-container');
51
- expect(loadingView).toHaveStyle({borderTopColor: light.text.disabled});
52
- });
53
- });
54
-
55
- describe('Disabled', () => {
56
- it('should render disabled status', () => {
57
- testingLib = render(Component({props: {disabled: true}}));
58
-
59
- const json = testingLib.toJSON();
60
- expect(json).toBeTruthy();
61
- });
62
-
63
- it('should render disabled status with disabled style', () => {
64
- testingLib = render(
65
- Component({
66
- props: {
67
- disabled: true,
68
- styles: {
69
- disabled: css`
70
- background-color: yellow;
71
- `,
72
- },
73
- },
74
- }),
75
- );
76
-
77
- const button = testingLib.getByTestId('button-container');
78
- expect(button).toHaveStyle({backgroundColor: 'yellow'});
79
- });
80
-
81
- it('should render container', () => {
82
- testingLib = render(
83
- Component({
84
- props: {
85
- styles: {
86
- container: css`
87
- background-color: blue;
88
- `,
89
- },
90
- },
91
- }),
92
- );
93
-
94
- const button = testingLib.getByTestId('button-container');
95
- expect(button).toHaveStyle({backgroundColor: 'blue'});
96
- });
97
- });
98
-
99
- describe('TextButton', () => {
100
- it('renders text button', () => {
101
- testingLib = render(
102
- Component({
103
- props: {
104
- testID: 'text-button',
105
- type: 'text',
106
- },
107
- }),
108
- );
109
-
110
- const json = testingLib.toJSON();
111
- expect(json).toBeTruthy();
112
- });
113
- });
114
-
115
- it('should render start and end elements', () => {
116
- testingLib = render(
117
- Component({props: {startElement: <Text />, endElement: <Text />}}),
118
- );
119
-
120
- const button = testingLib.getByTestId('button-container');
121
-
122
- // @ts-ignore
123
- expect(button.findAllByType(Text)).toHaveLength(3);
124
- });
125
-
126
- describe('[Button] Interaction', () => {
127
- let cnt = 1;
128
-
129
- it('should simulate onPress', () => {
130
- testingLib = render(
131
- Component({
132
- props: {
133
- onPress: () => cnt++,
134
- },
135
- }),
136
- );
137
-
138
- const button = testingLib.getByTestId('button-container');
139
-
140
- fireEvent.press(button);
141
-
142
- expect(cnt).toBe(2);
143
- });
144
- });
145
-
146
- describe('[Button] color', () => {
147
- it('should renders primary color', () => {
148
- testingLib = render(Component({props: {color: 'primary'}}));
149
-
150
- const button = testingLib.getByTestId('button-container');
151
- expect(button).toHaveStyle({backgroundColor: light.button.primary.bg});
152
- });
153
-
154
- it('should renders secondary color', () => {
155
- testingLib = render(Component({props: {color: 'secondary'}}));
156
-
157
- const button = testingLib.getByTestId('button-container');
158
- expect(button).toHaveStyle({
159
- backgroundColor: light.button.secondary.bg,
160
- });
161
- });
162
-
163
- it('should renders success color', () => {
164
- testingLib = render(Component({props: {color: 'success'}}));
165
-
166
- const button = testingLib.getByTestId('button-container');
167
- expect(button).toHaveStyle({backgroundColor: light.button.success.bg});
168
- });
169
-
170
- it('should renders warning color', () => {
171
- testingLib = render(Component({props: {color: 'warning'}}));
172
-
173
- const button = testingLib.getByTestId('button-container');
174
- expect(button).toHaveStyle({backgroundColor: light.button.warning.bg});
175
- });
176
-
177
- it('renders danger color', () => {
178
- testingLib = render(Component({props: {color: 'danger'}}));
179
-
180
- const button = testingLib.getByTestId('button-container');
181
- expect(button).toHaveStyle({backgroundColor: light.button.danger.bg});
182
- });
183
-
184
- it('should renders info color', () => {
185
- testingLib = render(Component({props: {color: 'info'}}));
186
-
187
- const button = testingLib.getByTestId('button-container');
188
- expect(button).toHaveStyle({backgroundColor: light.button.info.bg});
189
- });
190
-
191
- it('should renders light color', () => {
192
- testingLib = render(Component({props: {color: 'light'}}));
193
-
194
- const button = testingLib.getByTestId('button-container');
195
- expect(button).toHaveStyle({backgroundColor: light.button.light.bg});
196
- });
197
- });
198
-
199
- describe('[Button] - dark mode', () => {
200
- it('should render button', () => {
201
- testingLib = render(Component({themeType: 'dark'}));
202
-
203
- const button = testingLib.getByTestId('button-container');
204
- expect(button).toHaveStyle({backgroundColor: dark.button.primary.bg});
205
- });
206
-
207
- it('should renders danger color', () => {
208
- testingLib = render(
209
- Component({
210
- props: {
211
- text: 'my-button',
212
- color: 'danger',
213
- },
214
- themeType: 'dark',
215
- }),
216
- );
217
-
218
- const button = testingLib.getByTestId('button-container');
219
- expect(button).toHaveStyle({backgroundColor: dark.button.danger.bg});
220
- });
221
- });
222
-
223
- describe('[Button] outlined', () => {
224
- it('should render [type=outlined] button', () => {
225
- testingLib = render(
226
- Component({
227
- props: {type: 'outlined'},
228
- }),
229
- );
230
-
231
- const button = testingLib.getByTestId('button-container');
232
- expect(button).toHaveStyle({backgroundColor: light.bg.basic});
233
- });
234
-
235
- it('should render [type=outlined] button with [color=primary]', () => {
236
- testingLib = render(
237
- Component({
238
- props: {
239
- type: 'outlined',
240
- color: 'primary',
241
- },
242
- }),
243
- );
244
-
245
- const button = testingLib.getByTestId('button-container');
246
- expect(button).toHaveStyle({
247
- backgroundColor: light.bg.basic,
248
- borderBottomColor: light.button.primary.bg,
249
- });
250
- });
251
-
252
- it('should render [type=outlined] button with [color=secondary]', () => {
253
- testingLib = render(
254
- Component({
255
- props: {
256
- type: 'outlined',
257
- color: 'secondary',
258
- },
259
- }),
260
- );
261
-
262
- const button = testingLib.getByTestId('button-container');
263
- expect(button).toHaveStyle({
264
- backgroundColor: light.bg.basic,
265
- borderBottomColor: light.button.secondary.bg,
266
- });
267
- });
268
-
269
- it('should render [type=outlined] button with [color=success]', () => {
270
- testingLib = render(
271
- Component({
272
- props: {
273
- type: 'outlined',
274
- color: 'success',
275
- },
276
- }),
277
- );
278
-
279
- const button = testingLib.getByTestId('button-container');
280
-
281
- expect(button).toHaveStyle({
282
- backgroundColor: light.bg.basic,
283
- borderBottomColor: light.button.success.bg,
284
- });
285
- });
286
-
287
- it('should render [type=outlined] button with [color=warning]', () => {
288
- testingLib = render(
289
- Component({
290
- props: {
291
- type: 'outlined',
292
- color: 'warning',
293
- },
294
- }),
295
- );
296
-
297
- const button = testingLib.getByTestId('button-container');
298
-
299
-
300
- expect(button).toHaveStyle({
301
- backgroundColor: light.bg.basic,
302
- borderBottomColor: light.button.warning.bg,
303
- });
304
- });
305
-
306
- it('should render [type=outlined] button with [color=danger]', () => {
307
- testingLib = render(
308
- Component({
309
- props: {
310
- type: 'outlined',
311
- color: 'danger',
312
- },
313
- }),
314
- );
315
-
316
- const button = testingLib.getByTestId('button-container');
317
-
318
- expect(button).toHaveStyle({
319
- backgroundColor: light.bg.basic,
320
- borderBottomColor: light.button.danger.bg,
321
- });
322
- });
323
-
324
- it('should render [type=outlined] button with [color=info]', () => {
325
- testingLib = render(
326
- Component({
327
- props: {
328
- type: 'outlined',
329
- color: 'info',
330
- },
331
- }),
332
- );
333
-
334
- const button = testingLib.getByTestId('button-container');
335
-
336
- expect(button).toHaveStyle({
337
- backgroundColor: light.bg.basic,
338
- borderBottomColor: light.button.info.bg,
339
- });
340
- });
341
-
342
- it('should render [type=outlined] button with [color=light]', () => {
343
- testingLib = render(
344
- Component({
345
- props: {
346
- type: 'outlined',
347
- color: 'light',
348
- },
349
- }),
350
- );
351
-
352
- const button = testingLib.getByTestId('button-container');
353
-
354
- expect(button).toHaveStyle({
355
- backgroundColor: light.bg.basic,
356
- borderBottomColor: light.button.light.bg,
357
- });
358
- });
359
-
360
- it('should render [type=outlined] `disabled` button', () => {
361
- testingLib = render(
362
- Component({
363
- props: {
364
- type: 'outlined',
365
- disabled: true,
366
- text: 'my-button',
367
- },
368
- }),
369
- );
370
-
371
- const button = testingLib.getByTestId('button-container');
372
-
373
- const text = testingLib.getByText('my-button');
374
- expect(text).toHaveStyle({color: light.button.disabled.text});
375
- });
376
- });
377
-
378
- describe('Outlined - dark mode', () => {
379
- it('should render [type=outlined] [color=primary] button', () => {
380
- testingLib = render(
381
- Component({
382
- props: {
383
- type: 'outlined',
384
- color: 'primary',
385
- },
386
- themeType: 'dark',
387
- }),
388
- );
389
-
390
- const button = testingLib.getByTestId('button-container');
391
- expect(button).toHaveStyle({borderBottomColor: dark.button.primary.bg});
392
- });
393
-
394
- it('should render [type=outlined] [color=secondary] button', () => {
395
- testingLib = render(
396
- Component({
397
- props: {
398
- type: 'outlined',
399
- color: 'secondary',
400
- },
401
- themeType: 'dark',
402
- }),
403
- );
404
-
405
- const button = testingLib.getByTestId('button-container');
406
- expect(button).toHaveStyle({
407
- borderBottomColor: dark.button.secondary.bg,
408
- });
409
- });
410
-
411
- it('should render [type=outlined] [color=success] button', () => {
412
- testingLib = render(
413
- Component({
414
- props: {
415
- type: 'outlined',
416
- color: 'success',
417
- },
418
- themeType: 'dark',
419
- }),
420
- );
421
-
422
- const button = testingLib.getByTestId('button-container');
423
- expect(button).toHaveStyle({borderBottomColor: dark.button.success.bg});
424
- });
425
-
426
- it('should render [type=outlined] [color=warning] button', () => {
427
- testingLib = render(
428
- Component({
429
- props: {
430
- type: 'outlined',
431
- color: 'warning',
432
- },
433
- themeType: 'dark',
434
- }),
435
- );
436
-
437
- const button = testingLib.getByTestId('button-container');
438
- expect(button).toHaveStyle({borderBottomColor: dark.button.warning.bg});
439
- });
440
-
441
- it('should render [type=outlined] [color=danger] button', () => {
442
- testingLib = render(
443
- Component({
444
- props: {
445
- type: 'outlined',
446
- color: 'danger',
447
- },
448
- themeType: 'dark',
449
- }),
450
- );
451
-
452
- const button = testingLib.getByTestId('button-container');
453
- expect(button).toHaveStyle({borderBottomColor: dark.button.danger.bg});
454
- });
455
-
456
- it('should [type=outlined] [color=light] button', () => {
457
- testingLib = render(
458
- Component({
459
- props: {
460
- type: 'outlined',
461
- color: 'light',
462
- },
463
- themeType: 'dark',
464
- }),
465
- );
466
-
467
- const button = testingLib.getByTestId('button-container');
468
- expect(button).toHaveStyle({borderBottomColor: dark.button.light.bg});
469
- });
470
-
471
- it('should render [type=outlined] [color=info] button', () => {
472
- testingLib = render(
473
- Component({
474
- props: {
475
- type: 'outlined',
476
- color: 'info',
477
- },
478
- themeType: 'dark',
479
- }),
480
- );
481
-
482
- const button = testingLib.getByTestId('button-container');
483
- expect(button).toHaveStyle({borderBottomColor: dark.button.info.bg});
484
- });
485
-
486
- it('should render [type=outlined] `disabled` button', () => {
487
- testingLib = render(
488
- Component({
489
- props: {
490
- type: 'outlined',
491
- disabled: true,
492
- text: 'my-button',
493
- },
494
- themeType: 'dark',
495
- }),
496
- );
497
-
498
- const button = testingLib.getByTestId('button-container');
499
-
500
- const text = testingLib.getByText('my-button');
501
- expect(text).toHaveStyle({color: dark.button.disabled.text});
502
- });
503
- });
504
-
505
- describe('[Button] sizes', () => {
506
- it('should render [large] button', () => {
507
- testingLib = render(
508
- Component({
509
- props: {size: 'large'},
510
- }),
511
- );
512
-
513
- const button = testingLib.getByTestId('button-container');
514
- });
515
-
516
- it('should render [small] button', () => {
517
- testingLib = render(
518
- Component({
519
- props: {
520
- size: 'small',
521
- color: 'danger',
522
- },
523
- themeType: 'dark',
524
- }),
525
- );
526
-
527
- const button = testingLib.getByTestId('button-container');
528
- });
529
- });
530
-
531
- describe('[Button] borderRadius', () => {
532
- it('should render with given borderRadius', () => {
533
- const borderRadius = 10;
534
-
535
- testingLib = render(
536
- Component({
537
- props: {
538
- borderRadius: borderRadius,
539
- },
540
- }),
541
- );
542
-
543
- const button = testingLib.getByTestId('button-container');
544
- expect(button).toHaveStyle({borderRadius: borderRadius});
545
- });
546
- });
547
-
548
- describe('[Button] accessibility', () => {
549
- it('should have accessibilityRole="button"', () => {
550
- testingLib = render(
551
- Component({
552
- props: {
553
- testID: 'a11y-button',
554
- text: 'Click me',
555
- },
556
- }),
557
- );
558
-
559
- const button = testingLib.getByTestId('a11y-button');
560
- expect(button.props.accessibilityRole).toBe('button');
561
- });
562
-
563
- it('should use text as default accessibilityLabel', () => {
564
- testingLib = render(
565
- Component({
566
- props: {
567
- testID: 'a11y-button',
568
- text: 'Submit',
569
- },
570
- }),
571
- );
572
-
573
- const button = testingLib.getByTestId('a11y-button');
574
- expect(button.props.accessibilityLabel).toBe('Submit');
575
- });
576
-
577
- it('should use custom accessibilityLabel when provided', () => {
578
- testingLib = render(
579
- Component({
580
- props: {
581
- testID: 'a11y-button',
582
- text: 'Submit',
583
- accessibilityLabel: 'Submit form',
584
- },
585
- }),
586
- );
587
-
588
- const button = testingLib.getByTestId('a11y-button');
589
- expect(button.props.accessibilityLabel).toBe('Submit form');
590
- });
591
-
592
- it('should have undefined accessibilityLabel when text is ReactElement', () => {
593
- testingLib = render(
594
- Component({
595
- props: {
596
- testID: 'a11y-button',
597
- text: <Text>Custom</Text>,
598
- },
599
- }),
600
- );
601
-
602
- const button = testingLib.getByTestId('a11y-button');
603
- expect(button.props.accessibilityLabel).toBeUndefined();
604
- });
605
-
606
- it('should allow custom accessibilityLabel with ReactElement text', () => {
607
- testingLib = render(
608
- Component({
609
- props: {
610
- testID: 'a11y-button',
611
- text: <Text>Custom</Text>,
612
- accessibilityLabel: 'Custom button',
613
- },
614
- }),
615
- );
616
-
617
- const button = testingLib.getByTestId('a11y-button');
618
- expect(button.props.accessibilityLabel).toBe('Custom button');
619
- });
620
- });
621
-
622
- describe('[Button] custom theme', () => {
623
- it('should render with custom primary color from theme', () => {
624
- const customTheme = {
625
- light: {
626
- button: {
627
- primary: {
628
- bg: '#FF5733',
629
- text: '#FFFFFF',
630
- },
631
- },
632
- },
633
- };
634
-
635
- testingLib = render(
636
- <ThemeProvider customTheme={customTheme}>
637
- <Button color="primary" onPress={jest.fn} testID="custom-button" />
638
- </ThemeProvider>,
639
- );
640
-
641
- const button = testingLib.getByTestId('button-container');
642
- expect(button).toHaveStyle({backgroundColor: '#FF5733'});
643
- });
644
-
645
- it('should render with custom primary color in dark mode', () => {
646
- const customTheme = {
647
- dark: {
648
- button: {
649
- primary: {
650
- bg: '#00BFFF',
651
- text: '#000000',
652
- },
653
- },
654
- },
655
- };
656
-
657
- testingLib = render(
658
- <ThemeProvider initialThemeType="dark" customTheme={customTheme}>
659
- <Button color="primary" onPress={jest.fn} testID="custom-button" />
660
- </ThemeProvider>,
661
- );
662
-
663
- const button = testingLib.getByTestId('button-container');
664
- expect(button).toHaveStyle({backgroundColor: '#00BFFF'});
665
- });
666
-
667
- it('should render outlined button with custom primary color', () => {
668
- const customTheme = {
669
- light: {
670
- button: {
671
- primary: {
672
- bg: '#9C27B0',
673
- text: '#FFFFFF',
674
- },
675
- },
676
- },
677
- };
678
-
679
- testingLib = render(
680
- <ThemeProvider customTheme={customTheme}>
681
- <Button
682
- type="outlined"
683
- color="primary"
684
- onPress={jest.fn}
685
- testID="custom-button"
686
- />
687
- </ThemeProvider>,
688
- );
689
-
690
- const button = testingLib.getByTestId('button-container');
691
- expect(button).toHaveStyle({borderBottomColor: '#9C27B0'});
692
- });
693
- });
694
- });