@jmruthers/pace-core 0.5.54 → 0.5.56
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/README.md +0 -4
- package/dist/{DataTable-7FMFXA7A.js → DataTable-DJQTKX33.js} +11 -11
- package/dist/{PublicLoadingSpinner-Bq_-BeK-.d.ts → PublicLoadingSpinner-SL8WaQN7.d.ts} +2 -21
- package/dist/{api-H5A3H4IR.js → api-LUNF5O6M.js} +3 -3
- package/dist/{appConfig-BVGyuvI7.d.ts → appConfig-DjpeG6P-.d.ts} +9 -1
- package/dist/{appNameResolver-7GHF5ED2.js → appNameResolver-UURKN7NF.js} +2 -2
- package/dist/{audit-BUW3LMJB.js → audit-6TOCAMKO.js} +2 -2
- package/dist/{chunk-NRK4AIHQ.js → chunk-2DFCT6D3.js} +3 -3
- package/dist/{chunk-GIO7BFE7.js → chunk-3JKVVLD3.js} +66 -169
- package/dist/{chunk-GIO7BFE7.js.map → chunk-3JKVVLD3.js.map} +1 -1
- package/dist/{chunk-MZBUOP4P.js → chunk-5BSLGBYI.js} +4 -3
- package/dist/chunk-5BSLGBYI.js.map +1 -0
- package/dist/{chunk-I5Z3QH5X.js → chunk-66C4BSAY.js} +2 -2
- package/dist/{chunk-I5Z3QH5X.js.map → chunk-66C4BSAY.js.map} +1 -1
- package/dist/{chunk-EL2O4IUX.js → chunk-ASXSJGPW.js} +20 -24
- package/dist/{chunk-EL2O4IUX.js.map → chunk-ASXSJGPW.js.map} +1 -1
- package/dist/{chunk-7BNPOCLL.js → chunk-B2WTCLCV.js} +6 -2
- package/dist/chunk-B2WTCLCV.js.map +1 -0
- package/dist/{chunk-WJARTBCT.js → chunk-D7ARGIA3.js} +16 -7
- package/dist/chunk-D7ARGIA3.js.map +1 -0
- package/dist/{chunk-MYP2EGHX.js → chunk-GIDCWCHF.js} +21 -14
- package/dist/chunk-GIDCWCHF.js.map +1 -0
- package/dist/{chunk-MSFACPQQ.js → chunk-HYNGIE5T.js} +11 -11
- package/dist/{chunk-MSFACPQQ.js.map → chunk-HYNGIE5T.js.map} +1 -1
- package/dist/{chunk-TRIZ7IB7.js → chunk-I5GID3EX.js} +148 -288
- package/dist/chunk-I5GID3EX.js.map +1 -0
- package/dist/{chunk-GWSBHC4J.js → chunk-KLPVOPRI.js} +261 -38
- package/dist/chunk-KLPVOPRI.js.map +1 -0
- package/dist/{chunk-BC3S53OZ.js → chunk-N6XMGSGD.js} +30 -14
- package/dist/chunk-N6XMGSGD.js.map +1 -0
- package/dist/{chunk-6MTY77WU.js → chunk-QB4GXDUM.js} +3 -3
- package/dist/{chunk-YDJW5XTN.js → chunk-STT7INZR.js} +25 -1
- package/dist/chunk-STT7INZR.js.map +1 -0
- package/dist/{chunk-NYUJ4FJR.js → chunk-UETTVYKU.js} +7 -7
- package/dist/chunk-UETTVYKU.js.map +1 -0
- package/dist/{chunk-22KLBHPS.js → chunk-W66AZIOH.js} +2 -2
- package/dist/chunk-W66AZIOH.js.map +1 -0
- package/dist/{chunk-NZ655MWE.js → chunk-YEHO6FDW.js} +5 -4
- package/dist/chunk-YEHO6FDW.js.map +1 -0
- package/dist/{chunk-SS3E6QLB.js → chunk-YNUBMSMV.js} +2 -2
- package/dist/chunk-YNUBMSMV.js.map +1 -0
- package/dist/{chunk-74C6SNEC.js → chunk-ZPK5656W.js} +3 -3
- package/dist/{chunk-74C6SNEC.js.map → chunk-ZPK5656W.js.map} +1 -1
- package/dist/components.d.ts +22 -899
- package/dist/components.js +436 -3118
- package/dist/components.js.map +1 -1
- package/dist/file-reference-9xUOnwyt.d.ts +70 -0
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +10 -10
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +49 -9
- package/dist/index.js +190 -25
- package/dist/index.js.map +1 -1
- package/dist/{organisation-CO3Sh3_D.d.ts → organisation-t-vvQC3g.d.ts} +1 -8
- package/dist/providers.d.ts +2 -2
- package/dist/providers.js +5 -5
- package/dist/rbac/index.d.ts +65 -46
- package/dist/rbac/index.js +10 -12
- package/dist/styles/core.css +0 -125
- package/dist/types.d.ts +2 -1
- package/dist/types.js +3 -1
- package/dist/types.js.map +1 -1
- package/dist/{usePublicRouteParams-B2OcAsur.d.ts → usePublicRouteParams-CdoFxnJK.d.ts} +1 -1
- package/dist/utils.d.ts +3 -4
- package/dist/utils.js +44 -13
- package/dist/utils.js.map +1 -1
- package/docs/FILE_REFERENCE_SYSTEM.md +440 -0
- package/docs/INDEX.md +7 -5
- package/docs/README.md +0 -1
- package/docs/api/README.md +0 -4
- 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 +2 -2
- package/docs/api/classes/PublicErrorBoundary.md +1 -1
- package/docs/api/classes/RBACAuditManager.md +12 -12
- package/docs/api/classes/RBACCache.md +1 -1
- package/docs/api/classes/RBACEngine.md +6 -6
- 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 +281 -0
- package/docs/api/interfaces/AggregateConfig.md +1 -1
- package/docs/api/interfaces/ButtonProps.md +1 -1
- package/docs/api/interfaces/CardProps.md +1 -1
- 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/EventContextType.md +1 -1
- package/docs/api/interfaces/EventLogoProps.md +1 -1
- package/docs/api/interfaces/EventProviderProps.md +1 -1
- package/docs/api/interfaces/FileSizeLimits.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 +1 -1
- package/docs/api/interfaces/LabelProps.md +1 -1
- package/docs/api/interfaces/LoginFormProps.md +1 -1
- package/docs/api/interfaces/NavigationAccessRecord.md +2 -2
- 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 +1 -1
- package/docs/api/interfaces/OrganisationMembership.md +1 -1
- package/docs/api/interfaces/OrganisationProviderProps.md +1 -1
- 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 +4 -4
- package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
- package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
- package/docs/api/interfaces/PublicLoadingSpinnerProps.md +1 -1
- 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 +1 -1
- 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 +2 -2
- package/docs/api/interfaces/RouteConfig.md +2 -2
- 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/ToastActionElement.md +1 -1
- package/docs/api/interfaces/ToastProps.md +1 -1
- package/docs/api/interfaces/UnifiedAuthContextType.md +1 -1
- package/docs/api/interfaces/UnifiedAuthProviderProps.md +1 -1
- 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 +1 -1
- package/docs/api/interfaces/UserMenuProps.md +1 -1
- package/docs/api/interfaces/UserProfile.md +1 -1
- package/docs/api/modules.md +204 -200
- package/docs/api-reference/components.md +141 -163
- package/docs/api-reference/hooks.md +347 -0
- package/docs/core-concepts/rbac-system.md +69 -16
- package/docs/getting-started/examples/basic-auth-app.md +0 -1
- package/docs/implementation-guides/datatable-rbac-usage.md +12 -11
- package/docs/implementation-guides/file-upload-storage.md +733 -0
- package/docs/implementation-guides/inactivity-tracking.md +779 -0
- package/docs/implementation-guides/organisation-security.md +748 -0
- package/docs/implementation-guides/public-pages-advanced.md +1022 -0
- package/docs/migration/MIGRATION_GUIDE.md +684 -0
- package/docs/migration/README.md +13 -2
- package/docs/migration/rbac-migration.md +73 -0
- package/docs/rbac/examples/rbac-rls-integration-example.md +11 -13
- package/docs/style-guide.md +269 -1
- package/package.json +1 -1
- package/src/__tests__/TESTING_GUIDELINES.md +331 -18
- package/src/__tests__/helpers/supabaseMock.ts +99 -0
- package/src/__tests__/rbac/PagePermissionGuard.test.tsx +10 -7
- package/src/__tests__/shared.ts +6 -0
- package/src/components/DataTable/components/ActionButtons.tsx +2 -2
- package/src/components/DataTable/components/DataTableCore.tsx +2 -2
- package/src/components/DataTable/components/UnifiedTableBody.tsx +1 -1
- package/src/components/DataTable/utils/debugTools.ts +2 -2
- package/src/components/Dialog/Dialog.test.tsx +12 -2
- package/src/components/ErrorBoundary/ErrorBoundary.test.tsx +6 -6
- package/src/components/ErrorBoundary/ErrorBoundary.tsx +2 -2
- package/src/components/FileDisplay.tsx +233 -0
- package/src/components/FileUpload.tsx +176 -0
- package/src/components/Footer/Footer.test.tsx +7 -7
- package/src/components/NavigationMenu/NavigationMenu.test.tsx +13 -6
- package/src/components/OrganisationSelector/OrganisationSelector.test.tsx +30 -3
- package/src/components/OrganisationSelector/OrganisationSelector.tsx +1 -1
- package/src/components/PaceAppLayout/__tests__/PaceAppLayout.rbac.test.tsx +558 -0
- package/src/components/PublicLayout/PublicErrorBoundary.tsx +1 -1
- package/src/components/PublicLayout/PublicPageDebugger.tsx +2 -2
- package/src/components/PublicLayout/PublicPageDiagnostic.tsx +2 -2
- package/src/components/PublicLayout/PublicPageProvider.tsx +2 -2
- package/src/components/Select/Select.test.tsx +50 -15
- package/src/components/SuperAdminGuard.tsx +2 -2
- package/src/components/__tests__/SuperAdminGuard.test.tsx +559 -0
- package/src/components/index.ts +0 -183
- package/src/hooks/__tests__/useOrganisationPermissions.unit.test.tsx +2 -2
- package/src/hooks/__tests__/usePermissionCache.unit.test.ts +1 -1
- package/src/hooks/__tests__/useRBAC.unit.test.ts +191 -138
- package/src/hooks/public/usePublicEvent.ts +2 -2
- package/src/hooks/useAppConfig.ts +3 -3
- package/src/hooks/useComponentPerformance.ts +1 -1
- package/src/hooks/useDataTablePerformance.ts +1 -1
- package/src/hooks/useFileReference.ts +232 -0
- package/src/hooks/useOrganisationPermissions.test.ts +254 -344
- package/src/hooks/useOrganisationPermissions.ts +15 -7
- package/src/hooks/useOrganisationSecurity.test.ts +390 -402
- package/src/hooks/usePerformanceMonitor.ts +1 -1
- package/src/hooks/usePermissionCache.test.ts +264 -395
- package/src/hooks/usePermissionCache.ts +34 -4
- package/src/hooks/useSecureDataAccess.test.ts +486 -0
- package/src/hooks/useSecureDataAccess.ts +4 -1
- package/src/providers/InactivityProvider.tsx +2 -2
- package/src/providers/OrganisationProvider.test.simple.tsx +168 -0
- package/src/providers/OrganisationProvider.test.tsx +168 -0
- package/src/providers/OrganisationProvider.tsx +25 -31
- package/src/providers/UnifiedAuthProvider.test.simple.tsx +205 -0
- package/src/providers/UnifiedAuthProvider.test.tsx +128 -0
- package/src/providers/__tests__/InactivityProvider.test.tsx +3 -4
- package/src/providers/__tests__/OrganisationProvider.test.tsx +19 -14
- package/src/rbac/__tests__/integration.authflow.test.tsx +123 -0
- package/src/rbac/__tests__/integration.navigation.test.tsx +72 -0
- package/src/rbac/__tests__/integration.securedata.test.tsx +92 -0
- package/src/rbac/__tests__/integration.smoke.test.tsx +73 -0
- package/src/rbac/__tests__/rbac-core.test.tsx +26 -22
- package/src/rbac/__tests__/rbac-engine-core-logic.test.ts +411 -0
- package/src/rbac/__tests__/rbac-engine-simplified.test.ts +285 -0
- package/src/rbac/__tests__/rbac-functions.test.ts +655 -0
- package/src/rbac/__tests__/rbac-integration.test.ts +532 -0
- package/src/rbac/__tests__/scenarios.user-role.test.tsx +196 -0
- package/src/rbac/api.test.ts +6 -6
- package/src/rbac/api.ts +2 -2
- package/src/rbac/audit.test.ts +485 -0
- package/src/rbac/audit.ts +7 -1
- package/src/rbac/cache-invalidation.ts +318 -0
- package/src/rbac/cache.test.ts +286 -0
- package/src/rbac/components/EnhancedNavigationMenu.test.tsx +559 -0
- package/src/rbac/components/EnhancedNavigationMenu.tsx +29 -23
- package/src/rbac/components/NavigationProvider.test.tsx +449 -0
- package/src/rbac/components/PagePermissionGuard.tsx +4 -4
- package/src/rbac/components/PagePermissionProvider.test.tsx +479 -0
- package/src/rbac/components/SecureDataProvider.test.tsx +511 -0
- package/src/rbac/components/__tests__/PagePermissionGuard.race-condition.test.tsx +159 -430
- package/src/rbac/components/__tests__/PagePermissionGuard.test.tsx +4 -5
- package/src/rbac/components/__tests__/PagePermissionGuard.verification.test.tsx +112 -118
- package/src/rbac/config.test.ts +410 -0
- package/src/rbac/engine.test.simple.ts +237 -0
- package/src/rbac/engine.test.ts +233 -0
- package/src/rbac/engine.ts +37 -41
- package/src/rbac/examples/CompleteRBACExample.tsx +3 -3
- package/src/rbac/examples/EventBasedApp.tsx +4 -4
- package/src/rbac/hooks/useRBAC.simple.test.ts +16 -0
- package/src/rbac/hooks/useRBAC.test.ts +207 -455
- package/src/rbac/hooks/useRBAC.ts +30 -22
- package/src/rbac/permissions.test.ts +128 -0
- package/src/rbac/permissions.ts +56 -141
- package/src/rbac/providers/RBACProvider.tsx +1 -1
- package/src/rbac/secureClient.test.ts +444 -0
- package/src/rbac/security.test.ts +390 -0
- package/src/rbac/security.ts +1 -1
- package/src/rbac/types.test.ts +382 -0
- package/src/rbac/types.ts +2 -2
- package/src/styles/core.css +0 -125
- package/src/types/file-reference.ts +77 -0
- package/src/types/rbac-functions.ts +290 -0
- package/src/types/supabase.ts +10 -28
- package/src/types/unified.ts +4 -1
- package/src/utils/__tests__/bundleAnalysis.unit.test.ts +81 -55
- package/src/utils/__tests__/lazyLoad.unit.test.tsx +21 -12
- package/src/utils/__tests__/organisationContext.unit.test.ts +13 -7
- package/src/utils/__tests__/performanceBudgets.unit.test.ts +3 -3
- package/src/utils/__tests__/sessionTracking.unit.test.ts +32 -12
- package/src/utils/appConfig.ts +1 -1
- package/src/utils/appIdResolver.test.ts +503 -0
- package/src/utils/appIdResolver.ts +1 -1
- package/src/utils/appNameResolver.test.ts +494 -0
- package/src/utils/appNameResolver.ts +3 -2
- package/src/utils/bundleAnalysis.ts +3 -3
- package/src/utils/debugLogger.ts +1 -1
- package/src/utils/file-reference.ts +263 -0
- package/src/utils/formatDate.test.ts +2 -2
- package/src/utils/organisationContext.test.ts +340 -0
- package/src/utils/organisationContext.ts +19 -6
- package/src/utils/performanceBudgets.ts +2 -2
- package/src/utils/permissionUtils.test.ts +393 -0
- package/src/utils/permissionUtils.ts +5 -2
- package/src/utils/secureDataAccess.test.ts +715 -0
- package/src/utils/secureDataAccess.ts +21 -5
- package/src/utils/sessionTracking.ts +34 -4
- package/src/utils/storage/__tests__/helpers.unit.test.ts +328 -0
- package/src/utils/storage/__tests__/index.unit.test.ts +16 -0
- package/src/utils/storage/helpers.ts +20 -25
- package/src/utils/storage/index.ts +29 -1
- package/src/vite-env.d.ts +17 -0
- package/dist/chunk-22KLBHPS.js.map +0 -1
- package/dist/chunk-7BNPOCLL.js.map +0 -1
- package/dist/chunk-BC3S53OZ.js.map +0 -1
- package/dist/chunk-GWSBHC4J.js.map +0 -1
- package/dist/chunk-MYP2EGHX.js.map +0 -1
- package/dist/chunk-MZBUOP4P.js.map +0 -1
- package/dist/chunk-NYUJ4FJR.js.map +0 -1
- package/dist/chunk-NZ655MWE.js.map +0 -1
- package/dist/chunk-SS3E6QLB.js.map +0 -1
- package/dist/chunk-TRIZ7IB7.js.map +0 -1
- package/dist/chunk-WJARTBCT.js.map +0 -1
- package/dist/chunk-YDJW5XTN.js.map +0 -1
- package/docs/print-components/README.md +0 -258
- package/docs/print-components/api-reference.md +0 -636
- package/docs/print-components/examples/README.md +0 -204
- package/docs/print-components/examples/basic-report.tsx +0 -92
- package/docs/print-components/examples/card-catalog.tsx +0 -149
- package/docs/print-components/examples/cover-page-report.tsx +0 -163
- package/docs/print-components/quick-start.md +0 -363
- package/src/components/PrintButton/PrintButton.tsx +0 -321
- package/src/components/PrintButton/PrintButtonGroup.tsx +0 -84
- package/src/components/PrintButton/PrintToolbar.tsx +0 -94
- package/src/components/PrintButton/__tests__/PrintButton.test.tsx +0 -271
- package/src/components/PrintButton/examples/PrintButtonShowcase.tsx +0 -438
- package/src/components/PrintButton/index.ts +0 -33
- package/src/components/PrintButton/types.ts +0 -173
- package/src/components/PrintCard/PrintCard.tsx +0 -154
- package/src/components/PrintCard/PrintCardContent.tsx +0 -57
- package/src/components/PrintCard/PrintCardFooter.tsx +0 -60
- package/src/components/PrintCard/PrintCardGrid.tsx +0 -91
- package/src/components/PrintCard/PrintCardHeader.tsx +0 -78
- package/src/components/PrintCard/PrintCardImage.tsx +0 -81
- package/src/components/PrintCard/examples/PrintCardShowcase.tsx +0 -239
- package/src/components/PrintCard/index.ts +0 -34
- package/src/components/PrintCard/types.ts +0 -171
- package/src/components/PrintDataTable/PrintDataTable.tsx +0 -215
- package/src/components/PrintDataTable/PrintTableGroup.tsx +0 -90
- package/src/components/PrintDataTable/PrintTableRow.tsx +0 -76
- package/src/components/PrintDataTable/index.ts +0 -25
- package/src/components/PrintDataTable/types.ts +0 -67
- package/src/components/PrintFooter/PrintFooter.tsx +0 -183
- package/src/components/PrintFooter/PrintFooterContent.tsx +0 -71
- package/src/components/PrintFooter/PrintFooterInfo.tsx +0 -86
- package/src/components/PrintFooter/PrintPageNumber.tsx +0 -90
- package/src/components/PrintFooter/examples/PrintFooterShowcase.tsx +0 -390
- package/src/components/PrintFooter/index.ts +0 -30
- package/src/components/PrintFooter/types.ts +0 -149
- package/src/components/PrintGrid/PrintGrid.tsx +0 -180
- package/src/components/PrintGrid/PrintGridBreakpoint.tsx +0 -109
- package/src/components/PrintGrid/PrintGridContainer.tsx +0 -128
- package/src/components/PrintGrid/PrintGridItem.tsx +0 -220
- package/src/components/PrintGrid/examples/PrintGridShowcase.tsx +0 -359
- package/src/components/PrintGrid/index.ts +0 -31
- package/src/components/PrintGrid/types.ts +0 -159
- package/src/components/PrintHeader/PrintCoverHeader.tsx +0 -230
- package/src/components/PrintHeader/PrintHeader.tsx +0 -150
- package/src/components/PrintHeader/index.ts +0 -17
- package/src/components/PrintHeader/types.ts +0 -42
- package/src/components/PrintLayout/PrintLayout.tsx +0 -122
- package/src/components/PrintLayout/PrintLayoutContext.tsx +0 -66
- package/src/components/PrintLayout/PrintPageBreak.tsx +0 -52
- package/src/components/PrintLayout/examples/PrintShowcase.tsx +0 -230
- package/src/components/PrintLayout/index.ts +0 -19
- package/src/components/PrintLayout/types.ts +0 -37
- package/src/components/PrintPageBreak/PrintPageBreak.tsx +0 -120
- package/src/components/PrintPageBreak/PrintPageBreakGroup.tsx +0 -90
- package/src/components/PrintPageBreak/PrintPageBreakIndicator.tsx +0 -112
- package/src/components/PrintPageBreak/examples/PrintPageBreakShowcase.tsx +0 -279
- package/src/components/PrintPageBreak/index.ts +0 -23
- package/src/components/PrintPageBreak/types.ts +0 -94
- package/src/components/PrintSection/PrintColumn.tsx +0 -104
- package/src/components/PrintSection/PrintDivider.tsx +0 -101
- package/src/components/PrintSection/PrintSection.tsx +0 -129
- package/src/components/PrintSection/PrintSectionContent.tsx +0 -75
- package/src/components/PrintSection/PrintSectionHeader.tsx +0 -97
- package/src/components/PrintSection/examples/PrintSectionShowcase.tsx +0 -258
- package/src/components/PrintSection/index.ts +0 -33
- package/src/components/PrintSection/types.ts +0 -155
- package/src/components/PrintText/PrintText.tsx +0 -116
- package/src/components/PrintText/index.ts +0 -16
- package/src/components/PrintText/types.ts +0 -24
- package/src/rbac/__tests__/integration.test.tsx +0 -218
- package/src/utils/print/PrintDataProcessor.ts +0 -390
- package/src/utils/print/examples/PrintUtilitiesShowcase.tsx +0 -397
- package/src/utils/print/index.ts +0 -29
- package/src/utils/print/types.ts +0 -196
- package/src/utils/print/usePrintOptimization.ts +0 -272
- /package/dist/{DataTable-7FMFXA7A.js.map → DataTable-DJQTKX33.js.map} +0 -0
- /package/dist/{api-H5A3H4IR.js.map → api-LUNF5O6M.js.map} +0 -0
- /package/dist/{appNameResolver-7GHF5ED2.js.map → appNameResolver-UURKN7NF.js.map} +0 -0
- /package/dist/{audit-BUW3LMJB.js.map → audit-6TOCAMKO.js.map} +0 -0
- /package/dist/{chunk-NRK4AIHQ.js.map → chunk-2DFCT6D3.js.map} +0 -0
- /package/dist/{chunk-6MTY77WU.js.map → chunk-QB4GXDUM.js.map} +0 -0
|
@@ -1,478 +1,207 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file PagePermissionGuard
|
|
2
|
+
* @file PagePermissionGuard Simplified Tests
|
|
3
3
|
* @package @jmruthers/pace-core
|
|
4
|
-
* @module RBAC/Components/PagePermissionGuard
|
|
4
|
+
* @module RBAC/Components/PagePermissionGuard
|
|
5
5
|
* @since 2.0.0
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* race conditions and UI state transitions without infinite loops.
|
|
7
|
+
* Simplified tests for PagePermissionGuard component.
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
10
|
import React from 'react';
|
|
12
|
-
import { render, screen
|
|
13
|
-
import { vi } from 'vitest';
|
|
11
|
+
import { render, screen } from '@testing-library/react';
|
|
12
|
+
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
14
13
|
import { PagePermissionGuard } from '../PagePermissionGuard';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
appId: 'app-123'
|
|
49
|
-
};
|
|
14
|
+
import { useCan } from '../../hooks';
|
|
15
|
+
|
|
16
|
+
// Mock the hooks with simple implementations
|
|
17
|
+
vi.mock('../../../providers/UnifiedAuthProvider', () => ({
|
|
18
|
+
useUnifiedAuth: () => ({
|
|
19
|
+
user: { id: 'user-123', email: 'test@example.com' },
|
|
20
|
+
isAuthenticated: true,
|
|
21
|
+
isLoading: false,
|
|
22
|
+
selectedOrganisationId: 'org-123',
|
|
23
|
+
selectedEventId: undefined,
|
|
24
|
+
supabase: {
|
|
25
|
+
from: vi.fn(() => ({
|
|
26
|
+
select: vi.fn(() => ({
|
|
27
|
+
eq: vi.fn(() => ({
|
|
28
|
+
single: vi.fn(() => Promise.resolve({ data: { id: 'app-123', name: 'test-app', is_active: true }, error: null }))
|
|
29
|
+
}))
|
|
30
|
+
}))
|
|
31
|
+
}))
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
vi.mock('../../hooks', () => ({
|
|
37
|
+
useCan: vi.fn()
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
// Mock the app name resolver
|
|
41
|
+
vi.mock('../../../utils/appNameResolver', () => ({
|
|
42
|
+
getCurrentAppName: () => 'test-app'
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
describe('PagePermissionGuard Simplified Tests', () => {
|
|
46
|
+
const mockUseCan = vi.mocked(useCan);
|
|
50
47
|
|
|
51
48
|
beforeEach(() => {
|
|
52
|
-
// Reset mocks
|
|
53
49
|
vi.clearAllMocks();
|
|
54
50
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
selectedOrganisationId: 'org-123',
|
|
59
|
-
selectedEventId: 'event-123',
|
|
60
|
-
supabase: {} as any,
|
|
61
|
-
isAuthenticated: true,
|
|
51
|
+
// Set up default mock behavior
|
|
52
|
+
mockUseCan.mockReturnValue({
|
|
53
|
+
can: false,
|
|
62
54
|
isLoading: false,
|
|
63
55
|
error: null,
|
|
64
|
-
signOut: vi.fn(),
|
|
65
|
-
refreshSession: vi.fn(),
|
|
66
|
-
hasPermission: vi.fn(),
|
|
67
|
-
hasRole: vi.fn(),
|
|
68
|
-
hasAccessLevel: vi.fn(),
|
|
69
|
-
validatePermission: vi.fn(),
|
|
70
|
-
canAccess: vi.fn(),
|
|
71
|
-
setSelectedEventId: vi.fn(),
|
|
72
|
-
appName: 'test-app',
|
|
73
|
-
hasErrors: false
|
|
74
56
|
});
|
|
75
57
|
});
|
|
76
58
|
|
|
77
|
-
describe('
|
|
78
|
-
it('
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
mockUseCan.mockImplementation(() => {
|
|
85
|
-
callCount++;
|
|
86
|
-
console.log(`[TEST] useCan call #${callCount}: can=${canValue}, isLoading=${isLoadingValue}`);
|
|
87
|
-
|
|
88
|
-
// Simulate the race condition: first call returns false, second call returns true
|
|
89
|
-
if (callCount === 1) {
|
|
90
|
-
canValue = false;
|
|
91
|
-
isLoadingValue = false;
|
|
92
|
-
} else if (callCount === 2) {
|
|
93
|
-
canValue = true;
|
|
94
|
-
isLoadingValue = false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
can: canValue,
|
|
99
|
-
isLoading: isLoadingValue,
|
|
100
|
-
error: null
|
|
101
|
-
};
|
|
59
|
+
describe('Basic Rendering', () => {
|
|
60
|
+
it('renders children when permission is granted', () => {
|
|
61
|
+
mockUseCan.mockReturnValue({
|
|
62
|
+
can: true,
|
|
63
|
+
isLoading: false,
|
|
64
|
+
error: null,
|
|
102
65
|
});
|
|
103
|
-
|
|
104
|
-
const TestComponent = () => {
|
|
105
|
-
renderCount++;
|
|
106
|
-
console.log(`[TEST] Component render #${renderCount}`);
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<PagePermissionGuard pageName="meals" operation="read">
|
|
110
|
-
<div data-testid="protected-content">Protected Content</div>
|
|
111
|
-
</PagePermissionGuard>
|
|
112
|
-
);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const { rerender } = render(<TestComponent />);
|
|
116
|
-
|
|
117
|
-
// Initial render should show loading (or content if scope resolves immediately)
|
|
118
|
-
// Note: In test environment, scope resolution may be synchronous
|
|
119
|
-
const hasLoading = screen.queryByText('Checking permissions...');
|
|
120
|
-
const hasContent = screen.queryByTestId('protected-content');
|
|
121
66
|
|
|
122
|
-
|
|
123
|
-
|
|
67
|
+
render(
|
|
68
|
+
<PagePermissionGuard
|
|
69
|
+
pageName="users"
|
|
70
|
+
operation="read"
|
|
71
|
+
scope={{ organisationId: 'org-123' }}
|
|
72
|
+
>
|
|
73
|
+
<div data-testid="protected-content">Protected Content</div>
|
|
74
|
+
</PagePermissionGuard>
|
|
75
|
+
);
|
|
124
76
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// Simulate the second permission check (this is where the race condition occurred)
|
|
131
|
-
act(() => {
|
|
132
|
-
// Trigger a re-render to simulate the second useCan call
|
|
133
|
-
rerender(<TestComponent />);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Wait for content to be stable (mock may not be applied in test environment)
|
|
137
|
-
await waitFor(() => {
|
|
138
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// Now the content should be visible
|
|
142
|
-
await waitFor(() => {
|
|
143
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
144
|
-
expect(screen.queryByText('Checking permissions...')).not.toBeInTheDocument();
|
|
145
|
-
expect(screen.queryByText('Access Denied')).not.toBeInTheDocument();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Verify we didn't have infinite loops
|
|
149
|
-
expect(callCount).toBeLessThanOrEqual(3); // Should be exactly 2 calls, but allow some tolerance
|
|
150
|
-
expect(renderCount).toBeLessThanOrEqual(5); // Should be reasonable number of renders
|
|
151
|
-
|
|
152
|
-
// Verify that the component rendered correctly without infinite loops
|
|
153
|
-
// The main goal is to ensure no infinite loops and proper final state
|
|
77
|
+
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
78
|
+
expect(screen.getByText('Protected Content')).toBeInTheDocument();
|
|
154
79
|
});
|
|
155
80
|
|
|
156
|
-
it('
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
can: canValue,
|
|
178
|
-
isLoading: isLoadingValue,
|
|
179
|
-
error: null
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const TestComponent = () => {
|
|
184
|
-
renderCount++;
|
|
185
|
-
return (
|
|
186
|
-
<PagePermissionGuard pageName="meals" operation="read">
|
|
187
|
-
<div data-testid="protected-content">Protected Content</div>
|
|
188
|
-
</PagePermissionGuard>
|
|
189
|
-
);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const { rerender } = render(<TestComponent />);
|
|
193
|
-
|
|
194
|
-
// Simulate multiple rapid re-renders
|
|
195
|
-
for (let i = 0; i < 5; i++) {
|
|
196
|
-
act(() => {
|
|
197
|
-
rerender(<TestComponent />);
|
|
198
|
-
});
|
|
199
|
-
await new Promise(resolve => setTimeout(resolve, 10)); // Small delay
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Wait for final state
|
|
203
|
-
await waitFor(() => {
|
|
204
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// Verify no infinite loops
|
|
208
|
-
expect(callCount).toBeLessThanOrEqual(6); // Should be reasonable
|
|
209
|
-
expect(renderCount).toBeLessThanOrEqual(10); // Should be reasonable
|
|
81
|
+
it('renders access denied when permission is not granted', () => {
|
|
82
|
+
mockUseCan.mockReturnValue({
|
|
83
|
+
can: false,
|
|
84
|
+
isLoading: false,
|
|
85
|
+
error: null,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
render(
|
|
89
|
+
<PagePermissionGuard
|
|
90
|
+
pageName="users"
|
|
91
|
+
operation="delete"
|
|
92
|
+
scope={{ organisationId: 'org-123' }}
|
|
93
|
+
>
|
|
94
|
+
<div data-testid="protected-content">Protected Content</div>
|
|
95
|
+
</PagePermissionGuard>
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(screen.getByText('Access Denied')).toBeInTheDocument();
|
|
99
|
+
expect(screen.queryByTestId('protected-content')).not.toBeInTheDocument();
|
|
210
100
|
});
|
|
211
101
|
|
|
212
|
-
it('
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
mockUseUnifiedAuth.mockImplementation(() => {
|
|
218
|
-
if (!scopeResolved) {
|
|
219
|
-
// Simulate scope not yet resolved
|
|
220
|
-
return {
|
|
221
|
-
user: mockUser,
|
|
222
|
-
selectedOrganisationId: null,
|
|
223
|
-
selectedEventId: null,
|
|
224
|
-
supabase: {} as any,
|
|
225
|
-
isAuthenticated: true,
|
|
226
|
-
isLoading: true,
|
|
227
|
-
error: null,
|
|
228
|
-
signOut: vi.fn(),
|
|
229
|
-
refreshSession: vi.fn(),
|
|
230
|
-
hasPermission: vi.fn(),
|
|
231
|
-
hasRole: vi.fn(),
|
|
232
|
-
hasAccessLevel: vi.fn(),
|
|
233
|
-
validatePermission: vi.fn(),
|
|
234
|
-
canAccess: vi.fn(),
|
|
235
|
-
setSelectedEventId: vi.fn(),
|
|
236
|
-
appName: 'test-app',
|
|
237
|
-
hasErrors: false
|
|
238
|
-
};
|
|
239
|
-
} else {
|
|
240
|
-
// Scope is resolved
|
|
241
|
-
return {
|
|
242
|
-
user: mockUser,
|
|
243
|
-
selectedOrganisationId: 'org-123',
|
|
244
|
-
selectedEventId: 'event-123',
|
|
245
|
-
supabase: {} as any,
|
|
246
|
-
isAuthenticated: true,
|
|
247
|
-
isLoading: false,
|
|
248
|
-
error: null,
|
|
249
|
-
signOut: vi.fn(),
|
|
250
|
-
refreshSession: vi.fn(),
|
|
251
|
-
hasPermission: vi.fn(),
|
|
252
|
-
hasRole: vi.fn(),
|
|
253
|
-
hasAccessLevel: vi.fn(),
|
|
254
|
-
validatePermission: vi.fn(),
|
|
255
|
-
canAccess: vi.fn(),
|
|
256
|
-
setSelectedEventId: vi.fn(),
|
|
257
|
-
appName: 'test-app',
|
|
258
|
-
hasErrors: false
|
|
259
|
-
};
|
|
260
|
-
}
|
|
102
|
+
it('renders loading state when checking permissions', () => {
|
|
103
|
+
mockUseCan.mockReturnValue({
|
|
104
|
+
can: false,
|
|
105
|
+
isLoading: true,
|
|
106
|
+
error: null,
|
|
261
107
|
});
|
|
262
108
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const TestComponent = () => {
|
|
273
|
-
renderCount++;
|
|
274
|
-
return (
|
|
275
|
-
<PagePermissionGuard pageName="meals" operation="read">
|
|
276
|
-
<div data-testid="protected-content">Protected Content</div>
|
|
277
|
-
</PagePermissionGuard>
|
|
278
|
-
);
|
|
279
|
-
};
|
|
109
|
+
render(
|
|
110
|
+
<PagePermissionGuard
|
|
111
|
+
pageName="users"
|
|
112
|
+
operation="read"
|
|
113
|
+
scope={{ organisationId: 'org-123' }}
|
|
114
|
+
>
|
|
115
|
+
<div data-testid="protected-content">Protected Content</div>
|
|
116
|
+
</PagePermissionGuard>
|
|
117
|
+
);
|
|
280
118
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
// Initial state: scope not resolved
|
|
119
|
+
// Should show loading state
|
|
284
120
|
expect(screen.getByText('Checking permissions...')).toBeInTheDocument();
|
|
285
|
-
|
|
286
|
-
// Simulate scope resolution
|
|
287
|
-
act(() => {
|
|
288
|
-
scopeResolved = true;
|
|
289
|
-
rerender(<TestComponent />);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
// Wait for content to appear
|
|
293
|
-
await waitFor(() => {
|
|
294
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
// Verify no infinite loops
|
|
298
|
-
expect(callCount).toBeLessThanOrEqual(3);
|
|
299
|
-
expect(renderCount).toBeLessThanOrEqual(5);
|
|
121
|
+
expect(screen.queryByTestId('protected-content')).not.toBeInTheDocument();
|
|
300
122
|
});
|
|
301
123
|
});
|
|
302
124
|
|
|
303
|
-
describe('
|
|
304
|
-
it('
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
renderCount++;
|
|
324
|
-
return (
|
|
325
|
-
<PagePermissionGuard pageName="meals" operation="read">
|
|
326
|
-
<div data-testid="protected-content">Protected Content</div>
|
|
327
|
-
</PagePermissionGuard>
|
|
328
|
-
);
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
const { rerender } = render(<TestComponent />);
|
|
332
|
-
|
|
333
|
-
// Test each state transition
|
|
334
|
-
for (let i = 0; i < stateSequence.length; i++) {
|
|
335
|
-
act(() => {
|
|
336
|
-
currentStateIndex = i;
|
|
337
|
-
rerender(<TestComponent />);
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
const expectedState = stateSequence[i];
|
|
341
|
-
|
|
342
|
-
if (expectedState.expectedUI === 'loading') {
|
|
343
|
-
// In test environment, scope resolution may be synchronous
|
|
344
|
-
const hasLoading = screen.queryByText('Checking permissions...');
|
|
345
|
-
const hasContent = screen.queryByTestId('protected-content');
|
|
346
|
-
expect(hasLoading || hasContent).toBeTruthy();
|
|
347
|
-
} else if (expectedState.expectedUI === 'denied') {
|
|
348
|
-
// In test environment, mock may not be applied, so check for content instead
|
|
349
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
350
|
-
} else if (expectedState.expectedUI === 'content') {
|
|
351
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Verify final state is correct
|
|
356
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
357
|
-
expect(screen.queryByText('Loading organisation context...')).not.toBeInTheDocument();
|
|
358
|
-
expect(screen.queryByText('Access Denied')).not.toBeInTheDocument();
|
|
125
|
+
describe('Error Handling', () => {
|
|
126
|
+
it('handles permission check errors gracefully', () => {
|
|
127
|
+
mockUseCan.mockReturnValue({
|
|
128
|
+
can: false,
|
|
129
|
+
isLoading: false,
|
|
130
|
+
error: new Error('Permission check failed'),
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
render(
|
|
134
|
+
<PagePermissionGuard
|
|
135
|
+
pageName="users"
|
|
136
|
+
operation="read"
|
|
137
|
+
scope={{ organisationId: 'org-123' }}
|
|
138
|
+
>
|
|
139
|
+
<div data-testid="protected-content">Protected Content</div>
|
|
140
|
+
</PagePermissionGuard>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(screen.getByText('Access Denied')).toBeInTheDocument();
|
|
144
|
+
expect(screen.queryByTestId('protected-content')).not.toBeInTheDocument();
|
|
359
145
|
});
|
|
360
146
|
});
|
|
361
147
|
|
|
362
|
-
describe('
|
|
363
|
-
it('
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
// Simulate supabase reference changing on every render
|
|
369
|
-
supabaseRef = { id: Math.random() };
|
|
370
|
-
|
|
371
|
-
return {
|
|
372
|
-
user: mockUser,
|
|
373
|
-
selectedOrganisationId: 'org-123',
|
|
374
|
-
selectedEventId: 'event-123',
|
|
375
|
-
supabase: supabaseRef as any,
|
|
376
|
-
isAuthenticated: true,
|
|
377
|
-
isLoading: false,
|
|
378
|
-
error: null,
|
|
379
|
-
signOut: vi.fn(),
|
|
380
|
-
refreshSession: vi.fn(),
|
|
381
|
-
hasPermission: vi.fn(),
|
|
382
|
-
hasRole: vi.fn(),
|
|
383
|
-
hasAccessLevel: vi.fn(),
|
|
384
|
-
validatePermission: vi.fn(),
|
|
385
|
-
canAccess: vi.fn(),
|
|
386
|
-
setSelectedEventId: vi.fn(),
|
|
387
|
-
appName: 'test-app',
|
|
388
|
-
hasErrors: false
|
|
389
|
-
};
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
mockUseCan.mockImplementation(() => {
|
|
393
|
-
callCount++;
|
|
394
|
-
return {
|
|
395
|
-
can: true,
|
|
396
|
-
isLoading: false,
|
|
397
|
-
error: null
|
|
398
|
-
};
|
|
148
|
+
describe('Props Validation', () => {
|
|
149
|
+
it('handles different permission formats', () => {
|
|
150
|
+
mockUseCan.mockReturnValue({
|
|
151
|
+
can: true,
|
|
152
|
+
isLoading: false,
|
|
153
|
+
error: null,
|
|
399
154
|
});
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
155
|
+
|
|
156
|
+
const testCases = [
|
|
157
|
+
{ pageName: 'users', operation: 'read' as const },
|
|
158
|
+
{ pageName: 'events', operation: 'create' as const },
|
|
159
|
+
{ pageName: 'organisations', operation: 'update' as const }
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
testCases.forEach(({ pageName, operation }) => {
|
|
163
|
+
const { unmount } = render(
|
|
164
|
+
<PagePermissionGuard
|
|
165
|
+
pageName={pageName}
|
|
166
|
+
operation={operation}
|
|
167
|
+
scope={{ organisationId: 'org-123' }}
|
|
168
|
+
>
|
|
169
|
+
<div data-testid={`content-${operation}:${pageName}`}>Content for {operation}:{pageName}</div>
|
|
406
170
|
</PagePermissionGuard>
|
|
407
171
|
);
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
const { rerender } = render(<TestComponent />);
|
|
411
|
-
|
|
412
|
-
// Simulate many re-renders with changing supabase reference
|
|
413
|
-
for (let i = 0; i < 10; i++) {
|
|
414
|
-
act(() => {
|
|
415
|
-
rerender(<TestComponent />);
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
172
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
expect(screen.getByTestId('protected-content')).toBeInTheDocument();
|
|
173
|
+
expect(screen.getByTestId(`content-${operation}:${pageName}`)).toBeInTheDocument();
|
|
174
|
+
unmount();
|
|
422
175
|
});
|
|
423
|
-
|
|
424
|
-
// Verify no infinite loops despite changing supabase reference
|
|
425
|
-
expect(callCount).toBeLessThanOrEqual(5); // Should be very few calls
|
|
426
|
-
expect(renderCount).toBeLessThanOrEqual(15); // Should be reasonable
|
|
427
176
|
});
|
|
428
177
|
|
|
429
|
-
it('
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
callCount++;
|
|
435
|
-
// Toggle permission on each call
|
|
436
|
-
canValue = !canValue;
|
|
437
|
-
return {
|
|
438
|
-
can: canValue,
|
|
439
|
-
isLoading: false,
|
|
440
|
-
error: null
|
|
441
|
-
};
|
|
178
|
+
it('handles different scope configurations', () => {
|
|
179
|
+
mockUseCan.mockReturnValue({
|
|
180
|
+
can: true,
|
|
181
|
+
isLoading: false,
|
|
182
|
+
error: null,
|
|
442
183
|
});
|
|
443
|
-
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
184
|
+
|
|
185
|
+
const scopes = [
|
|
186
|
+
{ organisationId: 'org-123' },
|
|
187
|
+
{ organisationId: 'org-123', eventId: 'event-456' },
|
|
188
|
+
{ organisationId: 'org-123', eventId: 'event-456', appId: 'app-789' },
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
scopes.forEach((scope, index) => {
|
|
192
|
+
const { unmount } = render(
|
|
193
|
+
<PagePermissionGuard
|
|
194
|
+
pageName="users"
|
|
195
|
+
operation="read"
|
|
196
|
+
scope={scope}
|
|
197
|
+
>
|
|
198
|
+
<div data-testid={`content-${index}`}>Content {index}</div>
|
|
449
199
|
</PagePermissionGuard>
|
|
450
200
|
);
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
const { rerender } = render(<TestComponent />);
|
|
454
201
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
act(() => {
|
|
458
|
-
rerender(<TestComponent />);
|
|
459
|
-
});
|
|
460
|
-
await new Promise(resolve => setTimeout(resolve, 5));
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// Should eventually stabilize
|
|
464
|
-
await waitFor(() => {
|
|
465
|
-
// Either content or denied should be visible, not loading
|
|
466
|
-
const hasContent = screen.queryByTestId('protected-content');
|
|
467
|
-
const hasDenied = screen.queryByText('Access Denied');
|
|
468
|
-
const hasLoading = screen.queryByText('Checking permissions...');
|
|
469
|
-
|
|
470
|
-
expect(hasContent || hasDenied).toBeTruthy();
|
|
471
|
-
expect(hasLoading).not.toBeInTheDocument();
|
|
202
|
+
expect(screen.getByTestId(`content-${index}`)).toBeInTheDocument();
|
|
203
|
+
unmount();
|
|
472
204
|
});
|
|
473
|
-
|
|
474
|
-
// Verify reasonable number of calls
|
|
475
|
-
expect(callCount).toBeLessThanOrEqual(10);
|
|
476
205
|
});
|
|
477
206
|
});
|
|
478
|
-
});
|
|
207
|
+
});
|
|
@@ -409,9 +409,8 @@ describe('PagePermissionGuard Component', () => {
|
|
|
409
409
|
it('handles app resolution errors in production', async () => {
|
|
410
410
|
mockGetCurrentAppName.mockReturnValue(null);
|
|
411
411
|
|
|
412
|
-
//
|
|
413
|
-
|
|
414
|
-
process.env.NODE_ENV = 'production';
|
|
412
|
+
// Mock import.meta.env.MODE for production using vi.stubEnv
|
|
413
|
+
vi.stubEnv('MODE', 'production');
|
|
415
414
|
|
|
416
415
|
render(
|
|
417
416
|
<PagePermissionGuard
|
|
@@ -427,8 +426,8 @@ describe('PagePermissionGuard Component', () => {
|
|
|
427
426
|
expect(screen.getByText('Checking permissions...')).toBeInTheDocument();
|
|
428
427
|
});
|
|
429
428
|
|
|
430
|
-
// Restore
|
|
431
|
-
|
|
429
|
+
// Restore environment
|
|
430
|
+
vi.unstubAllEnvs();
|
|
432
431
|
});
|
|
433
432
|
|
|
434
433
|
it('validates app ID format in production', async () => {
|