@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.
- package/change-log.md +330 -309
- package/dist/components/buttons/ConfirmButton.d.ts +2 -2
- package/dist/components/buttons/DeleteConfirmButton.d.ts +2 -2
- package/dist/components/buttons/IconButtons.d.ts +40 -41
- package/dist/components/errors/Errors.d.ts +1 -2
- package/dist/components/forms/FormField.d.ts +22 -0
- package/dist/components/forms/FormFields.d.ts +1 -56
- package/dist/components/forms/FormModal.d.ts +7 -34
- package/dist/components/forms/FormModalProvider.d.ts +19 -26
- package/dist/components/forms/FormProvider.d.ts +66 -0
- package/dist/components/forms/fields/FormBadgesSelection.d.ts +26 -0
- package/dist/components/forms/fields/FormCheckbox.d.ts +7 -0
- package/dist/components/forms/fields/FormDropdown.d.ts +19 -0
- package/dist/components/forms/fields/FormInput.d.ts +17 -0
- package/dist/components/forms/fields/FormSelect.d.ts +12 -0
- package/dist/components/forms/fields/index.d.ts +5 -0
- package/dist/components/indicators/CheckIndicator.d.ts +1 -2
- package/dist/components/indicators/LoadingIndicator.d.ts +4 -4
- package/dist/components/login/LoginPage.d.ts +1 -1
- package/dist/components/tables/DataTable.d.ts +2 -2
- package/dist/components/tables/DragAndDropList.d.ts +2 -2
- package/dist/components/tables/SearchBox.d.ts +2 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -2
- package/dist/index.js.LICENSE.txt +0 -4
- package/dist/localization/LocalizationContext.d.ts +1 -1
- package/dist/utils/hooks.d.ts +1 -1
- package/dist/utils/timeAndDate.d.ts +5 -2
- package/dist/utils/utils.d.ts +3 -3
- package/package.json +10 -11
- package/src/__tests__/buttons.test.tsx +545 -0
- package/src/__tests__/errors.test.tsx +339 -0
- package/src/__tests__/forms.test.tsx +3021 -0
- package/src/__tests__/hooks.test.tsx +413 -0
- package/src/__tests__/indicators.test.tsx +284 -0
- package/src/__tests__/localization.test.tsx +462 -0
- package/src/__tests__/login.test.tsx +417 -0
- package/src/__tests__/setupTests.ts +328 -0
- package/src/__tests__/tables.test.tsx +609 -0
- package/src/__tests__/timeAndDate.test.tsx +308 -0
- package/src/__tests__/utils.test.tsx +422 -0
- package/src/components/forms/FormField.tsx +92 -0
- package/src/components/forms/FormFields.tsx +3 -423
- package/src/components/forms/FormModal.tsx +168 -243
- package/src/components/forms/FormModalProvider.tsx +141 -95
- package/src/components/forms/FormProvider.tsx +218 -0
- package/src/components/forms/fields/FormBadgesSelection.tsx +108 -0
- package/src/components/forms/fields/FormCheckbox.tsx +76 -0
- package/src/components/forms/fields/FormDropdown.tsx +123 -0
- package/src/components/forms/fields/FormInput.tsx +114 -0
- package/src/components/forms/fields/FormSelect.tsx +47 -0
- package/src/components/forms/fields/index.ts +6 -0
- package/src/index.ts +32 -28
- package/src/localization/LocalizationContext.tsx +156 -131
- package/src/localization/localization.ts +131 -131
- package/src/utils/hooks.ts +108 -94
- package/src/utils/timeAndDate.ts +33 -4
- package/src/utils/utils.ts +74 -66
- package/dist/components/forms/CreateEditModal.d.ts +0 -41
- package/dist/components/forms/CreateEditModalProvider.d.ts +0 -41
- package/dist/components/forms/FormFields.test.d.ts +0 -4
- package/dist/login/Login.d.ts +0 -70
- package/src/components/forms/FormFields.test.tsx +0 -107
|
@@ -0,0 +1,339 @@
|
|
|
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
|
+
});
|