feat(admin-ui): add test cases for redux state, auth/security utilities, and complex form components#2901
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR updates accordion and theme context usage to hook-based reads, adjusts sidebar and layout measurement logic, and adds Redux, utility, listener, and component tests across admin-ui app and plugin modules. ChangesAdmin UI refactors and coverage updates
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: faisalsiddique4400 <faisalsiddique10886@gmail.com>
|
There was a problem hiding this comment.
Actionable comments posted: 8
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@admin-ui/app/components/SidebarMenu/SidebarMenuItem.tsx`:
- Around line 205-216: Remove the redundant menuContext prop spread from the
React.cloneElement call in SidebarMenuItem; entries, addEntry, updateEntry, and
removeEntry are already read via use(MenuContext) inside SidebarMenuItem and
should not be forwarded to cloned children as unused props. Update the clone
props to keep only the child-specific values like isSubNode, parentId,
currentUrl, and slim, and leave the existing
SidebarMenuItemProps/SidebarMenuContext typing intact for locating the change.
In `@admin-ui/app/context/theme/themeContext.tsx`:
- Around line 44-51: getStoredTheme currently calls
storage.get(STORAGE_KEYS.INIT_THEME) without protection, which can throw during
GluuLoader rendering when storage is blocked or unavailable. Update
getStoredTheme in themeContext.tsx to match the defensive pattern used by
getInitialTheme: wrap the storage read in try/catch, validate the returned value
with isValidTheme, and fall back to DEFAULT_THEME on any error or invalid value.
In `@admin-ui/app/redux/features/__tests__/authSlice.test.ts`:
- Around line 31-35: The auth slice tests are bypassing action payload type
safety by casting payloads to never, which hides contract drift. Update the
affected reducer tests in authSlice.test.ts to use properly typed fixtures or
minimal valid payload objects for the actions like getOAuth2ConfigResponse and
the other listed cases, so the tests fail at compile time if the slice payload
shapes change. Keep the assertions focused on reducer behavior, but remove the
unsafe as never casts and align the test inputs with the actual action creators’
payload contracts.
In `@admin-ui/app/redux/listeners/__tests__/sessionListener.test.ts`:
- Around line 27-63: Add a dedicated test in sessionListener.test.ts for the 403
recovery path in auditLogoutLogs. The current suite covers success, non-2xx, and
non-403 failures, but it does not exercise the branch in auditLogoutLogs from
sessionListener.ts that handles a 403 by performing session cleanup and redirect
logic. Mock a 403 response via mockedPostUserAction, dispatch auditLogoutLogs,
and assert the expected side effects on the store and any redirect/cleanup
helpers used by sessionListener.
In `@admin-ui/plugins/admin/redux/features/__tests__/WebhookSlice.test.ts`:
- Line 29: The tests for WebhookSlice are bypassing the action payload types by
casting arguments with as never, which hides contract drift. Update the
assertions around triggerWebhook and setWebhookTriggerResults in
WebhookSlice.test so they use correctly typed payload values instead of forced
casts, keeping the test aligned with the real action creators and their payload
definitions.
In `@admin-ui/plugins/admin/redux/listeners/__tests__/webhookListener.test.ts`:
- Line 24: The webhook listener tests are bypassing type safety by casting
`listenerMiddleware.startListening` to `never`, which hides contract mismatches
between the test setup and production listener API. Remove the `as never` casts
in `setupWebhookListener` test calls and update the test helpers/mocks to match
the real `startListening` and `triggerWebhook` shapes so TypeScript enforces the
listener registration and payload contracts throughout the suite.
In `@admin-ui/plugins/auth-server/redux/features/__tests__/scopeSlice.test.ts`:
- Around line 10-12: The test for setClientSelectedScopes is asserting object
identity with toBe(scopes), which over-couples it to the reducer reusing the
same array instance. Update the assertion in scopeSlice.test.ts to verify the
selectedClientScopes contents/value instead of referential equality, so the test
remains valid if the reducer copies or normalizes the payload while preserving
behavior.
In `@admin-ui/plugins/auth-server/utils/__tests__/sessionExpiredRedirect.test.ts`:
- Around line 35-41: The test currently only covers token-fetch failure and
never reaches the cleanup path in redirectSessionExpired. Update the
sessionExpiredRedirect.test.ts case for redirectSessionExpired so
mockedFetchToken succeeds and mockedDeleteSession rejects, then keep asserting
the custom auditLogoutLogs dispatch and that the promise still resolves; this
will exercise the deleteAdminUiSession failure branch instead of the
fetchApiTokenWithDefaultScopes rejection branch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 90aff19f-3069-4a88-8f02-b34ed22601b0
📒 Files selected for processing (38)
admin-ui/app/components/Accordion/Accordion.tsxadmin-ui/app/components/Accordion/AccordionBody.tsxadmin-ui/app/components/Accordion/AccordionHeader.tsxadmin-ui/app/components/Accordion/AccordionIndicator.tsxadmin-ui/app/components/Accordion/context.tsxadmin-ui/app/components/Accordion/types.tsadmin-ui/app/components/GluuDropdown/GluuDropdown.tsxadmin-ui/app/components/SidebarMenu/SidebarMenuItem.tsxadmin-ui/app/components/Theme/ThemeClass.tsxadmin-ui/app/components/Theme/ThemeContext.tsxadmin-ui/app/components/Theme/ThemeProvider.tsxadmin-ui/app/context/theme/themeContext.tsxadmin-ui/app/redux/features/__tests__/authSlice.test.tsadmin-ui/app/redux/features/__tests__/cedarPermissionsSlice.test.tsadmin-ui/app/redux/features/__tests__/initSlice.test.tsadmin-ui/app/redux/features/__tests__/logoutSlice.test.tsadmin-ui/app/redux/features/__tests__/sessionSlice.test.tsadmin-ui/app/redux/features/__tests__/toastSlice.test.tsadmin-ui/app/redux/listeners/__tests__/sessionListener.test.tsadmin-ui/app/routes/Apps/Gluu/GluuAppSidebar.tsxadmin-ui/app/routes/Apps/Gluu/GluuLoader.tsxadmin-ui/app/utils/__tests__/TokenController.test.tsadmin-ui/plugins/admin/components/Assets/__tests__/AssetForm.test.tsxadmin-ui/plugins/admin/components/Cedarling/__tests__/PolicyStoreUploadConfirmDialog.test.tsxadmin-ui/plugins/admin/components/MAU/components/__tests__/DateRangeSelector.test.tsxadmin-ui/plugins/admin/components/Mapping/__tests__/RolePermissionCard.test.tsxadmin-ui/plugins/admin/redux/features/__tests__/WebhookSlice.test.tsadmin-ui/plugins/admin/redux/listeners/__tests__/webhookListener.test.tsadmin-ui/plugins/auth-server/components/AuthServerProperties/components/__tests__/JsonPropertyBuilder.test.tsxadmin-ui/plugins/auth-server/components/ConfigApiProperties/components/__tests__/JsonPropertyBuilderConfigApi.test.tsxadmin-ui/plugins/auth-server/components/Ssa/components/SsaForm.tsxadmin-ui/plugins/auth-server/redux/features/__tests__/scopeSlice.test.tsadmin-ui/plugins/auth-server/utils/__tests__/sessionExpiredRedirect.test.tsadmin-ui/plugins/fido/components/Metrics/components/PasskeyAdoptionChart.tsxadmin-ui/plugins/user-management/components/User2FADevicesModal.tsxadmin-ui/plugins/user-management/components/UserForm.tsxadmin-ui/plugins/user-management/components/__tests__/PasswordChangeModal.test.tsxadmin-ui/plugins/user-management/components/__tests__/User2FADevicesModal.test.tsx
Signed-off-by: faisalsiddique4400 <faisalsiddique10886@gmail.com>
There was a problem hiding this comment.
♻️ Duplicate comments (2)
admin-ui/app/redux/listeners/__tests__/sessionListener.test.ts (1)
75-76: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the
as nevermock result casts.These still erase the recovery-path API contracts, so this test can keep compiling even if
fetchApiTokenWithDefaultScopesordeleteAdminUiSessionchange shape.Suggested change
- mockedFetchToken.mockResolvedValue({ access_token: 'tok' } as never) - mockedDeleteSession.mockResolvedValue({} as never) + mockedFetchToken.mockResolvedValue({ access_token: 'tok' }) + mockedDeleteSession.mockResolvedValue({})🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@admin-ui/app/redux/listeners/__tests__/sessionListener.test.ts` around lines 75 - 76, The mocked return values in sessionListener.test.ts are being force-cast to never, which hides type changes in fetchApiTokenWithDefaultScopes and deleteAdminUiSession. Update the mockedFetchToken and mockedDeleteSession setup to use properly typed mock responses instead of as never, so the test continues to validate the recovery-path API contracts against the real signatures.admin-ui/plugins/auth-server/utils/__tests__/sessionExpiredRedirect.test.ts (1)
36-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDrop the
as neveron the mocked token response.This lets the test keep compiling even if
fetchApiTokenWithDefaultScopesstops returning the shape thatredirectSessionExpiredactually consumes.Suggested change
- mockedFetchToken.mockResolvedValue({ access_token: 'tok' } as never) + mockedFetchToken.mockResolvedValue({ access_token: 'tok' })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@admin-ui/plugins/auth-server/utils/__tests__/sessionExpiredRedirect.test.ts` at line 36, The mocked token response in redirectSessionExpired test is being force-cast with as never, which hides type mismatches between mockedFetchToken and what fetchApiTokenWithDefaultScopes actually returns. Remove the unsafe cast in sessionExpiredRedirect.test.ts and make the mock value match the real return type expected by redirectSessionExpired so the test fails if the consumed token shape changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@admin-ui/app/redux/listeners/__tests__/sessionListener.test.ts`:
- Around line 75-76: The mocked return values in sessionListener.test.ts are
being force-cast to never, which hides type changes in
fetchApiTokenWithDefaultScopes and deleteAdminUiSession. Update the
mockedFetchToken and mockedDeleteSession setup to use properly typed mock
responses instead of as never, so the test continues to validate the
recovery-path API contracts against the real signatures.
In `@admin-ui/plugins/auth-server/utils/__tests__/sessionExpiredRedirect.test.ts`:
- Line 36: The mocked token response in redirectSessionExpired test is being
force-cast with as never, which hides type mismatches between mockedFetchToken
and what fetchApiTokenWithDefaultScopes actually returns. Remove the unsafe cast
in sessionExpiredRedirect.test.ts and make the mock value match the real return
type expected by redirectSessionExpired so the test fails if the consumed token
shape changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ea1e0baf-029e-48f9-bb28-9ee702f33de8
📒 Files selected for processing (7)
admin-ui/app/components/SidebarMenu/SidebarMenuItem.tsxadmin-ui/app/redux/features/__tests__/authSlice.test.tsadmin-ui/app/redux/listeners/__tests__/sessionListener.test.tsadmin-ui/plugins/admin/redux/features/__tests__/WebhookSlice.test.tsadmin-ui/plugins/admin/redux/listeners/__tests__/webhookListener.test.tsadmin-ui/plugins/auth-server/redux/features/__tests__/scopeSlice.test.tsadmin-ui/plugins/auth-server/utils/__tests__/sessionExpiredRedirect.test.ts
💤 Files with no reviewable changes (1)
- admin-ui/app/components/SidebarMenu/SidebarMenuItem.tsx
Signed-off-by: faisalsiddique4400 <faisalsiddique10886@gmail.com>
|



feat(admin-ui): add test cases for redux state, auth/security utilities, and complex form components (#2900)
Summary
This PR expands automated test coverage across several critical areas of the Admin UI that currently contain important business logic but lack dedicated test coverage.
The work focuses on Redux state management, authentication and security utilities, complex form components, shared utilities, and data hooks that are difficult to validate manually and are susceptible to regressions.
The objective is to improve confidence in application behavior, strengthen regression protection, and support the ongoing initiative to improve overall Jest coverage across the Admin UI.
Fix Summary
TokenControllerAuditLoggersessionExpiredRedirectApiKeyRedirectAppAuthProviderJsonPropertyBuilderJsonPropertyBuilderConfigApiPasswordChangeModalUser2FADevicesModalAssetFormRolePermissionCardDateRangeSelectorPolicyStoreUploadConfirmDialogVerification
passes successfully.
🔗 Ticket
Closes: #2900
Summary by CodeRabbit