@jmruthers/pace-core 0.5.73 → 0.5.75
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/dist/{DataTable-INW5YIFV.js → DataTable-HWZQGASI.js} +8 -8
- package/dist/{PublicLoadingSpinner-DLpF5bbs.d.ts → PublicLoadingSpinner-BKNBT6b6.d.ts} +2 -2
- package/dist/RBACService-C4udt_Zp.d.ts +528 -0
- package/dist/{UnifiedAuthProvider-6SYT5WFN.js → UnifiedAuthProvider-3NKDOSOK.js} +6 -4
- package/dist/UnifiedAuthProvider-Bj6YCf7c.d.ts +113 -0
- package/dist/{chunk-2PRPDH66.js → chunk-2CHATWBF.js} +5 -7
- package/dist/chunk-2CHATWBF.js.map +1 -0
- package/dist/{chunk-43C63KLH.js → chunk-2DFZ432F.js} +496 -30
- package/dist/chunk-2DFZ432F.js.map +1 -0
- package/dist/{chunk-M4UMXYNK.js → chunk-33PHABLB.js} +36 -3
- package/dist/chunk-33PHABLB.js.map +1 -0
- package/dist/chunk-5F3NDPJV.js +232 -0
- package/dist/chunk-5F3NDPJV.js.map +1 -0
- package/dist/chunk-A4FUBC7B.js +17 -0
- package/dist/chunk-A4FUBC7B.js.map +1 -0
- package/dist/{chunk-SMJZMKYN.js → chunk-A6HBIY5P.js} +2 -11
- package/dist/{chunk-SMJZMKYN.js.map → chunk-A6HBIY5P.js.map} +1 -1
- package/dist/{chunk-GBC5PC3N.js → chunk-CY3AHGO4.js} +6256 -1937
- package/dist/chunk-CY3AHGO4.js.map +1 -0
- package/dist/{chunk-BYG6OSTC.js → chunk-DAXLNIDY.js} +48 -50
- package/dist/chunk-DAXLNIDY.js.map +1 -0
- package/dist/{chunk-VKOCWWVY.js → chunk-L3RV2ALE.js} +1 -6
- package/dist/{chunk-VKOCWWVY.js.map → chunk-L3RV2ALE.js.map} +1 -1
- package/dist/chunk-LW7MMEAQ.js +59 -0
- package/dist/chunk-LW7MMEAQ.js.map +1 -0
- package/dist/{chunk-LANO5IFV.js → chunk-NTNILOBC.js} +7 -9
- package/dist/chunk-NTNILOBC.js.map +1 -0
- package/dist/chunk-PYUXFQJ3.js +11 -0
- package/dist/chunk-PYUXFQJ3.js.map +1 -0
- package/dist/chunk-URUTVZ7N.js +27 -0
- package/dist/chunk-URUTVZ7N.js.map +1 -0
- package/dist/chunk-WN6XJWOS.js +2468 -0
- package/dist/chunk-WN6XJWOS.js.map +1 -0
- package/dist/{chunk-3SP4P7NS.js → chunk-XLZ7U46Z.js} +59 -1
- package/dist/chunk-XLZ7U46Z.js.map +1 -0
- package/dist/{chunk-UC2BWIK7.js → chunk-ZTT2AXMX.js} +9 -14
- package/dist/chunk-ZTT2AXMX.js.map +1 -0
- package/dist/components.d.ts +4 -5
- package/dist/components.js +32 -39
- package/dist/components.js.map +1 -1
- package/dist/hooks.d.ts +3 -3
- package/dist/hooks.js +9 -8
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +156 -10
- package/dist/index.js +188 -93
- package/dist/index.js.map +1 -1
- package/dist/{organisation-t-vvQC3g.d.ts → organisation-BtshODVF.d.ts} +4 -3
- package/dist/providers.d.ts +27 -38
- package/dist/providers.js +33 -23
- package/dist/rbac/index.d.ts +61 -5
- package/dist/rbac/index.js +13 -14
- package/dist/styles/index.js +2 -2
- package/dist/theming/runtime.js +1 -3
- package/dist/types.d.ts +3 -3
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/{unified-CMPjE_fv.d.ts → unified-CM7T0aTK.d.ts} +1 -1
- package/dist/useInactivityTracker-MRUU55XI.js +10 -0
- package/dist/useInactivityTracker-MRUU55XI.js.map +1 -0
- package/dist/{usePublicRouteParams-Ua1Vz-HG.d.ts → usePublicRouteParams-B-CumWRc.d.ts} +3 -3
- package/dist/utils.js +7 -9
- package/dist/utils.js.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/docs/api/classes/ColumnFactory.md +1 -1
- package/docs/api/classes/ErrorBoundary.md +1 -1
- package/docs/api/classes/InvalidScopeError.md +1 -1
- package/docs/api/classes/MissingUserContextError.md +1 -1
- package/docs/api/classes/OrganisationContextRequiredError.md +1 -1
- package/docs/api/classes/PermissionDeniedError.md +1 -1
- package/docs/api/classes/PublicErrorBoundary.md +1 -1
- package/docs/api/classes/RBACAuditManager.md +1 -1
- package/docs/api/classes/RBACCache.md +1 -1
- package/docs/api/classes/RBACEngine.md +1 -1
- package/docs/api/classes/RBACError.md +1 -1
- package/docs/api/classes/RBACNotInitializedError.md +1 -1
- package/docs/api/classes/SecureSupabaseClient.md +1 -1
- package/docs/api/classes/StorageUtils.md +1 -1
- package/docs/api/enums/FileCategory.md +1 -1
- package/docs/api/interfaces/AggregateConfig.md +1 -1
- package/docs/api/interfaces/ButtonProps.md +3 -3
- package/docs/api/interfaces/CardProps.md +2 -2
- package/docs/api/interfaces/ColorPalette.md +1 -1
- package/docs/api/interfaces/ColorShade.md +1 -1
- package/docs/api/interfaces/DataAccessRecord.md +1 -1
- package/docs/api/interfaces/DataTableAction.md +1 -1
- package/docs/api/interfaces/DataTableColumn.md +1 -1
- package/docs/api/interfaces/DataTableProps.md +1 -1
- package/docs/api/interfaces/DataTableToolbarButton.md +1 -1
- package/docs/api/interfaces/EmptyStateConfig.md +1 -1
- package/docs/api/interfaces/EnhancedNavigationMenuProps.md +1 -1
- package/docs/api/interfaces/EventLogoProps.md +2 -2
- package/docs/api/interfaces/FileDisplayProps.md +1 -1
- package/docs/api/interfaces/FileMetadata.md +1 -1
- package/docs/api/interfaces/FileReference.md +1 -1
- package/docs/api/interfaces/FileSizeLimits.md +1 -1
- package/docs/api/interfaces/FileUploadOptions.md +1 -1
- package/docs/api/interfaces/FileUploadProps.md +1 -1
- package/docs/api/interfaces/FooterProps.md +1 -1
- package/docs/api/interfaces/InactivityWarningModalProps.md +1 -1
- package/docs/api/interfaces/InputProps.md +2 -2
- package/docs/api/interfaces/LabelProps.md +1 -1
- package/docs/api/interfaces/LoginFormProps.md +1 -1
- package/docs/api/interfaces/NavigationAccessRecord.md +1 -1
- package/docs/api/interfaces/NavigationContextType.md +1 -1
- package/docs/api/interfaces/NavigationGuardProps.md +1 -1
- package/docs/api/interfaces/NavigationItem.md +1 -1
- package/docs/api/interfaces/NavigationMenuProps.md +1 -1
- package/docs/api/interfaces/NavigationProviderProps.md +1 -1
- package/docs/api/interfaces/Organisation.md +1 -1
- package/docs/api/interfaces/OrganisationContextType.md +28 -17
- package/docs/api/interfaces/OrganisationMembership.md +1 -1
- package/docs/api/interfaces/OrganisationProviderProps.md +2 -2
- package/docs/api/interfaces/OrganisationSecurityError.md +1 -1
- package/docs/api/interfaces/PaceAppLayoutProps.md +1 -1
- package/docs/api/interfaces/PaceLoginPageProps.md +1 -1
- package/docs/api/interfaces/PageAccessRecord.md +1 -1
- package/docs/api/interfaces/PagePermissionContextType.md +1 -1
- package/docs/api/interfaces/PagePermissionGuardProps.md +1 -1
- package/docs/api/interfaces/PagePermissionProviderProps.md +1 -1
- package/docs/api/interfaces/PaletteData.md +1 -1
- package/docs/api/interfaces/PermissionEnforcerProps.md +1 -1
- package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
- package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
- package/docs/api/interfaces/PublicLoadingSpinnerProps.md +2 -2
- package/docs/api/interfaces/PublicPageFooterProps.md +1 -1
- package/docs/api/interfaces/PublicPageHeaderProps.md +1 -1
- package/docs/api/interfaces/PublicPageLayoutProps.md +1 -1
- package/docs/api/interfaces/RBACConfig.md +1 -1
- package/docs/api/interfaces/RBACContextType.md +5 -11
- package/docs/api/interfaces/RBACLogger.md +1 -1
- package/docs/api/interfaces/RBACProviderProps.md +1 -1
- package/docs/api/interfaces/RoleBasedRouterContextType.md +1 -1
- package/docs/api/interfaces/RoleBasedRouterProps.md +1 -1
- package/docs/api/interfaces/RouteAccessRecord.md +1 -1
- package/docs/api/interfaces/RouteConfig.md +1 -1
- package/docs/api/interfaces/SecureDataContextType.md +1 -1
- package/docs/api/interfaces/SecureDataProviderProps.md +1 -1
- package/docs/api/interfaces/StorageConfig.md +1 -1
- package/docs/api/interfaces/StorageFileInfo.md +1 -1
- package/docs/api/interfaces/StorageFileMetadata.md +1 -1
- package/docs/api/interfaces/StorageListOptions.md +1 -1
- package/docs/api/interfaces/StorageListResult.md +1 -1
- package/docs/api/interfaces/StorageUploadOptions.md +1 -1
- package/docs/api/interfaces/StorageUploadResult.md +1 -1
- package/docs/api/interfaces/StorageUrlOptions.md +1 -1
- package/docs/api/interfaces/StyleImport.md +1 -1
- package/docs/api/interfaces/SwitchProps.md +1 -1
- package/docs/api/interfaces/ToastActionElement.md +1 -1
- package/docs/api/interfaces/ToastProps.md +1 -1
- package/docs/api/interfaces/UnifiedAuthContextType.md +524 -440
- package/docs/api/interfaces/UnifiedAuthProviderProps.md +14 -14
- package/docs/api/interfaces/UseInactivityTrackerOptions.md +1 -1
- package/docs/api/interfaces/UseInactivityTrackerReturn.md +1 -1
- package/docs/api/interfaces/UsePublicEventLogoOptions.md +1 -1
- package/docs/api/interfaces/UsePublicEventLogoReturn.md +1 -1
- package/docs/api/interfaces/UsePublicEventOptions.md +1 -1
- package/docs/api/interfaces/UsePublicEventReturn.md +1 -1
- package/docs/api/interfaces/UsePublicRouteParamsReturn.md +1 -1
- package/docs/api/interfaces/UserEventAccess.md +11 -11
- package/docs/api/interfaces/UserMenuProps.md +1 -1
- package/docs/api/interfaces/UserProfile.md +1 -1
- package/docs/api/modules.md +179 -52
- package/docs/architecture/services.md +30 -32
- package/docs/breaking-changes.md +2 -5
- package/docs/implementation-guides/data-tables.md +82 -1
- package/docs/migration/service-architecture.md +121 -260
- package/docs/rbac/README-rbac-rls-integration.md +48 -38
- package/{src/rbac/examples → examples/RBAC}/CompleteRBACExample.tsx +3 -2
- package/{src/rbac/examples → examples/RBAC}/EventBasedApp.tsx +5 -4
- package/{src/components/examples → examples/RBAC}/PermissionExample.tsx +7 -6
- package/examples/RBAC/__tests__/PermissionExample.test.tsx +150 -0
- package/examples/RBAC/index.ts +13 -0
- package/examples/README.md +37 -0
- package/examples/index.ts +22 -0
- package/{src/examples → examples/public-pages}/CorrectPublicPageImplementation.tsx +1 -1
- package/{src/examples → examples/public-pages}/PublicEventPage.tsx +1 -1
- package/{src/examples → examples/public-pages}/PublicPageApp.tsx +1 -1
- package/{src/examples → examples/public-pages}/PublicPageUsageExample.tsx +1 -1
- package/examples/public-pages/__tests__/PublicPageUsageExample.test.tsx +159 -0
- package/examples/public-pages/index.ts +14 -0
- package/package.json +22 -18
- package/src/__tests__/TEST_GUIDE_CURSOR.md +650 -9
- package/src/__tests__/helpers/README.md +255 -0
- package/src/__tests__/helpers/index.ts +62 -0
- package/src/__tests__/helpers/supabaseMock.ts +27 -3
- package/src/__tests__/rbac/PagePermissionGuard.test.tsx +6 -8
- package/src/components/DataTable/components/DataTableCore.tsx +37 -3
- package/src/components/DataTable/components/__tests__/COVERAGE_NOTE.md +55 -0
- package/src/components/DataTable/core/ColumnManager.ts +10 -0
- package/src/components/DataTable/core/__tests__/ColumnFactory.test.ts +254 -0
- package/src/components/DataTable/core/__tests__/ColumnManager.test.ts +193 -0
- package/src/components/DataTable/examples/__tests__/HierarchicalExample.test.tsx +45 -0
- package/src/components/DataTable/examples/__tests__/PerformanceExample.test.tsx +117 -0
- package/src/components/Dialog/Dialog.tsx +2 -2
- package/src/components/Dialog/examples/__tests__/HtmlDialogExample.test.tsx +71 -0
- package/src/components/Dialog/examples/__tests__/SimpleHtmlTest.test.tsx +122 -0
- package/src/components/EventSelector/EventSelector.tsx +1 -1
- package/src/components/Header/Header.test.tsx +35 -1
- package/src/components/Header/Header.tsx +3 -1
- package/src/components/OrganisationSelector/OrganisationSelector.tsx +3 -3
- package/src/components/PaceAppLayout/__tests__/PaceAppLayout.rbac.test.tsx +24 -4
- package/src/components/PaceLoginPage/PaceLoginPage.test.tsx +3 -2
- package/src/components/Toast/Toast.test.tsx +1 -1
- package/src/components/Toast/Toast.tsx +1 -1
- package/src/hooks/__tests__/useFocusManagement.unit.test.ts +220 -0
- package/src/hooks/__tests__/useIsMobile.unit.test.ts +117 -0
- package/src/hooks/__tests__/useKeyboardShortcuts.unit.test.ts +295 -0
- package/src/hooks/__tests__/useOrganisationSecurity.unit.test.tsx +29 -19
- package/src/hooks/__tests__/useRBAC.unit.test.ts +7 -3
- package/src/hooks/__tests__/useSecureDataAccess.unit.test.tsx +115 -19
- package/src/hooks/useEventTheme.test.ts +350 -0
- package/src/hooks/useEventTheme.ts +1 -1
- package/src/hooks/useEvents.ts +61 -0
- package/src/hooks/useOrganisationSecurity.test.ts +4 -4
- package/src/hooks/useOrganisationSecurity.ts +2 -2
- package/src/hooks/useOrganisations.ts +64 -0
- package/src/hooks/useSecureDataAccess.test.ts +9 -5
- package/src/hooks/useSecureDataAccess.ts +2 -2
- package/src/index.ts +18 -3
- package/src/providers/AuthProvider.tsx +8 -292
- package/src/providers/EventProvider.tsx +15 -425
- package/src/providers/InactivityProvider.tsx +8 -231
- package/src/providers/OrganisationProvider.test.simple.tsx +3 -2
- package/src/providers/OrganisationProvider.tsx +11 -890
- package/src/providers/UnifiedAuthProvider.tsx +8 -320
- package/src/providers/__tests__/AuthProvider.test.tsx +18 -17
- package/src/providers/__tests__/EventProvider.test.tsx +253 -2
- package/src/providers/__tests__/InactivityProvider.test-helper.tsx +65 -0
- package/src/providers/__tests__/InactivityProvider.test.tsx +46 -114
- package/src/providers/__tests__/OrganisationProvider.test.tsx +313 -3
- package/src/providers/__tests__/UnifiedAuthProvider.test.tsx +383 -2
- package/src/providers/index.ts +8 -7
- package/src/providers/services/EventServiceProvider.tsx +3 -0
- package/src/providers/services/UnifiedAuthProvider.tsx +3 -0
- package/src/rbac/hooks/usePermissions.test.ts +296 -0
- package/src/rbac/hooks/useRBAC.test.ts +9 -5
- package/src/rbac/hooks/useRBAC.ts +3 -3
- package/src/rbac/providers/__tests__/RBACProvider.integration.test.tsx +688 -0
- package/src/rbac/providers/__tests__/RBACProvider.test.tsx +507 -0
- package/src/services/AuthService.ts +19 -4
- package/src/services/__tests__/AuthService.test.ts +288 -0
- package/src/styles/core.css +2 -0
- package/src/types/__tests__/guards.test.ts +246 -0
- package/src/types/guards.ts +1 -0
- package/src/types/organisation.ts +3 -2
- package/src/validation/__tests__/sanitization.unit.test.ts +250 -0
- package/src/validation/__tests__/schemaUtils.unit.test.ts +451 -0
- package/src/validation/__tests__/user.unit.test.ts +440 -0
- package/dist/RBACProvider-BO4ilsQB.d.ts +0 -63
- package/dist/UnifiedAuthProvider-D02AMXgO.d.ts +0 -103
- package/dist/chunk-2PRPDH66.js.map +0 -1
- package/dist/chunk-3SP4P7NS.js.map +0 -1
- package/dist/chunk-43C63KLH.js.map +0 -1
- package/dist/chunk-5A4RL4BC.js +0 -5670
- package/dist/chunk-5A4RL4BC.js.map +0 -1
- package/dist/chunk-BYG6OSTC.js.map +0 -1
- package/dist/chunk-CDDYJCYU.js +0 -79
- package/dist/chunk-CDDYJCYU.js.map +0 -1
- package/dist/chunk-F24P24TZ.js +0 -17
- package/dist/chunk-F24P24TZ.js.map +0 -1
- package/dist/chunk-GBC5PC3N.js.map +0 -1
- package/dist/chunk-LANO5IFV.js.map +0 -1
- package/dist/chunk-M4UMXYNK.js.map +0 -1
- package/dist/chunk-RJNE764D.js +0 -953
- package/dist/chunk-RJNE764D.js.map +0 -1
- package/dist/chunk-UC2BWIK7.js.map +0 -1
- package/dist/rbac/cli/policy-manager.js +0 -278
- package/dist/rbac/cli/policy-manager.js.map +0 -1
- package/docs/api/interfaces/EventContextType.md +0 -96
- package/docs/api/interfaces/EventProviderProps.md +0 -19
- package/src/providers/OrganisationProvider.test.tsx +0 -164
- package/src/providers/UnifiedAuthProvider.test.tsx +0 -124
- package/src/providers/__tests__/AuthProvider.test.tsx.backup +0 -771
- package/src/providers/__tests__/EventProvider.test.tsx.backup +0 -824
- package/src/providers/__tests__/OrganisationProvider.test.tsx.backup +0 -820
- package/src/providers/__tests__/UnifiedAuthProvider.test.tsx.backup +0 -911
- package/src/providers/__tests__/UnifiedAuthProvider.test.tsx.backup2 +0 -166
- package/src/rbac/cli/__tests__/policy-manager.test.ts +0 -339
- package/src/rbac/cli/policy-manager.ts +0 -443
- package/dist/{DataTable-INW5YIFV.js.map → DataTable-HWZQGASI.js.map} +0 -0
- package/dist/{UnifiedAuthProvider-6SYT5WFN.js.map → UnifiedAuthProvider-3NKDOSOK.js.map} +0 -0
- package/dist/{validation-PM_iOaTI.d.ts → validation-D8VcbTzC.d.ts} +2 -2
- /package/src/utils/{appNameResolver.test.ts.backup → appNameResolver.test 2.ts} +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
|
-
import { render, screen } from '@testing-library/react';
|
|
7
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
8
8
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
9
9
|
import { OrganisationProvider, useOrganisations } from '../OrganisationProvider';
|
|
10
10
|
import { TEST_FIXTURES } from '../../__tests__/fixtures/test-data';
|
|
@@ -77,7 +77,7 @@ const TestWrapper = ({
|
|
|
77
77
|
);
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
describe('OrganisationProvider
|
|
80
|
+
describe('OrganisationProvider', () => {
|
|
81
81
|
let mockSupabaseClient: ReturnType<typeof createMockSupabaseClient>;
|
|
82
82
|
|
|
83
83
|
beforeEach(() => {
|
|
@@ -85,7 +85,7 @@ describe('OrganisationProvider - Simple Tests', () => {
|
|
|
85
85
|
mockSupabaseClient = createMockSupabaseClient();
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
describe('
|
|
88
|
+
describe('Rendering', () => {
|
|
89
89
|
it('renders without crashing', () => {
|
|
90
90
|
render(
|
|
91
91
|
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
@@ -181,4 +181,314 @@ describe('OrganisationProvider - Simple Tests', () => {
|
|
|
181
181
|
expect(screen.getByTestId('test-component')).toBeInTheDocument();
|
|
182
182
|
});
|
|
183
183
|
});
|
|
184
|
+
|
|
185
|
+
describe('[integration] Organisation Loading and Data Management', () => {
|
|
186
|
+
it('loads user organisations', () => {
|
|
187
|
+
const TestLoadingComponent = () => {
|
|
188
|
+
const { organisations, isLoading, error } = useOrganisations();
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<div>
|
|
192
|
+
<div data-testid="orgs-loaded">{organisations.length}</div>
|
|
193
|
+
<div data-testid="loading-status">{isLoading ? 'loading' : 'ready'}</div>
|
|
194
|
+
<div data-testid="error-status">{error ? 'error' : 'no-error'}</div>
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
render(
|
|
200
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
201
|
+
<TestLoadingComponent />
|
|
202
|
+
</TestWrapper>
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
expect(screen.getByTestId('orgs-loaded')).toBeInTheDocument();
|
|
206
|
+
expect(screen.getByTestId('loading-status')).toHaveTextContent('ready');
|
|
207
|
+
expect(screen.getByTestId('error-status')).toHaveTextContent('no-error');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('provides organisation selection functionality', () => {
|
|
211
|
+
const TestSelectionComponent = () => {
|
|
212
|
+
const { organisations, setSelectedOrganisation, selectedOrganisation } = useOrganisations();
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<div>
|
|
216
|
+
<div data-testid="selected-org">{selectedOrganisation?.name || selectedOrganisation?.display_name || 'none'}</div>
|
|
217
|
+
<button
|
|
218
|
+
data-testid="select-org-btn"
|
|
219
|
+
onClick={() => setSelectedOrganisation(organisations[0] || null)}
|
|
220
|
+
>
|
|
221
|
+
Select First
|
|
222
|
+
</button>
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
render(
|
|
228
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
229
|
+
<TestSelectionComponent />
|
|
230
|
+
</TestWrapper>
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
expect(screen.getByTestId('selected-org')).toBeInTheDocument();
|
|
234
|
+
expect(screen.getByTestId('select-org-btn')).toBeInTheDocument();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('handles organisation switching', () => {
|
|
238
|
+
const TestSwitchingComponent = () => {
|
|
239
|
+
const { organisations, setSelectedOrganisation, selectedOrganisation } = useOrganisations();
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<div>
|
|
243
|
+
<div data-testid="current-org">{selectedOrganisation?.name || selectedOrganisation?.display_name || 'none'}</div>
|
|
244
|
+
<button
|
|
245
|
+
data-testid="switch-org-btn"
|
|
246
|
+
onClick={() => {
|
|
247
|
+
if (organisations.length > 1) {
|
|
248
|
+
setSelectedOrganisation(organisations[1] || null);
|
|
249
|
+
}
|
|
250
|
+
}}
|
|
251
|
+
>
|
|
252
|
+
Switch Org
|
|
253
|
+
</button>
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
render(
|
|
259
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
260
|
+
<TestSwitchingComponent />
|
|
261
|
+
</TestWrapper>
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
expect(screen.getByTestId('current-org')).toBeInTheDocument();
|
|
265
|
+
expect(screen.getByTestId('switch-org-btn')).toBeInTheDocument();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('[integration] Organisation Context and Security', () => {
|
|
270
|
+
it('validates organisation context availability', () => {
|
|
271
|
+
const TestContextValidationComponent = () => {
|
|
272
|
+
const { hasValidOrganisationContext, selectedOrganisation } = useOrganisations();
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<div>
|
|
276
|
+
<div data-testid="valid-context">{hasValidOrganisationContext ? 'valid' : 'invalid'}</div>
|
|
277
|
+
<div data-testid="context-status">{selectedOrganisation ? 'set' : 'not-set'}</div>
|
|
278
|
+
</div>
|
|
279
|
+
);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
render(
|
|
283
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
284
|
+
<TestContextValidationComponent />
|
|
285
|
+
</TestWrapper>
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
expect(screen.getByTestId('valid-context')).toBeInTheDocument();
|
|
289
|
+
expect(screen.getByTestId('context-status')).toBeInTheDocument();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('provides organisation refresh functionality', () => {
|
|
293
|
+
const TestRefreshComponent = () => {
|
|
294
|
+
const { refreshOrganisations } = useOrganisations();
|
|
295
|
+
|
|
296
|
+
return (
|
|
297
|
+
<div>
|
|
298
|
+
<button data-testid="refresh-org-btn" onClick={() => refreshOrganisations()}>
|
|
299
|
+
Refresh Organisations
|
|
300
|
+
</button>
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
render(
|
|
306
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
307
|
+
<TestRefreshComponent />
|
|
308
|
+
</TestWrapper>
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const btn = screen.getByTestId('refresh-org-btn');
|
|
312
|
+
expect(btn).toBeInTheDocument();
|
|
313
|
+
|
|
314
|
+
// Click refresh
|
|
315
|
+
fireEvent.click(btn);
|
|
316
|
+
// Should not throw
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('maintains organisation state across re-renders', () => {
|
|
320
|
+
const TestStateStabilityComponent = () => {
|
|
321
|
+
const { selectedOrganisation, organisations } = useOrganisations();
|
|
322
|
+
|
|
323
|
+
return (
|
|
324
|
+
<div>
|
|
325
|
+
<div data-testid="org-state">
|
|
326
|
+
{selectedOrganisation ? (selectedOrganisation.name || selectedOrganisation.display_name) : 'none'}
|
|
327
|
+
</div>
|
|
328
|
+
<div data-testid="orgs-count">{organisations.length}</div>
|
|
329
|
+
</div>
|
|
330
|
+
);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const { rerender } = render(
|
|
334
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
335
|
+
<TestStateStabilityComponent />
|
|
336
|
+
</TestWrapper>
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
// Mock data returns organisations, so check for either initial state or existing orgs
|
|
340
|
+
const orgState = screen.getByTestId('org-state').textContent;
|
|
341
|
+
expect(['none', 'Test Organisation', 'Test Organisation 1']).toContain(orgState);
|
|
342
|
+
|
|
343
|
+
// Re-render
|
|
344
|
+
rerender(
|
|
345
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
346
|
+
<TestStateStabilityComponent />
|
|
347
|
+
</TestWrapper>
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
// After re-render, state should remain stable
|
|
351
|
+
const orgStateAfter = screen.getByTestId('org-state').textContent;
|
|
352
|
+
expect(orgStateAfter).toBe(orgState); // State should be stable
|
|
353
|
+
expect(screen.getByTestId('orgs-count')).toBeInTheDocument();
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
describe('[integration] Organisation Providers and Integration', () => {
|
|
358
|
+
it('integrates with auth provider', () => {
|
|
359
|
+
const TestAuthIntegrationComponent = () => {
|
|
360
|
+
const { selectedOrganisation, organisations } = useOrganisations();
|
|
361
|
+
|
|
362
|
+
return (
|
|
363
|
+
<div>
|
|
364
|
+
<div data-testid="auth-integrated">integrated</div>
|
|
365
|
+
<div data-testid="orgs-available">{organisations.length > 0 ? 'yes' : 'no'}</div>
|
|
366
|
+
</div>
|
|
367
|
+
);
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const mockUser = {
|
|
371
|
+
id: 'user-123',
|
|
372
|
+
email: 'test@example.com',
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const mockSession = {
|
|
376
|
+
access_token: 'token',
|
|
377
|
+
user: mockUser,
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
render(
|
|
381
|
+
<TestWrapper supabaseClient={mockSupabaseClient} user={mockUser} session={mockSession}>
|
|
382
|
+
<TestAuthIntegrationComponent />
|
|
383
|
+
</TestWrapper>
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
expect(screen.getByTestId('auth-integrated')).toBeInTheDocument();
|
|
387
|
+
expect(screen.getByTestId('orgs-available')).toBeInTheDocument();
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('handles missing auth gracefully', () => {
|
|
391
|
+
const TestNoAuthComponent = () => {
|
|
392
|
+
const { organisations, selectedOrganisation } = useOrganisations();
|
|
393
|
+
|
|
394
|
+
return (
|
|
395
|
+
<div>
|
|
396
|
+
<div data-testid="orgs-count">{organisations.length}</div>
|
|
397
|
+
<div data-testid="has-selection">{selectedOrganisation ? 'yes' : 'no'}</div>
|
|
398
|
+
<div data-testid="orgs-array-exists">{Array.isArray(organisations) ? 'yes' : 'no'}</div>
|
|
399
|
+
</div>
|
|
400
|
+
);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
render(
|
|
404
|
+
<TestWrapper supabaseClient={mockSupabaseClient} user={null} session={null}>
|
|
405
|
+
<TestNoAuthComponent />
|
|
406
|
+
</TestWrapper>
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
expect(screen.getByTestId('orgs-count')).toBeInTheDocument();
|
|
410
|
+
expect(screen.getByTestId('orgs-array-exists')).toHaveTextContent('yes');
|
|
411
|
+
// Mock might return data, so we just check the structure exists
|
|
412
|
+
expect(screen.getByTestId('has-selection')).toBeInTheDocument();
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('supports organisation hierarchy', () => {
|
|
416
|
+
const TestHierarchyComponent = () => {
|
|
417
|
+
const { organisations, selectedOrganisation } = useOrganisations();
|
|
418
|
+
|
|
419
|
+
return (
|
|
420
|
+
<div>
|
|
421
|
+
<div data-testid="has-organisations">{organisations.length > 0 ? 'yes' : 'no'}</div>
|
|
422
|
+
<div data-testid="hierarchy-supported">supported</div>
|
|
423
|
+
</div>
|
|
424
|
+
);
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
render(
|
|
428
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
429
|
+
<TestHierarchyComponent />
|
|
430
|
+
</TestWrapper>
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
expect(screen.getByTestId('has-organisations')).toBeInTheDocument();
|
|
434
|
+
expect(screen.getByTestId('hierarchy-supported')).toHaveTextContent('supported');
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
describe('[integration] Error Handling and Edge Cases', () => {
|
|
439
|
+
it('handles organisation loading errors', () => {
|
|
440
|
+
const TestErrorComponent = () => {
|
|
441
|
+
const { error, organisations } = useOrganisations();
|
|
442
|
+
|
|
443
|
+
return (
|
|
444
|
+
<div>
|
|
445
|
+
<div data-testid="error-state">{error ? 'has-error' : 'no-error'}</div>
|
|
446
|
+
<div data-testid="orgs-available">{organisations.length}</div>
|
|
447
|
+
</div>
|
|
448
|
+
);
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
render(
|
|
452
|
+
<TestWrapper supabaseClient={null}>
|
|
453
|
+
<TestErrorComponent />
|
|
454
|
+
</TestWrapper>
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
expect(screen.getByTestId('error-state')).toBeInTheDocument();
|
|
458
|
+
expect(screen.getByTestId('orgs-available')).toBeInTheDocument();
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('maintains stability with rapid operations', () => {
|
|
462
|
+
const TestRapidOpsComponent = () => {
|
|
463
|
+
const { setSelectedOrganisation, refreshOrganisations, organisations } = useOrganisations();
|
|
464
|
+
|
|
465
|
+
return (
|
|
466
|
+
<div>
|
|
467
|
+
<button
|
|
468
|
+
data-testid="rapid-ops-btn"
|
|
469
|
+
onClick={() => {
|
|
470
|
+
setSelectedOrganisation(organisations[0] || null);
|
|
471
|
+
refreshOrganisations();
|
|
472
|
+
}}
|
|
473
|
+
>
|
|
474
|
+
Rapid Ops
|
|
475
|
+
</button>
|
|
476
|
+
</div>
|
|
477
|
+
);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
render(
|
|
481
|
+
<TestWrapper supabaseClient={mockSupabaseClient}>
|
|
482
|
+
<TestRapidOpsComponent />
|
|
483
|
+
</TestWrapper>
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
const btn = screen.getByTestId('rapid-ops-btn');
|
|
487
|
+
fireEvent.click(btn);
|
|
488
|
+
fireEvent.click(btn);
|
|
489
|
+
fireEvent.click(btn);
|
|
490
|
+
|
|
491
|
+
expect(btn).toBeInTheDocument();
|
|
492
|
+
});
|
|
493
|
+
});
|
|
184
494
|
});
|