Skip to content

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

Merged
rax7389 merged 2 commits into
mainfrom
chore/cleanup-test-my-org
Jul 27, 2026
Merged

chore: refactor test files to test public components only#427
rax7389 merged 2 commits into
mainfrom
chore/cleanup-test-my-org

Conversation

@rax7389

@rax7389 rax7389 commented Jul 25, 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, domain tables, member management, and SSO provider workflows.
    • Added assertions for loading states, errors, empty states, pagination, forms, actions, and custom messaging.
    • Simplified several test suites by focusing on end-to-end component behavior.
  • Chores
    • Removed non-functional section comments from test files for cleaner, more consistent test organization.

@rax7389 rax7389 self-assigned this Jul 25, 2026
@rax7389 rax7389 added the refactor Restructuring existing code and logic to reduce technical debt and improve quality label Jul 25, 2026
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR updates organization component tests to target primary components, adds coverage for loading, forms, actions, pagination, errors, and refresh behavior, and removes non-functional section comments across related MFA, domain, SSO, organization, and hook test files.

Changes

Organization and account test suites

Layer / File(s) Summary
Test scaffolding cleanup
packages/react/src/components/auth0/my-account/**/__tests__/*, packages/react/src/components/auth0/my-organization/shared/**/__tests__/*, packages/react/src/hooks/**/__tests__/*
Removes non-functional section headers and repositions existing test helpers without changing runtime test behavior.
Organization component test coverage
packages/react/src/components/auth0/my-organization/__tests__/domain-table.test.tsx, organization-details-edit.test.tsx, organization-member-detail.test.tsx
Refocuses tests on primary components and adds coverage for table rendering, forms, loading errors, and edited-value retention while removing view-specific suites.
Member management integration tests
packages/react/src/components/auth0/my-organization/__tests__/organization-member-management.test.tsx
Uses a mocked core client to test tabs, invitations, member actions, modals, pagination, error states, and refresh controls.
SSO provider component tests
packages/react/src/components/auth0/my-organization/__tests__/sso-provider-*.test.tsx
Targets primary SSO provider components and adds coverage for headers, validation, loading errors, updates, table states, and empty states while removing view-specific suites.

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

Possibly related PRs

Suggested reviewers: chakrihacker, grandmaester, harishsundar-okta

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: refactoring tests to focus on public components instead of internal view components.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/cleanup-test-my-org

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.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@51f72e8). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #427   +/-   ##
=======================================
  Coverage        ?   89.80%           
=======================================
  Files           ?      236           
  Lines           ?    17632           
  Branches        ?     2499           
=======================================
  Hits            ?    15835           
  Misses          ?     1797           
  Partials        ?        0           

☔ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (8)
packages/react/src/components/auth0/my-organization/__tests__/organization-member-management.test.tsx (2)

764-786: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate styling test block.

This describe('styling', ...) and its single test duplicate the earlier styling.classes block at lines 192-214 (same styling shape, same custom class, same assertion). Consider removing one to avoid duplicated coverage that could silently diverge.

♻️ Proposed fix to remove the duplicate block
-  describe('styling', () => {
-    it('should apply custom class when styling.classes are provided', async () => {
-      const styling = {
-        variables: {
-          common: {},
-          light: {},
-          dark: {},
-        },
-        classes: {
-          'OrganizationMemberManagement-root': 'custom-root-class',
-        },
-      };
-
-      renderWithProviders(
-        <OrganizationMemberManagement {...createMockComponentProps({ styling })} />,
-      );
-
-      await waitForComponentToLoad();
-
-      expect(document.querySelector('.custom-root-class')).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__/organization-member-management.test.tsx`
around lines 764 - 786, Remove the later duplicate describe('styling') block and
its custom-class test from organization-member-management.test.tsx, keeping the
earlier styling.classes coverage unchanged.

521-564: 🎯 Functional Correctness | 🔵 Trivial

Pagination tests don't verify pagination behavior.

These mock a next cursor but only assert basic table/data presence identical to the non-paginated rendering tests — no assertion on pagination controls or a second page fetch. See consolidated comment for a related instance in domain-table.test.tsx.

🤖 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__/organization-member-management.test.tsx`
around lines 521 - 564, Strengthen the pagination tests in the pagination
describe block by asserting the next-page behavior rather than only initial
rendering. Verify pagination controls are shown when the mocked response
includes response.next, trigger the control, and assert the corresponding
members.list or invitations.list mock is called again with the next cursor; keep
the existing data-rendering assertions.
packages/react/src/components/auth0/my-organization/__tests__/sso-provider-table.test.tsx (1)

848-858: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing negative case for hideHeader.

Only hideHeader: false is covered. Since the removed SsoProviderTableView suite previously verified header hiding, add a hideHeader: true case for SsoProviderTable to avoid a coverage regression on this toggle.

✅ Suggested addition
   describe('hideHeader', () => {
     describe('when is false', () => {
       it('should render the header', async () => {
         renderTable();

         await waitForComponentToLoad();

         expect(screen.getByText(/header.title/i)).toBeInTheDocument();
       });
     });
+
+    describe('when is true', () => {
+      it('should not render the header', async () => {
+        renderTable({ hideHeader: true });
+
+        await waitForComponentToLoad();
+
+        expect(screen.queryByText(/header.title/i)).not.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-table.test.tsx`
around lines 848 - 858, Add a `hideHeader: true` test alongside the existing
`hideHeader: false` case in the `hideHeader` describe block for
`SsoProviderTable`. Render the table, wait for it to load, and assert that the
header text is not present, preserving the existing positive-case coverage.
packages/react/src/components/auth0/my-organization/__tests__/organization-details-edit.test.tsx (2)

1-1: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

"Error handling" tests don't verify an error was actually surfaced. Both tests mock a rejected fetch but only assert the loading indicator eventually disappears — an assertion equally true for a successful load, so these tests would pass even if the error path silently rendered nothing.

  • packages/react/src/components/auth0/my-organization/__tests__/organization-details-edit.test.tsx#L571-587: assert an actual error indicator/message (or that the form falls back to an empty/default state) instead of only queryByRole('progressbar') absence.
  • packages/react/src/components/auth0/my-organization/__tests__/sso-provider-edit.test.tsx#L869-884: assert an actual error indicator/message instead of only "Loading..." absence.
🤖 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__/organization-details-edit.test.tsx`
at line 1, Strengthen the rejected-fetch tests in organization-details-edit and
sso-provider-edit so they verify the error outcome, not merely that loading
ends. After mocking fetch rejection, assert the rendered error indicator/message
(or the documented empty/default form state for organization-details-edit),
while retaining the existing loading-disappearance checks if useful.

571-587: 🎯 Functional Correctness | 🔵 Trivial

Error test doesn't verify an error was actually surfaced.

This only asserts the progressbar disappears, which would be equally true on a successful load. See consolidated comment for a related instance in sso-provider-edit.test.tsx.

🤖 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__/organization-details-edit.test.tsx`
around lines 571 - 587, Strengthen the “when organization details fail to load”
test in the error handling suite by asserting the user-visible error state after
the rejected organizationDetails.get call. Keep the existing progressbar
assertion, and verify a specific error message, alert, or other established
error indicator rather than only confirming loading completed.
packages/react/src/components/auth0/my-organization/__tests__/domain-table.test.tsx (2)

1-1: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

"Pagination" tests don't exercise pagination behavior. Both suites mock a next-page cursor but only re-assert the same basic table/data presence already covered by the non-paginated rendering tests, so they wouldn't catch a pagination regression (e.g., missing "load more"/next-page control, or a second fetch never firing).

  • packages/react/src/components/auth0/my-organization/__tests__/domain-table.test.tsx#L733-745: assert an actual pagination-specific behavior (e.g., a "next page" control/fetch), not just that the table renders with the first page's domain.
  • packages/react/src/components/auth0/my-organization/__tests__/organization-member-management.test.tsx#L521-564: same — verify pagination controls or a subsequent-page fetch rather than re-checking single-page table presence.
🤖 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__/domain-table.test.tsx`
at line 1, Strengthen the pagination tests in the domain-table and
organization-member-management suites so they verify pagination-specific
behavior, not merely initial table or data rendering. In the relevant tests, use
the mocked next-page cursor to assert that the load-more/next-page control is
rendered and/or activating it triggers the subsequent fetch and displays the
next-page results, while preserving the existing first-page setup.

733-745: 🎯 Functional Correctness | 🔵 Trivial

Pagination test doesn't exercise pagination.

This test mocks no page/next-cursor data and only re-asserts basic table rendering — identical in substance to the "table rendering" tests above. It doesn't validate any pagination-specific behavior (e.g., page controls, fetching a second page). See consolidated comment for a related instance.

🤖 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__/domain-table.test.tsx`
around lines 733 - 745, The pagination test for DomainTable currently only
verifies basic table rendering and must exercise paginated behavior. Update the
test setup to provide page or next-cursor data, then assert pagination-specific
UI or behavior such as rendering controls and fetching or displaying a second
page; keep the existing table-data assertion as appropriate.
packages/react/src/components/auth0/my-organization/__tests__/sso-provider-edit.test.tsx (1)

869-884: 🎯 Functional Correctness | 🔵 Trivial

Error test doesn't verify an error was actually surfaced.

Only asserts "Loading..." disappears, which is equally true on a successful load. See consolidated comment for a related instance in organization-details-edit.test.tsx.

🤖 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 869 - 884, The “when provider fails to load” test only verifies
that loading ends and does not assert error handling. Update the test around
SsoProviderEdit and the mocked identityProviders.get rejection to verify the
expected error UI or message is surfaced, while retaining the loading completion
check if needed.
🤖 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 747-765: Strengthen the assertion in the customMessages test for
DomainTable so it specifically requires “Custom Domain Title” to be rendered.
Remove the alternative default-key match, while preserving the existing
table-rendering and loading checks.

---

Nitpick comments:
In
`@packages/react/src/components/auth0/my-organization/__tests__/domain-table.test.tsx`:
- Line 1: Strengthen the pagination tests in the domain-table and
organization-member-management suites so they verify pagination-specific
behavior, not merely initial table or data rendering. In the relevant tests, use
the mocked next-page cursor to assert that the load-more/next-page control is
rendered and/or activating it triggers the subsequent fetch and displays the
next-page results, while preserving the existing first-page setup.
- Around line 733-745: The pagination test for DomainTable currently only
verifies basic table rendering and must exercise paginated behavior. Update the
test setup to provide page or next-cursor data, then assert pagination-specific
UI or behavior such as rendering controls and fetching or displaying a second
page; keep the existing table-data assertion as appropriate.

In
`@packages/react/src/components/auth0/my-organization/__tests__/organization-details-edit.test.tsx`:
- Line 1: Strengthen the rejected-fetch tests in organization-details-edit and
sso-provider-edit so they verify the error outcome, not merely that loading
ends. After mocking fetch rejection, assert the rendered error indicator/message
(or the documented empty/default form state for organization-details-edit),
while retaining the existing loading-disappearance checks if useful.
- Around line 571-587: Strengthen the “when organization details fail to load”
test in the error handling suite by asserting the user-visible error state after
the rejected organizationDetails.get call. Keep the existing progressbar
assertion, and verify a specific error message, alert, or other established
error indicator rather than only confirming loading completed.

In
`@packages/react/src/components/auth0/my-organization/__tests__/organization-member-management.test.tsx`:
- Around line 764-786: Remove the later duplicate describe('styling') block and
its custom-class test from organization-member-management.test.tsx, keeping the
earlier styling.classes coverage unchanged.
- Around line 521-564: Strengthen the pagination tests in the pagination
describe block by asserting the next-page behavior rather than only initial
rendering. Verify pagination controls are shown when the mocked response
includes response.next, trigger the control, and assert the corresponding
members.list or invitations.list mock is called again with the next cursor; keep
the existing data-rendering assertions.

In
`@packages/react/src/components/auth0/my-organization/__tests__/sso-provider-edit.test.tsx`:
- Around line 869-884: The “when provider fails to load” test only verifies that
loading ends and does not assert error handling. Update the test around
SsoProviderEdit and the mocked identityProviders.get rejection to verify the
expected error UI or message is surfaced, while retaining the loading completion
check if needed.

In
`@packages/react/src/components/auth0/my-organization/__tests__/sso-provider-table.test.tsx`:
- Around line 848-858: Add a `hideHeader: true` test alongside the existing
`hideHeader: false` case in the `hideHeader` describe block for
`SsoProviderTable`. Render the table, wait for it to load, and assert that the
header text is not present, preserving the existing positive-case coverage.
🪄 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: 963415c3-6716-4ea5-9b90-b38bd849a015

📥 Commits

Reviewing files that changed from the base of the PR and between 51f72e8 and b2e95fd.

📒 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-modal.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/factors-list.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/tests/otp-verification-form.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/organization-details.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/idp-management/sso-provider-delete/tests/provider-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/domain-management/domain-create/tests/domain-create-modal.test.tsx
  • packages/react/src/components/auth0/my-account/shared/mfa/tests/empty-state.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/error-state.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/idp-management/sso-provider-remove/tests/provider-remove.test.tsx
  • packages/react/src/components/auth0/my-organization/shared/domain-management/domain-delete/tests/domain-delete-modal.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/setting-details.test.tsx
  • packages/react/src/components/auth0/my-account/tests/user-mfa-management.test.tsx

@grandmaester grandmaester left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!!!

@rax7389
rax7389 merged commit 478dcf1 into main Jul 27, 2026
7 checks passed
@rax7389
rax7389 deleted the chore/cleanup-test-my-org branch July 27, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Restructuring existing code and logic to reduce technical debt and improve quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants