@jasperoosthoek/react-toolbox 0.9.4 → 0.10.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 (38) hide show
  1. package/README.md +455 -155
  2. package/change-log.md +18 -1
  3. package/dist/components/forms/FormField.d.ts +13 -0
  4. package/dist/components/forms/FormModal.d.ts +3 -2
  5. package/dist/components/forms/FormProvider.d.ts +3 -0
  6. package/dist/components/forms/fields/FormInput.d.ts +1 -1
  7. package/dist/components/indicators/FixedLoadingIndicator.d.ts +16 -0
  8. package/dist/components/tables/DataTable.d.ts +2 -2
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.es.js +2235 -0
  11. package/dist/index.es.js.map +1 -0
  12. package/dist/index.umd.js +28 -0
  13. package/dist/index.umd.js.map +1 -0
  14. package/package.json +26 -12
  15. package/src/components/forms/FormField.tsx +6 -2
  16. package/src/components/forms/FormModal.tsx +38 -20
  17. package/src/components/forms/FormProvider.tsx +7 -1
  18. package/src/components/forms/fields/FormBadgesSelection.tsx +20 -9
  19. package/src/components/forms/fields/FormCheckbox.tsx +8 -10
  20. package/src/components/forms/fields/FormDropdown.tsx +4 -5
  21. package/src/components/forms/fields/FormInput.tsx +6 -6
  22. package/src/components/forms/fields/FormSelect.tsx +4 -3
  23. package/src/components/indicators/FixedLoadingIndicator.tsx +49 -0
  24. package/src/components/tables/DataTable.tsx +27 -30
  25. package/src/index.ts +1 -0
  26. package/dist/index.js +0 -3
  27. package/dist/index.js.LICENSE.txt +0 -15
  28. package/src/__tests__/buttons.test.tsx +0 -545
  29. package/src/__tests__/errors.test.tsx +0 -339
  30. package/src/__tests__/forms.test.tsx +0 -3021
  31. package/src/__tests__/hooks.test.tsx +0 -413
  32. package/src/__tests__/indicators.test.tsx +0 -284
  33. package/src/__tests__/localization.test.tsx +0 -462
  34. package/src/__tests__/login.test.tsx +0 -417
  35. package/src/__tests__/setupTests.ts +0 -328
  36. package/src/__tests__/tables.test.tsx +0 -609
  37. package/src/__tests__/timeAndDate.test.tsx +0 -308
  38. package/src/__tests__/utils.test.tsx +0 -422
@@ -1,339 +0,0 @@
1
- import React from 'react';
2
- import { render, act, fireEvent } from '@testing-library/react';
3
- import {
4
- ErrorBoundary,
5
- ErrorContext,
6
- useError,
7
- dispatchError
8
- } from '../components/errors/ErrorBoundary';
9
- import { ErrorPage } from '../components/errors/Errors';
10
-
11
- describe('Error Components Tests', () => {
12
- describe('ErrorBoundary', () => {
13
- it('should render ErrorBoundary without crashing', () => {
14
- expect(() => {
15
- render(
16
- <ErrorBoundary>
17
- <div>Test Content</div>
18
- </ErrorBoundary>
19
- );
20
- }).not.toThrow();
21
- });
22
-
23
- it('should render children when no error occurs', () => {
24
- const { getByText } = render(
25
- <ErrorBoundary>
26
- <div>Test Content</div>
27
- </ErrorBoundary>
28
- );
29
-
30
- expect(getByText('Test Content')).toBeInTheDocument();
31
- });
32
-
33
- it('should provide error context to children', () => {
34
- const TestComponent = () => {
35
- const { error, clearError } = useError();
36
- return (
37
- <div>
38
- <span>Error: {error ? 'Yes' : 'No'}</span>
39
- <button onClick={clearError}>Clear Error</button>
40
- </div>
41
- );
42
- };
43
-
44
- expect(() => {
45
- render(
46
- <ErrorBoundary>
47
- <TestComponent />
48
- </ErrorBoundary>
49
- );
50
- }).not.toThrow();
51
- });
52
-
53
- it('should handle custom error events', () => {
54
- const TestComponent = () => {
55
- const { error } = useError();
56
- return <div>Error State: {error ? 'Error' : 'No Error'}</div>;
57
- };
58
-
59
- const { getByText } = render(
60
- <ErrorBoundary>
61
- <TestComponent />
62
- </ErrorBoundary>
63
- );
64
-
65
- // Initially no error
66
- expect(getByText('Error State: No Error')).toBeInTheDocument();
67
-
68
- // Dispatch an error
69
- act(() => {
70
- dispatchError('Test error');
71
- });
72
-
73
- // Should show error state
74
- expect(getByText('Error State: Error')).toBeInTheDocument();
75
- });
76
-
77
- it('should clear errors when clearError is called', () => {
78
- const TestComponent = () => {
79
- const { error, clearError } = useError();
80
- return (
81
- <div>
82
- <span>Error State: {error ? 'Error' : 'No Error'}</span>
83
- <button onClick={clearError}>Clear</button>
84
- </div>
85
- );
86
- };
87
-
88
- const { getByText, getByRole } = render(
89
- <ErrorBoundary>
90
- <TestComponent />
91
- </ErrorBoundary>
92
- );
93
-
94
- // Dispatch an error
95
- act(() => {
96
- dispatchError('Test error');
97
- });
98
-
99
- expect(getByText('Error State: Error')).toBeInTheDocument();
100
-
101
- // Clear the error
102
- act(() => {
103
- fireEvent.click(getByRole('button'));
104
- });
105
-
106
- expect(getByText('Error State: No Error')).toBeInTheDocument();
107
- });
108
-
109
- it('should be a valid React component', () => {
110
- expect(typeof ErrorBoundary).toBe('function');
111
- });
112
- });
113
-
114
- describe('useError hook', () => {
115
- it('should provide error context when used within ErrorBoundary', () => {
116
- const TestComponent = () => {
117
- const { error, clearError } = useError();
118
- return (
119
- <div>
120
- <span data-testid="error-status">
121
- {error ? 'Has Error' : 'No Error'}
122
- </span>
123
- <button onClick={clearError} data-testid="clear-button">
124
- Clear
125
- </button>
126
- </div>
127
- );
128
- };
129
-
130
- expect(() => {
131
- render(
132
- <ErrorBoundary>
133
- <TestComponent />
134
- </ErrorBoundary>
135
- );
136
- }).not.toThrow();
137
- });
138
-
139
- it('should return error context functions', () => {
140
- let contextValue: any;
141
-
142
- const TestComponent = () => {
143
- contextValue = useError();
144
- return <div>Test</div>;
145
- };
146
-
147
- render(
148
- <ErrorBoundary>
149
- <TestComponent />
150
- </ErrorBoundary>
151
- );
152
-
153
- expect(contextValue).toBeDefined();
154
- expect(typeof contextValue.clearError).toBe('function');
155
- expect(contextValue.error).toBeDefined();
156
- });
157
- });
158
-
159
- describe('dispatchError function', () => {
160
- it('should be a valid function', () => {
161
- expect(typeof dispatchError).toBe('function');
162
- });
163
-
164
- it('should dispatch custom events without throwing', () => {
165
- expect(() => {
166
- dispatchError('Test error message');
167
- }).not.toThrow();
168
-
169
- expect(() => {
170
- dispatchError({ message: 'Test error object' });
171
- }).not.toThrow();
172
-
173
- expect(() => {
174
- dispatchError(null);
175
- }).not.toThrow();
176
- });
177
- });
178
-
179
- describe('ErrorContext', () => {
180
- it('should provide default error context', () => {
181
- expect(ErrorContext).toBeDefined();
182
- expect(ErrorContext.Provider).toBeDefined();
183
- expect(ErrorContext.Consumer).toBeDefined();
184
- });
185
- });
186
-
187
- describe('ErrorPage', () => {
188
- it('should render ErrorPage without crashing', () => {
189
- expect(() => {
190
- render(
191
- <ErrorPage>
192
- <div>Error Message</div>
193
- </ErrorPage>
194
- );
195
- }).not.toThrow();
196
- });
197
-
198
- it('should render children content', () => {
199
- const { getByText } = render(
200
- <ErrorPage>
201
- <h1>Something went wrong</h1>
202
- <p>Please try again later</p>
203
- </ErrorPage>
204
- );
205
-
206
- expect(getByText('Something went wrong')).toBeInTheDocument();
207
- expect(getByText('Please try again later')).toBeInTheDocument();
208
- });
209
-
210
- it('should handle different types of children', () => {
211
- expect(() => {
212
- render(
213
- <ErrorPage>
214
- <div>Text content</div>
215
- </ErrorPage>
216
- );
217
- }).not.toThrow();
218
-
219
- expect(() => {
220
- render(
221
- <ErrorPage>
222
- {['Multiple', 'text', 'elements']}
223
- </ErrorPage>
224
- );
225
- }).not.toThrow();
226
-
227
- expect(() => {
228
- render(
229
- <ErrorPage>
230
- <span>Single element</span>
231
- </ErrorPage>
232
- );
233
- }).not.toThrow();
234
- });
235
-
236
- it('should apply proper styling structure', () => {
237
- const { container } = render(
238
- <ErrorPage>
239
- <div>Content</div>
240
- </ErrorPage>
241
- );
242
-
243
- // Should have container structure
244
- expect(container.firstChild).toBeTruthy();
245
- });
246
-
247
- it('should be a valid React component', () => {
248
- expect(typeof ErrorPage).toBe('function');
249
- });
250
- });
251
-
252
- describe('Error Handling Integration', () => {
253
- it('should work together - ErrorBoundary with ErrorPage', () => {
254
- const TestErrorPage = () => {
255
- const { error } = useError();
256
-
257
- if (error) {
258
- return (
259
- <ErrorPage>
260
- <h2>An error occurred</h2>
261
- <p>{error.toString()}</p>
262
- </ErrorPage>
263
- );
264
- }
265
-
266
- return <div>Normal content</div>;
267
- };
268
-
269
- expect(() => {
270
- render(
271
- <ErrorBoundary>
272
- <TestErrorPage />
273
- </ErrorBoundary>
274
- );
275
- }).not.toThrow();
276
- });
277
-
278
- it('should handle error lifecycle correctly', () => {
279
- const TestComponent = () => {
280
- const { error, clearError } = useError();
281
-
282
- return (
283
- <div>
284
- {error ? (
285
- <ErrorPage>
286
- <div>
287
- <span>Error occurred: {error}</span>
288
- <button onClick={clearError}>Retry</button>
289
- </div>
290
- </ErrorPage>
291
- ) : (
292
- <div>
293
- <span>All good</span>
294
- <button onClick={() => dispatchError('Test error')}>
295
- Trigger Error
296
- </button>
297
- </div>
298
- )}
299
- </div>
300
- );
301
- };
302
-
303
- const { getByText, queryByText } = render(
304
- <ErrorBoundary>
305
- <TestComponent />
306
- </ErrorBoundary>
307
- );
308
-
309
- // Initially no error
310
- expect(getByText('All good')).toBeInTheDocument();
311
-
312
- // Trigger error
313
- act(() => {
314
- fireEvent.click(getByText('Trigger Error'));
315
- });
316
-
317
- // Should show error page
318
- expect(getByText('Error occurred: Test error')).toBeInTheDocument();
319
-
320
- // Clear error
321
- act(() => {
322
- fireEvent.click(getByText('Retry'));
323
- });
324
-
325
- // Should return to normal state
326
- expect(getByText('All good')).toBeInTheDocument();
327
- expect(queryByText('Error occurred: Test error')).not.toBeInTheDocument();
328
- });
329
- });
330
-
331
- describe('Component Export Verification', () => {
332
- it('should export all error components as functions', () => {
333
- expect(typeof ErrorBoundary).toBe('function');
334
- expect(typeof ErrorPage).toBe('function');
335
- expect(typeof useError).toBe('function');
336
- expect(typeof dispatchError).toBe('function');
337
- });
338
- });
339
- });