@jmruthers/pace-core 0.5.115 → 0.5.116

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 (234) hide show
  1. package/dist/{AuthService-CVgsgtaZ.d.ts → AuthService-D4646R4b.d.ts} +9 -4
  2. package/dist/{DataTable-H5KJCAIS.js → DataTable-ZOAKQ3SU.js} +10 -9
  3. package/dist/{UnifiedAuthProvider-KZZUO27W.js → UnifiedAuthProvider-YFN7YGVN.js} +4 -3
  4. package/dist/{api-PKU4PUBO.js → api-TNIBJWLM.js} +3 -3
  5. package/dist/{audit-H4YJJF7R.js → audit-T36HM7IM.js} +2 -2
  6. package/dist/{chunk-SYXOZQ4P.js → chunk-2GJ5GL77.js} +1 -1
  7. package/dist/chunk-2GJ5GL77.js.map +1 -0
  8. package/dist/{chunk-XYRZV7R5.js → chunk-2LM4QQGH.js} +30 -34
  9. package/dist/chunk-2LM4QQGH.js.map +1 -0
  10. package/dist/{chunk-3OGQLOJM.js → chunk-3DBFLLLU.js} +30 -1
  11. package/dist/chunk-3DBFLLLU.js.map +1 -0
  12. package/dist/{chunk-KTHLNIMA.js → chunk-ECOVPXYS.js} +13 -62
  13. package/dist/chunk-ECOVPXYS.js.map +1 -0
  14. package/dist/{chunk-OO3V7W4H.js → chunk-KA3PSVNV.js} +87 -40
  15. package/dist/chunk-KA3PSVNV.js.map +1 -0
  16. package/dist/{chunk-HKWQN44G.js → chunk-KMPWND3F.js} +15 -15
  17. package/dist/{chunk-L36JW4KV.js → chunk-LFS45U62.js} +2 -2
  18. package/dist/{chunk-NEONKMTU.js → chunk-LZYHAL7Y.js} +9 -4
  19. package/dist/{chunk-NEONKMTU.js.map → chunk-LZYHAL7Y.js.map} +1 -1
  20. package/dist/{chunk-BUN7NMV7.js → chunk-O3FTRYEU.js} +2 -2
  21. package/dist/{chunk-F6QB26OS.js → chunk-P3PUOL6B.js} +80 -8
  22. package/dist/chunk-P3PUOL6B.js.map +1 -0
  23. package/dist/{chunk-ZPXWJA4H.js → chunk-PHDAXDHB.js} +131 -5
  24. package/dist/chunk-PHDAXDHB.js.map +1 -0
  25. package/dist/chunk-UJI6WSMD.js +201 -0
  26. package/dist/{chunk-5CDJCTOO.js.map → chunk-UJI6WSMD.js.map} +1 -1
  27. package/dist/{chunk-OUU3SP6I.js → chunk-UKZWNQMB.js} +50 -7
  28. package/dist/{chunk-OUU3SP6I.js.map → chunk-UKZWNQMB.js.map} +1 -1
  29. package/dist/{chunk-7H75SHXZ.js → chunk-VN3OOE35.js} +2 -2
  30. package/dist/{chunk-QKIVSZ2O.js → chunk-WP5I5GLN.js} +2 -2
  31. package/dist/components.d.ts +1 -1
  32. package/dist/components.js +12 -11
  33. package/dist/components.js.map +1 -1
  34. package/dist/hooks.d.ts +1 -1
  35. package/dist/hooks.js +10 -9
  36. package/dist/hooks.js.map +1 -1
  37. package/dist/index.d.ts +4 -4
  38. package/dist/index.js +19 -16
  39. package/dist/index.js.map +1 -1
  40. package/dist/providers.d.ts +2 -2
  41. package/dist/providers.js +3 -2
  42. package/dist/rbac/index.d.ts +82 -1
  43. package/dist/rbac/index.js +13 -10
  44. package/dist/{useToast-DVT4dMtf.d.ts → useToast-Cs_g32bg.d.ts} +1 -1
  45. package/dist/utils.js +6 -4
  46. package/dist/utils.js.map +1 -1
  47. package/dist/validation.js +3 -1
  48. package/dist/validation.js.map +1 -1
  49. package/docs/README.md +4 -0
  50. package/docs/api/classes/ColumnFactory.md +1 -1
  51. package/docs/api/classes/ErrorBoundary.md +1 -1
  52. package/docs/api/classes/InvalidScopeError.md +1 -1
  53. package/docs/api/classes/MissingUserContextError.md +1 -1
  54. package/docs/api/classes/OrganisationContextRequiredError.md +1 -1
  55. package/docs/api/classes/PermissionDeniedError.md +1 -1
  56. package/docs/api/classes/PublicErrorBoundary.md +1 -1
  57. package/docs/api/classes/RBACAuditManager.md +35 -12
  58. package/docs/api/classes/RBACCache.md +1 -1
  59. package/docs/api/classes/RBACEngine.md +1 -1
  60. package/docs/api/classes/RBACError.md +1 -1
  61. package/docs/api/classes/RBACNotInitializedError.md +1 -1
  62. package/docs/api/classes/SecureSupabaseClient.md +1 -1
  63. package/docs/api/classes/StorageUtils.md +1 -1
  64. package/docs/api/enums/FileCategory.md +1 -1
  65. package/docs/api/interfaces/AggregateConfig.md +1 -1
  66. package/docs/api/interfaces/ButtonProps.md +1 -1
  67. package/docs/api/interfaces/CardProps.md +1 -1
  68. package/docs/api/interfaces/ColorPalette.md +1 -1
  69. package/docs/api/interfaces/ColorShade.md +1 -1
  70. package/docs/api/interfaces/DataAccessRecord.md +1 -1
  71. package/docs/api/interfaces/DataRecord.md +1 -1
  72. package/docs/api/interfaces/DataTableAction.md +1 -1
  73. package/docs/api/interfaces/DataTableColumn.md +1 -1
  74. package/docs/api/interfaces/DataTableProps.md +1 -1
  75. package/docs/api/interfaces/DataTableToolbarButton.md +1 -1
  76. package/docs/api/interfaces/EmptyStateConfig.md +1 -1
  77. package/docs/api/interfaces/EnhancedNavigationMenuProps.md +1 -1
  78. package/docs/api/interfaces/EventAppRoleData.md +71 -0
  79. package/docs/api/interfaces/FileDisplayProps.md +1 -1
  80. package/docs/api/interfaces/FileMetadata.md +1 -1
  81. package/docs/api/interfaces/FileReference.md +1 -1
  82. package/docs/api/interfaces/FileSizeLimits.md +1 -1
  83. package/docs/api/interfaces/FileUploadOptions.md +1 -1
  84. package/docs/api/interfaces/FileUploadProps.md +1 -1
  85. package/docs/api/interfaces/FooterProps.md +1 -1
  86. package/docs/api/interfaces/GrantEventAppRoleParams.md +122 -0
  87. package/docs/api/interfaces/InactivityWarningModalProps.md +1 -1
  88. package/docs/api/interfaces/InputProps.md +1 -1
  89. package/docs/api/interfaces/LabelProps.md +1 -1
  90. package/docs/api/interfaces/LoginFormProps.md +1 -1
  91. package/docs/api/interfaces/NavigationAccessRecord.md +1 -1
  92. package/docs/api/interfaces/NavigationContextType.md +1 -1
  93. package/docs/api/interfaces/NavigationGuardProps.md +1 -1
  94. package/docs/api/interfaces/NavigationItem.md +1 -1
  95. package/docs/api/interfaces/NavigationMenuProps.md +1 -1
  96. package/docs/api/interfaces/NavigationProviderProps.md +1 -1
  97. package/docs/api/interfaces/Organisation.md +1 -1
  98. package/docs/api/interfaces/OrganisationContextType.md +1 -1
  99. package/docs/api/interfaces/OrganisationMembership.md +1 -1
  100. package/docs/api/interfaces/OrganisationProviderProps.md +1 -1
  101. package/docs/api/interfaces/OrganisationSecurityError.md +1 -1
  102. package/docs/api/interfaces/PaceAppLayoutProps.md +27 -27
  103. package/docs/api/interfaces/PaceLoginPageProps.md +1 -1
  104. package/docs/api/interfaces/PageAccessRecord.md +1 -1
  105. package/docs/api/interfaces/PagePermissionContextType.md +1 -1
  106. package/docs/api/interfaces/PagePermissionGuardProps.md +1 -1
  107. package/docs/api/interfaces/PagePermissionProviderProps.md +1 -1
  108. package/docs/api/interfaces/PaletteData.md +1 -1
  109. package/docs/api/interfaces/PermissionEnforcerProps.md +1 -1
  110. package/docs/api/interfaces/ProtectedRouteProps.md +1 -1
  111. package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
  112. package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
  113. package/docs/api/interfaces/PublicLoadingSpinnerProps.md +1 -1
  114. package/docs/api/interfaces/PublicPageFooterProps.md +1 -1
  115. package/docs/api/interfaces/PublicPageHeaderProps.md +1 -1
  116. package/docs/api/interfaces/PublicPageLayoutProps.md +1 -1
  117. package/docs/api/interfaces/RBACConfig.md +1 -1
  118. package/docs/api/interfaces/RBACLogger.md +1 -1
  119. package/docs/api/interfaces/RevokeEventAppRoleParams.md +100 -0
  120. package/docs/api/interfaces/RoleBasedRouterContextType.md +1 -1
  121. package/docs/api/interfaces/RoleBasedRouterProps.md +1 -1
  122. package/docs/api/interfaces/RoleManagementResult.md +52 -0
  123. package/docs/api/interfaces/RouteAccessRecord.md +1 -1
  124. package/docs/api/interfaces/RouteConfig.md +1 -1
  125. package/docs/api/interfaces/SecureDataContextType.md +1 -1
  126. package/docs/api/interfaces/SecureDataProviderProps.md +1 -1
  127. package/docs/api/interfaces/StorageConfig.md +1 -1
  128. package/docs/api/interfaces/StorageFileInfo.md +1 -1
  129. package/docs/api/interfaces/StorageFileMetadata.md +1 -1
  130. package/docs/api/interfaces/StorageListOptions.md +1 -1
  131. package/docs/api/interfaces/StorageListResult.md +1 -1
  132. package/docs/api/interfaces/StorageUploadOptions.md +1 -1
  133. package/docs/api/interfaces/StorageUploadResult.md +1 -1
  134. package/docs/api/interfaces/StorageUrlOptions.md +1 -1
  135. package/docs/api/interfaces/StyleImport.md +1 -1
  136. package/docs/api/interfaces/SwitchProps.md +1 -1
  137. package/docs/api/interfaces/ToastActionElement.md +1 -1
  138. package/docs/api/interfaces/ToastProps.md +1 -1
  139. package/docs/api/interfaces/UnifiedAuthContextType.md +1 -1
  140. package/docs/api/interfaces/UnifiedAuthProviderProps.md +1 -1
  141. package/docs/api/interfaces/UseInactivityTrackerOptions.md +1 -1
  142. package/docs/api/interfaces/UseInactivityTrackerReturn.md +1 -1
  143. package/docs/api/interfaces/UsePublicEventOptions.md +1 -1
  144. package/docs/api/interfaces/UsePublicEventReturn.md +1 -1
  145. package/docs/api/interfaces/UsePublicFileDisplayOptions.md +1 -1
  146. package/docs/api/interfaces/UsePublicFileDisplayReturn.md +1 -1
  147. package/docs/api/interfaces/UsePublicRouteParamsReturn.md +1 -1
  148. package/docs/api/interfaces/UseResolvedScopeOptions.md +1 -1
  149. package/docs/api/interfaces/UseResolvedScopeReturn.md +1 -1
  150. package/docs/api/interfaces/UserEventAccess.md +1 -1
  151. package/docs/api/interfaces/UserMenuProps.md +1 -1
  152. package/docs/api/interfaces/UserProfile.md +1 -1
  153. package/docs/api/modules.md +41 -14
  154. package/docs/architecture/rpc-function-standards.md +193 -0
  155. package/package.json +1 -1
  156. package/src/__tests__/TEST_STANDARD.md +244 -2
  157. package/src/components/DataTable/__tests__/a11y.basic.test.tsx +46 -16
  158. package/src/components/DataTable/__tests__/keyboard.test.tsx +276 -217
  159. package/src/components/DataTable/components/DataTableCore.tsx +29 -2
  160. package/src/components/DataTable/components/DataTableToolbar.tsx +3 -2
  161. package/src/components/DataTable/components/EditableRow.tsx +18 -1
  162. package/src/components/DataTable/components/ViewRowModal.tsx +1 -1
  163. package/src/components/DataTable/components/__tests__/AccessDeniedPage.test.tsx +735 -0
  164. package/src/components/DataTable/components/__tests__/BulkOperationsDropdown.test.tsx +572 -0
  165. package/src/components/DataTable/components/__tests__/ColumnVisibilityDropdown.test.tsx +708 -0
  166. package/src/components/DataTable/components/__tests__/DataTableErrorBoundary.test.tsx +451 -0
  167. package/src/components/DataTable/components/__tests__/DataTableModals.test.tsx +456 -0
  168. package/src/components/DataTable/components/__tests__/EditableRow.test.tsx +454 -0
  169. package/src/components/DataTable/components/__tests__/ExpandButton.test.tsx +462 -0
  170. package/src/components/DataTable/components/__tests__/FilterRow.test.tsx +423 -0
  171. package/src/components/DataTable/components/__tests__/GroupHeader.test.tsx +393 -0
  172. package/src/components/DataTable/components/__tests__/GroupingDropdown.test.tsx +617 -0
  173. package/src/components/DataTable/components/__tests__/ImportModal.test.tsx +734 -0
  174. package/src/components/DataTable/components/__tests__/ViewRowModal.test.tsx +412 -0
  175. package/src/components/DataTable/hooks/useTableHandlers.ts +4 -0
  176. package/src/components/EventSelector/EventSelector.tsx +5 -25
  177. package/src/components/PaceAppLayout/PaceAppLayout.test.tsx +12 -7
  178. package/src/components/PaceAppLayout/PaceAppLayout.tsx +4 -0
  179. package/src/components/PaceAppLayout/__tests__/PaceAppLayout.accessibility.test.tsx +7 -2
  180. package/src/components/PaceAppLayout/__tests__/PaceAppLayout.integration.test.tsx +13 -8
  181. package/src/components/PaceAppLayout/__tests__/PaceAppLayout.performance.test.tsx +109 -100
  182. package/src/components/PaceAppLayout/__tests__/PaceAppLayout.security.test.tsx +18 -13
  183. package/src/components/PaceAppLayout/__tests__/PaceAppLayout.unit.test.tsx +17 -12
  184. package/src/components/PaceLoginPage/PaceLoginPage.test.tsx +2 -0
  185. package/src/components/PaceLoginPage/PaceLoginPage.tsx +11 -1
  186. package/src/components/PasswordReset/PasswordChangeForm.test.tsx +2 -2
  187. package/src/components/ProtectedRoute/ProtectedRoute.test.tsx +648 -0
  188. package/src/components/ProtectedRoute/ProtectedRoute.tsx +10 -7
  189. package/src/components/PublicLayout/__tests__/PublicErrorBoundary.test.tsx +4 -12
  190. package/src/components/Select/Select.tsx +8 -0
  191. package/src/components/Toast/Toast.tsx +1 -1
  192. package/src/hooks/__tests__/usePublicEvent.simple.test.ts +367 -3
  193. package/src/hooks/__tests__/usePublicFileDisplay.test.ts +916 -0
  194. package/src/hooks/useEventTheme.ts +49 -18
  195. package/src/hooks/usePermissionCache.ts +5 -3
  196. package/src/hooks/useSecureDataAccess.ts +11 -1
  197. package/src/hooks/useToast.ts +1 -1
  198. package/src/providers/services/EventServiceProvider.tsx +15 -8
  199. package/src/rbac/__tests__/cache-invalidation.test.ts +385 -0
  200. package/src/rbac/audit.test.ts +206 -0
  201. package/src/rbac/audit.ts +37 -2
  202. package/src/rbac/components/__tests__/PagePermissionGuard.test.tsx +26 -23
  203. package/src/rbac/errors.test.ts +340 -0
  204. package/src/rbac/hooks/index.ts +9 -0
  205. package/src/rbac/hooks/useResolvedScope.test.ts +1063 -0
  206. package/src/rbac/hooks/useRoleManagement.test.ts +908 -0
  207. package/src/rbac/hooks/useRoleManagement.ts +255 -0
  208. package/src/services/AuthService.ts +10 -0
  209. package/src/services/EventService.ts +111 -50
  210. package/src/services/__tests__/AuthService.test.ts +1 -1
  211. package/src/services/__tests__/EventService.test.ts +60 -45
  212. package/src/services/interfaces/IEventService.ts +1 -1
  213. package/src/utils/__tests__/deviceFingerprint.unit.test.ts +320 -0
  214. package/src/utils/__tests__/logger.unit.test.ts +398 -0
  215. package/src/utils/__tests__/validation.unit.test.ts +225 -1
  216. package/src/utils/file-reference.test.ts +214 -0
  217. package/dist/chunk-3OGQLOJM.js.map +0 -1
  218. package/dist/chunk-5CDJCTOO.js +0 -190
  219. package/dist/chunk-F6QB26OS.js.map +0 -1
  220. package/dist/chunk-KTHLNIMA.js.map +0 -1
  221. package/dist/chunk-OO3V7W4H.js.map +0 -1
  222. package/dist/chunk-SYXOZQ4P.js.map +0 -1
  223. package/dist/chunk-XYRZV7R5.js.map +0 -1
  224. package/dist/chunk-ZPXWJA4H.js.map +0 -1
  225. package/src/rbac/audit-enhanced.ts +0 -351
  226. /package/dist/{DataTable-H5KJCAIS.js.map → DataTable-ZOAKQ3SU.js.map} +0 -0
  227. /package/dist/{UnifiedAuthProvider-KZZUO27W.js.map → UnifiedAuthProvider-YFN7YGVN.js.map} +0 -0
  228. /package/dist/{api-PKU4PUBO.js.map → api-TNIBJWLM.js.map} +0 -0
  229. /package/dist/{audit-H4YJJF7R.js.map → audit-T36HM7IM.js.map} +0 -0
  230. /package/dist/{chunk-HKWQN44G.js.map → chunk-KMPWND3F.js.map} +0 -0
  231. /package/dist/{chunk-L36JW4KV.js.map → chunk-LFS45U62.js.map} +0 -0
  232. /package/dist/{chunk-BUN7NMV7.js.map → chunk-O3FTRYEU.js.map} +0 -0
  233. /package/dist/{chunk-7H75SHXZ.js.map → chunk-VN3OOE35.js.map} +0 -0
  234. /package/dist/{chunk-QKIVSZ2O.js.map → chunk-WP5I5GLN.js.map} +0 -0
@@ -0,0 +1,462 @@
1
+ /**
2
+ * @file ExpandButton Component Tests
3
+ * @package @jmruthers/pace-core
4
+ * @module Components/DataTable/Components/__tests__
5
+ * @since 0.4.35
6
+ *
7
+ * Comprehensive test suite for ExpandButton component following testing guidelines.
8
+ * Tests cover all major functionality, edge cases, and user interactions.
9
+ */
10
+
11
+ import React from 'react';
12
+ import { render, screen } from '@testing-library/react';
13
+ import userEvent from '@testing-library/user-event';
14
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
15
+ import { ExpandButton, ExpandButtonMinimal } from '../ExpandButton';
16
+
17
+ // Mock lucide-react icons
18
+ vi.mock('lucide-react', () => ({
19
+ ChevronRightIcon: ({ className }: { className?: string }) => (
20
+ <div data-testid="chevron-right-icon" className={className}>ChevronRight</div>
21
+ ),
22
+ ChevronDownIcon: ({ className }: { className?: string }) => (
23
+ <div data-testid="chevron-down-icon" className={className}>ChevronDown</div>
24
+ ),
25
+ }));
26
+
27
+ describe('[component] ExpandButton', () => {
28
+ const defaultProps = {
29
+ rowId: 'row-1',
30
+ isExpanded: false,
31
+ hasChildren: true,
32
+ onClick: vi.fn(),
33
+ };
34
+
35
+ beforeEach(() => {
36
+ vi.clearAllMocks();
37
+ });
38
+
39
+ afterEach(() => {
40
+ vi.clearAllMocks();
41
+ });
42
+
43
+ describe('Rendering', () => {
44
+ it('returns null when hasChildren is false', () => {
45
+ const { container } = render(
46
+ <ExpandButton
47
+ {...defaultProps}
48
+ hasChildren={false}
49
+ />
50
+ );
51
+
52
+ expect(container.firstChild).toBeNull();
53
+ });
54
+
55
+ it('renders button when hasChildren is true', () => {
56
+ render(<ExpandButton {...defaultProps} />);
57
+
58
+ expect(screen.getByRole('button')).toBeInTheDocument();
59
+ });
60
+
61
+ it('renders ChevronRight icon when not expanded', () => {
62
+ render(<ExpandButton {...defaultProps} isExpanded={false} />);
63
+
64
+ expect(screen.getByTestId('chevron-right-icon')).toBeInTheDocument();
65
+ expect(screen.queryByTestId('chevron-down-icon')).not.toBeInTheDocument();
66
+ });
67
+
68
+ it('renders ChevronDown icon when expanded', () => {
69
+ render(<ExpandButton {...defaultProps} isExpanded={true} />);
70
+
71
+ expect(screen.getByTestId('chevron-down-icon')).toBeInTheDocument();
72
+ expect(screen.queryByTestId('chevron-right-icon')).not.toBeInTheDocument();
73
+ });
74
+
75
+ it('has correct testId attribute', () => {
76
+ render(<ExpandButton {...defaultProps} rowId="test-row-123" />);
77
+
78
+ const button = screen.getByRole('button');
79
+ expect(button).toHaveAttribute('data-testid', 'expand-button-test-row-123');
80
+ });
81
+ });
82
+
83
+ describe('User Interactions', () => {
84
+ it('calls onClick when button is clicked', async () => {
85
+ const user = userEvent.setup();
86
+ const handleClick = vi.fn();
87
+
88
+ render(
89
+ <ExpandButton
90
+ {...defaultProps}
91
+ onClick={handleClick}
92
+ />
93
+ );
94
+
95
+ const button = screen.getByRole('button');
96
+ await user.click(button);
97
+
98
+ expect(handleClick).toHaveBeenCalledTimes(1);
99
+ });
100
+
101
+ it('calls onClick when Enter key is pressed', async () => {
102
+ const user = userEvent.setup();
103
+ const handleClick = vi.fn();
104
+
105
+ render(
106
+ <ExpandButton
107
+ {...defaultProps}
108
+ onClick={handleClick}
109
+ />
110
+ );
111
+
112
+ const button = screen.getByRole('button');
113
+ button.focus();
114
+ await user.keyboard('{Enter}');
115
+
116
+ expect(handleClick).toHaveBeenCalledTimes(1);
117
+ });
118
+
119
+ it('calls onClick when Space key is pressed', async () => {
120
+ const user = userEvent.setup();
121
+ const handleClick = vi.fn();
122
+
123
+ render(
124
+ <ExpandButton
125
+ {...defaultProps}
126
+ onClick={handleClick}
127
+ />
128
+ );
129
+
130
+ const button = screen.getByRole('button');
131
+ button.focus();
132
+ await user.keyboard(' ');
133
+
134
+ expect(handleClick).toHaveBeenCalledTimes(1);
135
+ });
136
+
137
+ it('stops event propagation on click', async () => {
138
+ const user = userEvent.setup();
139
+ const handleClick = vi.fn();
140
+ const handleParentClick = vi.fn();
141
+
142
+ render(
143
+ <div onClick={handleParentClick}>
144
+ <ExpandButton
145
+ {...defaultProps}
146
+ onClick={handleClick}
147
+ />
148
+ </div>
149
+ );
150
+
151
+ const button = screen.getByRole('button');
152
+ await user.click(button);
153
+
154
+ expect(handleClick).toHaveBeenCalledTimes(1);
155
+ expect(handleParentClick).not.toHaveBeenCalled();
156
+ });
157
+
158
+ it('stops event propagation on keyboard events', async () => {
159
+ const user = userEvent.setup();
160
+ const handleClick = vi.fn();
161
+ const handleParentKeyDown = vi.fn();
162
+
163
+ render(
164
+ <div onKeyDown={handleParentKeyDown}>
165
+ <ExpandButton
166
+ {...defaultProps}
167
+ onClick={handleClick}
168
+ />
169
+ </div>
170
+ );
171
+
172
+ const button = screen.getByRole('button');
173
+ button.focus();
174
+ await user.keyboard('{Enter}');
175
+
176
+ expect(handleClick).toHaveBeenCalledTimes(1);
177
+ expect(handleParentKeyDown).not.toHaveBeenCalled();
178
+ });
179
+ });
180
+
181
+ describe('Accessibility', () => {
182
+ it('has aria-label for collapsed state', () => {
183
+ render(<ExpandButton {...defaultProps} isExpanded={false} />);
184
+
185
+ const button = screen.getByRole('button');
186
+ expect(button).toHaveAttribute('aria-label', 'Expand row');
187
+ });
188
+
189
+ it('has aria-label for expanded state', () => {
190
+ render(<ExpandButton {...defaultProps} isExpanded={true} />);
191
+
192
+ const button = screen.getByRole('button');
193
+ expect(button).toHaveAttribute('aria-label', 'Collapse row');
194
+ });
195
+
196
+ it('has aria-expanded attribute', () => {
197
+ render(<ExpandButton {...defaultProps} isExpanded={false} />);
198
+
199
+ const button = screen.getByRole('button');
200
+ expect(button).toHaveAttribute('aria-expanded', 'false');
201
+ });
202
+
203
+ it('updates aria-expanded when state changes', () => {
204
+ const { rerender } = render(<ExpandButton {...defaultProps} isExpanded={false} />);
205
+
206
+ let button = screen.getByRole('button');
207
+ expect(button).toHaveAttribute('aria-expanded', 'false');
208
+
209
+ rerender(<ExpandButton {...defaultProps} isExpanded={true} />);
210
+
211
+ button = screen.getByRole('button');
212
+ expect(button).toHaveAttribute('aria-expanded', 'true');
213
+ });
214
+ });
215
+
216
+ describe('Styling', () => {
217
+ it('applies custom className', () => {
218
+ render(
219
+ <ExpandButton
220
+ {...defaultProps}
221
+ className="custom-class"
222
+ />
223
+ );
224
+
225
+ const button = screen.getByRole('button');
226
+ expect(button.className).toContain('custom-class');
227
+ });
228
+
229
+ it('has proper button styling classes', () => {
230
+ render(<ExpandButton {...defaultProps} />);
231
+
232
+ const button = screen.getByRole('button');
233
+ expect(button.className).toContain('inline-flex');
234
+ expect(button.className).toContain('items-center');
235
+ expect(button.className).toContain('justify-center');
236
+ });
237
+ });
238
+
239
+ describe('Edge Cases', () => {
240
+ it('handles rapid clicks', async () => {
241
+ const user = userEvent.setup();
242
+ const handleClick = vi.fn();
243
+
244
+ render(
245
+ <ExpandButton
246
+ {...defaultProps}
247
+ onClick={handleClick}
248
+ />
249
+ );
250
+
251
+ const button = screen.getByRole('button');
252
+ await user.click(button);
253
+ await user.click(button);
254
+ await user.click(button);
255
+
256
+ expect(handleClick).toHaveBeenCalledTimes(3);
257
+ });
258
+
259
+ it('handles undefined onClick gracefully', () => {
260
+ expect(() => {
261
+ render(
262
+ <ExpandButton
263
+ {...defaultProps}
264
+ onClick={undefined as any}
265
+ />
266
+ );
267
+ }).not.toThrow();
268
+ });
269
+
270
+ it('handles empty rowId', () => {
271
+ render(
272
+ <ExpandButton
273
+ {...defaultProps}
274
+ rowId=""
275
+ />
276
+ );
277
+
278
+ const button = screen.getByRole('button');
279
+ expect(button).toHaveAttribute('data-testid', 'expand-button-');
280
+ });
281
+ });
282
+ });
283
+
284
+ describe('[component] ExpandButtonMinimal', () => {
285
+ const defaultProps = {
286
+ rowId: 'row-1',
287
+ isExpanded: false,
288
+ hasChildren: true,
289
+ onClick: vi.fn(),
290
+ };
291
+
292
+ beforeEach(() => {
293
+ vi.clearAllMocks();
294
+ });
295
+
296
+ afterEach(() => {
297
+ vi.clearAllMocks();
298
+ });
299
+
300
+ describe('Rendering', () => {
301
+ it('returns null when hasChildren is false', () => {
302
+ const { container } = render(
303
+ <ExpandButtonMinimal
304
+ {...defaultProps}
305
+ hasChildren={false}
306
+ />
307
+ );
308
+
309
+ expect(container.firstChild).toBeNull();
310
+ });
311
+
312
+ it('renders button when hasChildren is true', () => {
313
+ render(<ExpandButtonMinimal {...defaultProps} />);
314
+
315
+ expect(screen.getByRole('button')).toBeInTheDocument();
316
+ });
317
+
318
+ it('renders minus sign when expanded', () => {
319
+ render(<ExpandButtonMinimal {...defaultProps} isExpanded={true} />);
320
+
321
+ expect(screen.getByText('−')).toBeInTheDocument();
322
+ expect(screen.queryByText('+')).not.toBeInTheDocument();
323
+ });
324
+
325
+ it('renders plus sign when not expanded', () => {
326
+ render(<ExpandButtonMinimal {...defaultProps} isExpanded={false} />);
327
+
328
+ expect(screen.getByText('+')).toBeInTheDocument();
329
+ expect(screen.queryByText('−')).not.toBeInTheDocument();
330
+ });
331
+
332
+ it('has correct testId attribute', () => {
333
+ render(<ExpandButtonMinimal {...defaultProps} rowId="test-row-456" />);
334
+
335
+ const button = screen.getByRole('button');
336
+ expect(button).toHaveAttribute('data-testid', 'expand-button-minimal-test-row-456');
337
+ });
338
+ });
339
+
340
+ describe('User Interactions', () => {
341
+ it('calls onClick when button is clicked', async () => {
342
+ const user = userEvent.setup();
343
+ const handleClick = vi.fn();
344
+
345
+ render(
346
+ <ExpandButtonMinimal
347
+ {...defaultProps}
348
+ onClick={handleClick}
349
+ />
350
+ );
351
+
352
+ const button = screen.getByRole('button');
353
+ await user.click(button);
354
+
355
+ expect(handleClick).toHaveBeenCalledTimes(1);
356
+ });
357
+
358
+ it('calls onClick when Enter key is pressed', async () => {
359
+ const user = userEvent.setup();
360
+ const handleClick = vi.fn();
361
+
362
+ render(
363
+ <ExpandButtonMinimal
364
+ {...defaultProps}
365
+ onClick={handleClick}
366
+ />
367
+ );
368
+
369
+ const button = screen.getByRole('button');
370
+ button.focus();
371
+ await user.keyboard('{Enter}');
372
+
373
+ expect(handleClick).toHaveBeenCalledTimes(1);
374
+ });
375
+
376
+ it('calls onClick when Space key is pressed', async () => {
377
+ const user = userEvent.setup();
378
+ const handleClick = vi.fn();
379
+
380
+ render(
381
+ <ExpandButtonMinimal
382
+ {...defaultProps}
383
+ onClick={handleClick}
384
+ />
385
+ );
386
+
387
+ const button = screen.getByRole('button');
388
+ button.focus();
389
+ await user.keyboard(' ');
390
+
391
+ expect(handleClick).toHaveBeenCalledTimes(1);
392
+ });
393
+
394
+ it('stops event propagation on click', async () => {
395
+ const user = userEvent.setup();
396
+ const handleClick = vi.fn();
397
+ const handleParentClick = vi.fn();
398
+
399
+ render(
400
+ <div onClick={handleParentClick}>
401
+ <ExpandButtonMinimal
402
+ {...defaultProps}
403
+ onClick={handleClick}
404
+ />
405
+ </div>
406
+ );
407
+
408
+ const button = screen.getByRole('button');
409
+ await user.click(button);
410
+
411
+ expect(handleClick).toHaveBeenCalledTimes(1);
412
+ expect(handleParentClick).not.toHaveBeenCalled();
413
+ });
414
+ });
415
+
416
+ describe('Accessibility', () => {
417
+ it('has aria-label for collapsed state', () => {
418
+ render(<ExpandButtonMinimal {...defaultProps} isExpanded={false} />);
419
+
420
+ const button = screen.getByRole('button');
421
+ expect(button).toHaveAttribute('aria-label', 'Expand row');
422
+ });
423
+
424
+ it('has aria-label for expanded state', () => {
425
+ render(<ExpandButtonMinimal {...defaultProps} isExpanded={true} />);
426
+
427
+ const button = screen.getByRole('button');
428
+ expect(button).toHaveAttribute('aria-label', 'Collapse row');
429
+ });
430
+
431
+ it('has aria-expanded attribute', () => {
432
+ render(<ExpandButtonMinimal {...defaultProps} isExpanded={false} />);
433
+
434
+ const button = screen.getByRole('button');
435
+ expect(button).toHaveAttribute('aria-expanded', 'false');
436
+ });
437
+ });
438
+
439
+ describe('Styling', () => {
440
+ it('applies custom className', () => {
441
+ render(
442
+ <ExpandButtonMinimal
443
+ {...defaultProps}
444
+ className="custom-class"
445
+ />
446
+ );
447
+
448
+ const button = screen.getByRole('button');
449
+ expect(button.className).toContain('custom-class');
450
+ });
451
+
452
+ it('has proper button styling classes', () => {
453
+ render(<ExpandButtonMinimal {...defaultProps} />);
454
+
455
+ const button = screen.getByRole('button');
456
+ expect(button.className).toContain('inline-flex');
457
+ expect(button.className).toContain('items-center');
458
+ expect(button.className).toContain('justify-center');
459
+ });
460
+ });
461
+ });
462
+