@jasperoosthoek/react-toolbox 0.8.0 → 0.9.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 (63) hide show
  1. package/change-log.md +330 -309
  2. package/dist/components/buttons/ConfirmButton.d.ts +2 -2
  3. package/dist/components/buttons/DeleteConfirmButton.d.ts +2 -2
  4. package/dist/components/buttons/IconButtons.d.ts +40 -41
  5. package/dist/components/errors/Errors.d.ts +1 -2
  6. package/dist/components/forms/FormField.d.ts +22 -0
  7. package/dist/components/forms/FormFields.d.ts +1 -56
  8. package/dist/components/forms/FormModal.d.ts +7 -34
  9. package/dist/components/forms/FormModalProvider.d.ts +19 -26
  10. package/dist/components/forms/FormProvider.d.ts +66 -0
  11. package/dist/components/forms/fields/FormBadgesSelection.d.ts +26 -0
  12. package/dist/components/forms/fields/FormCheckbox.d.ts +7 -0
  13. package/dist/components/forms/fields/FormDropdown.d.ts +19 -0
  14. package/dist/components/forms/fields/FormInput.d.ts +17 -0
  15. package/dist/components/forms/fields/FormSelect.d.ts +12 -0
  16. package/dist/components/forms/fields/index.d.ts +5 -0
  17. package/dist/components/indicators/CheckIndicator.d.ts +1 -2
  18. package/dist/components/indicators/LoadingIndicator.d.ts +4 -4
  19. package/dist/components/login/LoginPage.d.ts +1 -1
  20. package/dist/components/tables/DataTable.d.ts +2 -2
  21. package/dist/components/tables/DragAndDropList.d.ts +2 -2
  22. package/dist/components/tables/SearchBox.d.ts +2 -2
  23. package/dist/index.d.ts +4 -1
  24. package/dist/index.js +2 -2
  25. package/dist/index.js.LICENSE.txt +0 -4
  26. package/dist/localization/LocalizationContext.d.ts +1 -1
  27. package/dist/utils/hooks.d.ts +1 -1
  28. package/dist/utils/timeAndDate.d.ts +5 -2
  29. package/dist/utils/utils.d.ts +3 -3
  30. package/package.json +10 -11
  31. package/src/__tests__/buttons.test.tsx +545 -0
  32. package/src/__tests__/errors.test.tsx +339 -0
  33. package/src/__tests__/forms.test.tsx +3021 -0
  34. package/src/__tests__/hooks.test.tsx +413 -0
  35. package/src/__tests__/indicators.test.tsx +284 -0
  36. package/src/__tests__/localization.test.tsx +462 -0
  37. package/src/__tests__/login.test.tsx +417 -0
  38. package/src/__tests__/setupTests.ts +328 -0
  39. package/src/__tests__/tables.test.tsx +609 -0
  40. package/src/__tests__/timeAndDate.test.tsx +308 -0
  41. package/src/__tests__/utils.test.tsx +422 -0
  42. package/src/components/forms/FormField.tsx +92 -0
  43. package/src/components/forms/FormFields.tsx +3 -423
  44. package/src/components/forms/FormModal.tsx +168 -243
  45. package/src/components/forms/FormModalProvider.tsx +141 -95
  46. package/src/components/forms/FormProvider.tsx +218 -0
  47. package/src/components/forms/fields/FormBadgesSelection.tsx +108 -0
  48. package/src/components/forms/fields/FormCheckbox.tsx +76 -0
  49. package/src/components/forms/fields/FormDropdown.tsx +123 -0
  50. package/src/components/forms/fields/FormInput.tsx +114 -0
  51. package/src/components/forms/fields/FormSelect.tsx +47 -0
  52. package/src/components/forms/fields/index.ts +6 -0
  53. package/src/index.ts +32 -28
  54. package/src/localization/LocalizationContext.tsx +156 -131
  55. package/src/localization/localization.ts +131 -131
  56. package/src/utils/hooks.ts +108 -94
  57. package/src/utils/timeAndDate.ts +33 -4
  58. package/src/utils/utils.ts +74 -66
  59. package/dist/components/forms/CreateEditModal.d.ts +0 -41
  60. package/dist/components/forms/CreateEditModalProvider.d.ts +0 -41
  61. package/dist/components/forms/FormFields.test.d.ts +0 -4
  62. package/dist/login/Login.d.ts +0 -70
  63. package/src/components/forms/FormFields.test.tsx +0 -107
@@ -0,0 +1,417 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { LocalizationProvider } from '../localization/LocalizationContext';
4
+ import { LoginPage } from '../components/login/LoginPage';
5
+
6
+ // Test wrapper with localization context
7
+ const TestWrapper = ({ children }: { children: React.ReactNode }) => (
8
+ <LocalizationProvider>
9
+ {children}
10
+ </LocalizationProvider>
11
+ );
12
+
13
+ describe('Login Components Tests', () => {
14
+ describe('LoginPage', () => {
15
+ const mockOnSubmit = jest.fn();
16
+ const mockCallback = jest.fn();
17
+ const mockOnResetPassword = jest.fn();
18
+
19
+ afterEach(() => {
20
+ jest.clearAllMocks();
21
+ });
22
+
23
+ it('should be a valid React component', () => {
24
+ expect(typeof LoginPage).toBe('function');
25
+ });
26
+
27
+ it('should render without crashing when not authenticated', () => {
28
+ expect(() => {
29
+ render(
30
+ <TestWrapper>
31
+ <LoginPage
32
+ onSubmit={mockOnSubmit}
33
+ isAuthenticated={false}
34
+ onResetPassword="#reset"
35
+ />
36
+ </TestWrapper>
37
+ );
38
+ }).not.toThrow();
39
+ });
40
+
41
+ it('should not render when authenticated', () => {
42
+ const { container } = render(
43
+ <TestWrapper>
44
+ <LoginPage
45
+ onSubmit={mockOnSubmit}
46
+ isAuthenticated={true}
47
+ onResetPassword="#reset"
48
+ />
49
+ </TestWrapper>
50
+ );
51
+
52
+ expect(container.firstChild).toBeNull();
53
+ });
54
+
55
+ it('should handle string reset password prop', () => {
56
+ expect(() => {
57
+ render(
58
+ <TestWrapper>
59
+ <LoginPage
60
+ onSubmit={mockOnSubmit}
61
+ isAuthenticated={false}
62
+ onResetPassword="https://example.com/reset"
63
+ />
64
+ </TestWrapper>
65
+ );
66
+ }).not.toThrow();
67
+ });
68
+
69
+ it('should handle function reset password prop', () => {
70
+ expect(() => {
71
+ render(
72
+ <TestWrapper>
73
+ <LoginPage
74
+ onSubmit={mockOnSubmit}
75
+ isAuthenticated={false}
76
+ onResetPassword={mockOnResetPassword}
77
+ />
78
+ </TestWrapper>
79
+ );
80
+ }).not.toThrow();
81
+ });
82
+
83
+ it('should handle string label prop', () => {
84
+ expect(() => {
85
+ render(
86
+ <TestWrapper>
87
+ <LoginPage
88
+ onSubmit={mockOnSubmit}
89
+ isAuthenticated={false}
90
+ onResetPassword="#reset"
91
+ label="Custom Login Title"
92
+ />
93
+ </TestWrapper>
94
+ );
95
+ }).not.toThrow();
96
+ });
97
+
98
+ it('should handle ReactElement label prop', () => {
99
+ const customLabel = <h2>Custom Login Component</h2>;
100
+
101
+ expect(() => {
102
+ render(
103
+ <TestWrapper>
104
+ <LoginPage
105
+ onSubmit={mockOnSubmit}
106
+ isAuthenticated={false}
107
+ onResetPassword="#reset"
108
+ label={customLabel}
109
+ />
110
+ </TestWrapper>
111
+ );
112
+ }).not.toThrow();
113
+ });
114
+
115
+ it('should handle callback prop', () => {
116
+ expect(() => {
117
+ render(
118
+ <TestWrapper>
119
+ <LoginPage
120
+ onSubmit={mockOnSubmit}
121
+ isAuthenticated={false}
122
+ onResetPassword="#reset"
123
+ callback={mockCallback}
124
+ />
125
+ </TestWrapper>
126
+ );
127
+ }).not.toThrow();
128
+ });
129
+
130
+ it('should handle all props together', () => {
131
+ const customLabel = <h1 className="title">Welcome</h1>;
132
+
133
+ expect(() => {
134
+ render(
135
+ <TestWrapper>
136
+ <LoginPage
137
+ onSubmit={mockOnSubmit}
138
+ isAuthenticated={false}
139
+ onResetPassword={mockOnResetPassword}
140
+ label={customLabel}
141
+ callback={mockCallback}
142
+ />
143
+ </TestWrapper>
144
+ );
145
+ }).not.toThrow();
146
+ });
147
+ });
148
+
149
+ describe('LoginPage Authentication Logic', () => {
150
+ const mockOnSubmit = jest.fn();
151
+
152
+ it('should render content when not authenticated', () => {
153
+ const { container } = render(
154
+ <TestWrapper>
155
+ <LoginPage
156
+ onSubmit={mockOnSubmit}
157
+ isAuthenticated={false}
158
+ onResetPassword="#reset"
159
+ />
160
+ </TestWrapper>
161
+ );
162
+
163
+ expect(container.firstChild).not.toBeNull();
164
+ });
165
+
166
+ it('should not render anything when authenticated', () => {
167
+ const { container } = render(
168
+ <TestWrapper>
169
+ <LoginPage
170
+ onSubmit={mockOnSubmit}
171
+ isAuthenticated={true}
172
+ onResetPassword="#reset"
173
+ />
174
+ </TestWrapper>
175
+ );
176
+
177
+ expect(container.firstChild).toBeNull();
178
+ });
179
+
180
+ it('should handle authentication state changes', () => {
181
+ const { container, rerender } = render(
182
+ <TestWrapper>
183
+ <LoginPage
184
+ onSubmit={mockOnSubmit}
185
+ isAuthenticated={false}
186
+ onResetPassword="#reset"
187
+ />
188
+ </TestWrapper>
189
+ );
190
+
191
+ expect(container.firstChild).not.toBeNull();
192
+
193
+ rerender(
194
+ <TestWrapper>
195
+ <LoginPage
196
+ onSubmit={mockOnSubmit}
197
+ isAuthenticated={true}
198
+ onResetPassword="#reset"
199
+ />
200
+ </TestWrapper>
201
+ );
202
+
203
+ expect(container.firstChild).toBeNull();
204
+ });
205
+ });
206
+
207
+ describe('LoginPage Props Validation', () => {
208
+ const mockOnSubmit = jest.fn();
209
+
210
+ it('should handle required props', () => {
211
+ expect(() => {
212
+ render(
213
+ <TestWrapper>
214
+ <LoginPage
215
+ onSubmit={mockOnSubmit}
216
+ isAuthenticated={false}
217
+ onResetPassword="#reset"
218
+ />
219
+ </TestWrapper>
220
+ );
221
+ }).not.toThrow();
222
+ });
223
+
224
+ it('should handle optional props', () => {
225
+ expect(() => {
226
+ render(
227
+ <TestWrapper>
228
+ <LoginPage
229
+ onSubmit={mockOnSubmit}
230
+ isAuthenticated={false}
231
+ onResetPassword={jest.fn()}
232
+ label="Optional Label"
233
+ callback={jest.fn()}
234
+ />
235
+ </TestWrapper>
236
+ );
237
+ }).not.toThrow();
238
+ });
239
+
240
+ it('should handle various prop combinations', () => {
241
+ const propCombinations = [
242
+ {
243
+ onSubmit: mockOnSubmit,
244
+ isAuthenticated: false,
245
+ onResetPassword: '#reset',
246
+ },
247
+ {
248
+ onSubmit: mockOnSubmit,
249
+ isAuthenticated: true,
250
+ onResetPassword: jest.fn(),
251
+ },
252
+ {
253
+ onSubmit: mockOnSubmit,
254
+ isAuthenticated: false,
255
+ onResetPassword: '#reset',
256
+ label: 'Custom Label',
257
+ callback: jest.fn(),
258
+ },
259
+ {
260
+ onSubmit: mockOnSubmit,
261
+ isAuthenticated: false,
262
+ onResetPassword: jest.fn(),
263
+ label: <div>JSX Label</div>,
264
+ },
265
+ ];
266
+
267
+ propCombinations.forEach((props) => {
268
+ expect(() => {
269
+ render(
270
+ <TestWrapper>
271
+ <LoginPage {...props} />
272
+ </TestWrapper>
273
+ );
274
+ }).not.toThrow();
275
+ });
276
+ });
277
+ });
278
+
279
+ describe('LoginPage Component Behavior', () => {
280
+ const mockOnSubmit = jest.fn();
281
+ const mockOnResetPassword = jest.fn();
282
+
283
+ afterEach(() => {
284
+ jest.clearAllMocks();
285
+ });
286
+
287
+ it('should handle various reset password types', () => {
288
+ // Test with string URL
289
+ expect(() => {
290
+ render(
291
+ <TestWrapper>
292
+ <LoginPage
293
+ onSubmit={mockOnSubmit}
294
+ isAuthenticated={false}
295
+ onResetPassword="https://example.com/reset"
296
+ />
297
+ </TestWrapper>
298
+ );
299
+ }).not.toThrow();
300
+
301
+ // Test with function callback
302
+ expect(() => {
303
+ render(
304
+ <TestWrapper>
305
+ <LoginPage
306
+ onSubmit={mockOnSubmit}
307
+ isAuthenticated={false}
308
+ onResetPassword={mockOnResetPassword}
309
+ />
310
+ </TestWrapper>
311
+ );
312
+ }).not.toThrow();
313
+ });
314
+
315
+ it('should handle label variations', () => {
316
+ // Test without label
317
+ expect(() => {
318
+ render(
319
+ <TestWrapper>
320
+ <LoginPage
321
+ onSubmit={mockOnSubmit}
322
+ isAuthenticated={false}
323
+ onResetPassword="#reset"
324
+ />
325
+ </TestWrapper>
326
+ );
327
+ }).not.toThrow();
328
+
329
+ // Test with string label
330
+ expect(() => {
331
+ render(
332
+ <TestWrapper>
333
+ <LoginPage
334
+ onSubmit={mockOnSubmit}
335
+ isAuthenticated={false}
336
+ onResetPassword="#reset"
337
+ label="Login Here"
338
+ />
339
+ </TestWrapper>
340
+ );
341
+ }).not.toThrow();
342
+
343
+ // Test with React element label
344
+ expect(() => {
345
+ render(
346
+ <TestWrapper>
347
+ <LoginPage
348
+ onSubmit={mockOnSubmit}
349
+ isAuthenticated={false}
350
+ onResetPassword="#reset"
351
+ label={<h1 className="login-title">Welcome</h1>}
352
+ />
353
+ </TestWrapper>
354
+ );
355
+ }).not.toThrow();
356
+ });
357
+
358
+ it('should handle optional callback prop', () => {
359
+ const mockCallback = jest.fn();
360
+
361
+ expect(() => {
362
+ render(
363
+ <TestWrapper>
364
+ <LoginPage
365
+ onSubmit={mockOnSubmit}
366
+ isAuthenticated={false}
367
+ onResetPassword="#reset"
368
+ callback={mockCallback}
369
+ />
370
+ </TestWrapper>
371
+ );
372
+ }).not.toThrow();
373
+ });
374
+ });
375
+
376
+ describe('Component Export Verification', () => {
377
+ it('should export LoginPage as a function', () => {
378
+ expect(typeof LoginPage).toBe('function');
379
+ });
380
+
381
+ it('should have the correct function signature', () => {
382
+ expect(LoginPage.length).toBe(1); // Should accept one parameter (props)
383
+ });
384
+ });
385
+
386
+ describe('LoginPage Rendering Logic', () => {
387
+ const mockOnSubmit = jest.fn();
388
+
389
+ it('should handle authenticated state properly', () => {
390
+ const { container } = render(
391
+ <TestWrapper>
392
+ <LoginPage
393
+ onSubmit={mockOnSubmit}
394
+ isAuthenticated={true}
395
+ onResetPassword="#reset"
396
+ />
397
+ </TestWrapper>
398
+ );
399
+
400
+ expect(container.firstChild).toBeNull();
401
+ });
402
+
403
+ it('should handle unauthenticated state properly', () => {
404
+ const { container } = render(
405
+ <TestWrapper>
406
+ <LoginPage
407
+ onSubmit={mockOnSubmit}
408
+ isAuthenticated={false}
409
+ onResetPassword="#reset"
410
+ />
411
+ </TestWrapper>
412
+ );
413
+
414
+ expect(container.firstChild).toBeTruthy();
415
+ });
416
+ });
417
+ });