Skip to content

chore: refactor test files to test public components only#400

Open
rax7389 wants to merge 3 commits into
mainfrom
chore/test-cleanup
Open

chore: refactor test files to test public components only#400
rax7389 wants to merge 3 commits into
mainfrom
chore/test-cleanup

Conversation

@rax7389

@rax7389 rax7389 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactors test files across my-organization components to test only the main public block components instead of internal View subcomponents, and adds coverage to compensate for removed View tests.

Why

  • Tests should focus on public API/components that consumers interact with, not internal implementation details
  • View component tests were testing internal implementation that could change without affecting the public contract
  • Improves test maintainability by reducing coupling to internal component structure
  • Removes : any type annotations and uses proper typing patterns

What

Key changes:

  • Removed View component tests from 7 test files in my-organization
  • Added comprehensive tests to main public components to maintain/improve coverage
  • Replaced : any types with proper mock types and ReturnType<typeof vi.fn> patterns
  • Used regex patterns for translation keys (e.g., /header\.title/i instead of 'header.title')
  • Used proper mocking utilities: mockCore(), initMockCoreClient(), mockToast()

Files changed (26 files):

  • organization-member-detail.test.tsx - Removed 27 View tests, added coverage for member data, error states, actions
  • organization-member-management.test.tsx - Refactored with proper mocking, added modal and action tests
  • organization-details-edit.test.tsx - Removed View tests, added form rendering and error handling tests
  • domain-table.test.tsx - Removed View tests, added table rendering and pagination tests
  • sso-provider-create.test.tsx - Removed View tests, added header, strategy, and validation tests
  • sso-provider-edit.test.tsx - Removed View tests, added header, error handling, and form tests
  • sso-provider-table.test.tsx - Removed View tests, added table display and error handling tests
  • Various shared component tests - Removed unused imports and cleaned up

Packages

  • packages/core
  • packages/react
  • examples

Testing

  • This change adds unit test coverage
  • Tested for both SPA and RWA flows, all example apps working
  • All existing and new tests complete without errors

Checklist

  • Breaking change
  • Requires docs update
  • Backward compatible

Contributing

Summary by CodeRabbit

  • Tests

    • Expanded coverage for organization management and MFA flows, including domain tables, member actions, SSO provider setup/editing, and form/error states.
    • Added checks for loading, empty, pagination, and failure scenarios to improve reliability of these experiences.
  • Refactor

    • Cleaned up test files by removing section-divider comments and simplifying test setup for consistency.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@rax7389, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1f5cb59d-eee0-40fa-bee6-75a6cba054a7

📥 Commits

Reviewing files that changed from the base of the PR and between 8b234ad and e736b86.

📒 Files selected for processing (2)
  • packages/react/src/components/auth0/my-organization/__tests__/domain-table.test.tsx
  • packages/react/src/components/auth0/my-organization/__tests__/organization-member-management.test.tsx
📝 Walkthrough

Walkthrough

This PR refactors test files across my-account and my-organization React components, removing deprecated "View" component test suites and consolidating coverage into container-component tests driven by mocked core API clients. Non-functional section-divider comments are also removed from numerous test files.

Changes

Test consolidation and cleanup

Layer / File(s) Summary
Comment cleanup across test files
packages/react/src/components/auth0/my-account/**/*.test.tsx, packages/react/src/components/auth0/my-organization/**/*.test.tsx, packages/react/src/hooks/**/*.test.ts
Removes decorative // ===== ... ===== section comments; no test logic, assertions, or mocks are changed.
DomainTable consolidation
.../my-organization/__tests__/domain-table.test.tsx
Drops DomainTableView import/tests, reworks waitForComponentToLoad, and adds DomainTable tests for rendering, empty state, pagination, and customMessages.
OrganizationDetailsEdit consolidation
.../my-organization/__tests__/organization-details-edit.test.tsx
Removes OrganizationDetailsEditView tests/imports and adds OrganizationDetailsEdit tests for form rendering, pre-population, and load/save error handling.
OrganizationMemberDetail consolidation
.../my-organization/__tests__/organization-member-detail.test.tsx
Drops OrganizationMemberDetailView imports and removes its entire test suite.
OrganizationMemberManagement container rework
.../my-organization/__tests__/organization-member-management.test.tsx
Replaces hook/view mocks with a mocked core API client and rewrites tests for rendering, tabs, invitation/member actions, empty states, pagination, errors, modals, and dark mode.
SsoProviderCreate consolidation
.../my-organization/__tests__/sso-provider-create.test.tsx
Removes SsoProviderCreateView tests/imports and adds header, step-indicator, strategy-selection, and validation tests for SsoProviderCreate.
SsoProviderEdit consolidation
.../my-organization/__tests__/sso-provider-edit.test.tsx
Removes SsoProviderEditView tests/imports and adds header rendering, load-error, and toggle-update tests for SsoProviderEdit.
SsoProviderTable consolidation
.../my-organization/__tests__/sso-provider-table.test.tsx
Updates hook imports, splits provider-display assertions, and adds empty-state, hideHeader, and error-handling tests while removing SsoProviderTableView suite.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested labels: refactor

Suggested reviewers: NaveenChand755

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: shifting tests from internal View subcomponents to public components only.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/test-cleanup

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Nitpick comments (1)
packages/react/src/components/auth0/my-organization/__tests__/sso-provider-edit.test.tsx (1)

724-742: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Strengthen the error handling test assertions.

The test "should handle error gracefully" only asserts that the loading text disappears, which duplicates waitForComponentToLoad logic rather than using the helper. It doesn't verify any error state or message is rendered to the user. Consider using waitForComponentToLoad() and adding an assertion for the error UI (e.g., an error message or error boundary fallback) to make the test name meaningful.

♻️ Proposed improvement
       it('should handle error gracefully', async () => {
         const apiService = mockCoreClient.getMyOrganizationApiClient().organization;
         apiService.identityProviders.get = vi
           .fn()
           .mockRejectedValue(new Error('Provider not found'));

         renderWithProviders(<SsoProviderEdit {...createMockSsoProviderEditProps()} />);

-        await waitFor(
-          () => {
-            expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
-          },
-          { timeout: 3000 },
-        );
+        await waitForComponentToLoad();
+
+        // Add assertion for error state visible to the user
+        // e.g., expect(screen.getByText(/error/i)).toBeInTheDocument();
       });
🤖 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
`@packages/react/src/components/auth0/my-organization/__tests__/sso-provider-edit.test.tsx`
around lines 724 - 742, The "should handle error gracefully" test in
SsoProviderEdit only checks that the loading state disappears, which repeats
generic loading behavior instead of validating error handling. Update the test
to use waitForComponentToLoad() for the async settle step, then add an assertion
against the actual error UI rendered by SsoProviderEdit (such as an error
message, fallback state, or error boundary output) so the test name matches its
behavior.
🤖 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
`@packages/react/src/components/auth0/my-organization/__tests__/domain-table.test.tsx`:
- Around line 746-765: The customMessages test in DomainTable only checks that
the table renders, so it does not verify the provided header title is actually
used. Update the test in the customMessages describe block to assert the
rendered text includes the passed title from createMockDomainTableProps, or
rename it to make clear it is only a smoke test; use DomainTable,
createMockDomainTableProps, and the customMessages.header.title prop to locate
the assertion.
- Around line 733-743: The pagination test in DomainTable currently only checks
that the table renders, so it does not verify the behavior described by its
name. Update the test in the pagination block of the domain-table suite to
assert pagination-specific UI from DomainTable (such as navigation buttons, page
controls, or page indicators) after renderWithProviders and
waitForComponentToLoad, or rename the test so it matches the actual assertion if
you intend to keep it as a simple render check.

In
`@packages/react/src/components/auth0/my-organization/__tests__/organization-member-management.test.tsx`:
- Around line 772-792: The dark mode test in OrganizationMemberManagement only
checks that the header renders, so it never verifies the provided styling class
is applied. Update the test to assert the root element receives the
dark-mode-root class from the styling.classes mapping, using the same approach
as the existing styling test in the OrganizationMemberManagement test suite,
while keeping the current renderWithProviders and waitForComponentToLoad flow.
- Around line 486-612: The empty-state, pagination, and error-handling tests in
OrganizationMemberManagement only verify API calls and don’t assert the UI
behavior the test names describe. Update the affected tests to check the
rendered outcome after the mocked organization.members.list and
organization.invitations.list calls resolve/reject, such as the empty-state
message, pagination controls, or error banner. Use the existing helpers and
selectors in OrganizationMemberManagement, renderWithProviders,
waitForComponentToLoad, and screen to assert what the user actually sees.
- Around line 614-650: The “close modal after creation” test in
OrganizationMemberManagement currently only verifies that
organization.invitations.create is called, so it does not actually assert the
modal closes; update this test to check that the invitation create modal is
dismissed after a successful submission. Reuse the existing modal title matcher
(/invitation\.create\.title/i) and add a post-submit assertion that it is no
longer present in the document, keeping the test aligned with its name and
behavior.
- Around line 338-461: Several tests in OrganizationMemberManagement are named
as action/behavior coverage but only assert setup or tab loading, so either
rename them to match the actual checks or add the missing user interactions and
expectations. In the invitation actions cases, use the relevant action UI to
trigger revoke/resend and assert the mocked
organization.invitations.delete/create calls plus the ComponentAction
onBefore/onAfter callbacks; in the member actions cases, interact with the view
details/assign roles/remove controls and verify the corresponding behavior
instead of only checking members.list or tab state. Refer to
OrganizationMemberManagement, createMockComponentProps, and the
revokeInvitationAction/resendInvitationAction/viewMemberDetailsAction/assignRolesAction/removeFromOrganizationAction
test cases when updating the assertions.
- Around line 421-422: The test file has a duplicate `const assignRolesAction`
declaration inside `organization-member-management.test.tsx`, which causes a
compile-time identifier redeclaration error. Remove the repeated declaration in
the `it('should handle assign roles action'...)` test and keep only one
`assignRolesAction` constant, making sure any subsequent uses in that test refer
to the single existing variable.

---

Nitpick comments:
In
`@packages/react/src/components/auth0/my-organization/__tests__/sso-provider-edit.test.tsx`:
- Around line 724-742: The "should handle error gracefully" test in
SsoProviderEdit only checks that the loading state disappears, which repeats
generic loading behavior instead of validating error handling. Update the test
to use waitForComponentToLoad() for the async settle step, then add an assertion
against the actual error UI rendered by SsoProviderEdit (such as an error
message, fallback state, or error boundary output) so the test name matches its
behavior.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b1594762-cf5e-483a-bd93-a923213cbbb1

📥 Commits

Reviewing files that changed from the base of the PR and between 876097c and 8b234ad.

📒 Files selected for processing (26)
  • packages/react/src/components/auth0/my-account/__tests__/user-mfa-management.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/__tests__/delete-factor-confirmation.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/__tests__/empty-state.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/__tests__/error-state.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/__tests__/factors-list.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/__tests__/otp-verification-form.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/__tests__/user-mfa-setup-form.test.tsx
  • packages/react/src/components/auth0/my-organization/__tests__/domain-table.test.tsx
  • packages/react/src/components/auth0/my-organization/__tests__/organization-details-edit.test.tsx
  • packages/react/src/components/auth0/my-organization/__tests__/organization-member-detail.test.tsx
  • packages/react/src/components/auth0/my-organization/__tests__/organization-member-management.test.tsx
  • packages/react/src/components/auth0/my-organization/__tests__/sso-provider-create.test.tsx
  • packages/react/src/components/auth0/my-organization/__tests__/sso-provider-edit.test.tsx
  • packages/react/src/components/auth0/my-organization/__tests__/sso-provider-table.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/domain-management/domain-create/__tests__/domain-create-modal.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/domain-management/domain-delete/__tests__/domain-delete-modal.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/domain-management/domain-verify/__tests__/domain-verify-modal.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-delete/__tests__/provider-delete-modal.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-edit/sso-provisioning/__tests__/sso-provisioning-details.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-remove/__tests__/provider-remove-modal.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-remove/__tests__/provider-remove.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/organization-management/organization-details/__tests__/branding-details.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/organization-management/organization-details/__tests__/organization-details.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/organization-management/organization-details/__tests__/setting-details.test.tsx
  • packages/react/src/hooks/__tests__/use-toast-provider.test.ts
  • packages/react/src/hooks/my-organization/__tests__/use-sso-domain-tab.test.ts
💤 Files with no reviewable changes (19)
  • packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-remove/tests/provider-remove.test.tsx
  • packages/react/src/hooks/tests/use-toast-provider.test.ts
  • packages/react/src/components/auth0/my-organization/shared/organization-management/organization-details/tests/organization-details.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-remove/tests/provider-remove-modal.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/tests/delete-factor-confirmation.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/domain-management/domain-create/tests/domain-create-modal.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-delete/tests/provider-delete-modal.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/tests/empty-state.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/tests/otp-verification-form.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/tests/error-state.test.tsx
  • packages/react/src/hooks/my-organization/tests/use-sso-domain-tab.test.ts
  • packages/react/src/components/auth0/my-organization/shared/organization-management/organization-details/tests/branding-details.test.tsx
  • packages/react/src/components/auth0/my-account/tests/user-mfa-management.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/tests/user-mfa-setup-form.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/domain-management/domain-verify/tests/domain-verify-modal.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/domain-management/domain-delete/tests/domain-delete-modal.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/organization-management/organization-details/tests/setting-details.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/idp-management/sso-provider-edit/sso-provisioning/tests/sso-provisioning-details.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/tests/factors-list.test.tsx

- Fix pagination test to verify table renders with domain data
- Fix customMessages test to use regex for flexible matching
- Fix member actions tests to verify API calls and table rendering
- Fix empty states tests to verify empty message UI elements
- Fix close modal test to verify modal closes after creation
- Fix styling test to verify custom class is applied

Addresses CodeRabbit review feedback about weak/misleading assertions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.86%. Comparing base (8ae4ff1) to head (e736b86).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #400      +/-   ##
==========================================
+ Coverage   88.63%   89.86%   +1.22%     
==========================================
  Files         203      203              
  Lines       17135    17201      +66     
  Branches     2273     2392     +119     
==========================================
+ Hits        15187    15457     +270     
+ Misses       1948     1744     -204     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants