enzyme -> RTL: convert the Organization screen suites - #447
Conversation
Migrate the Organization screen's test suite off enzyme/mountWithContexts onto renderWithContexts (React Testing Library): OrganizationList + item, OrganizationDetail, OrganizationAdd/Edit (shared OrganizationForm mocked), OrganizationForm, and the ExecEnv and Teams sublists. Behaviour and assertions are preserved; interactions go through accessible roles and real user events.
There was a problem hiding this comment.
Pull request overview
Migrates the Organization screen’s UI test suites from enzyme (mountWithContexts) to React Testing Library (renderWithContexts), aligning tests with accessible queries and real user interactions while keeping coverage focused on behavior.
Changes:
- Converted Organization list/detail/add/edit/form tests to RTL patterns (
screen,userEvent,waitFor) with mocked lookups where needed. - Updated Organization teams and execution environments list/item suites to RTL table idioms and error rendering assertions.
- Refactored some assertions to be more user-facing (roles/labels) and reduced redundant mount-only tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| awx/ui/src/screens/Organization/shared/OrganizationForm.test.js | RTL conversion with deterministic lookup mocks and user-event driven form assertions |
| awx/ui/src/screens/Organization/OrganizationTeams/OrgnizationTeamListItem.test.js | RTL conversion of team list row assertions |
| awx/ui/src/screens/Organization/OrganizationTeams/OrganizationTeamList.test.js | RTL conversion for team list loading, rendering, and error states |
| awx/ui/src/screens/Organization/OrganizationList/OrganizationListItem.test.js | RTL conversion for org list row rendering and edit capability checks |
| awx/ui/src/screens/Organization/OrganizationList/OrganizationList.test.js | RTL conversion for list loading, selection, bulk delete, and error modal behavior |
| awx/ui/src/screens/Organization/OrganizationExecEnvList/OrganizationExecEnvListItem.test.js | RTL conversion for execution environment row rendering assertions |
| awx/ui/src/screens/Organization/OrganizationExecEnvList/OrganizationExecEnvList.test.js | RTL conversion for execution environments list rendering and add-button visibility |
| awx/ui/src/screens/Organization/OrganizationEdit/OrganizationEdit.test.js | RTL conversion using a mocked OrganizationForm to drive submit/cancel behavior |
| awx/ui/src/screens/Organization/OrganizationDetail/OrganizationDetail.test.js | RTL conversion for details rendering, delete flows, and permission-gated actions |
| awx/ui/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.js | RTL conversion using a mocked OrganizationForm to drive create/cancel flows |
| renderWithContexts(<OrganizationDetail organization={mockOrganization} />); | ||
| const editButton = await screen.findByRole('link', { name: 'Edit' }); | ||
| expect(editButton).toHaveTextContent('Edit'); | ||
| expect(editButton).toHaveAttribute('href', '/organizations/undefined/edit'); | ||
| }); |
| const onSubmit = jest.fn(); | ||
| OrganizationsAPI.update.mockResolvedValue(1, mockDataForm); | ||
| OrganizationsAPI.associateInstanceGroup.mockResolvedValue('done'); |
| expect(await screen.findByText('Error!')).toBeInTheDocument(); | ||
| await settleTooltips(); |
| @@ -1,57 +1,41 @@ | |||
| import React from 'react'; | |||
Render OrganizationDetail under a real route so the Edit link resolves /organizations/12/edit (not undefined); drop the dead settleTooltips() call on the open error modal; pass a single value to OrganizationsAPI.update.mockResolvedValue; rename the misspelled OrgnizationTeamListItem test file.
Render OrganizationDetail under a real route so the Edit link resolves /organizations/12/edit (not undefined); drop the dead settleTooltips() call on the open error modal; pass a single value to OrganizationsAPI.update.mockResolvedValue.
|
Thanks for the review. Pushed a commit: OrganizationDetail renders under a real route so the Edit link resolves to /organizations/12/edit instead of undefined, the dead settleTooltips call on the still-open error modal is dropped, update.mockResolvedValue now takes a single value, and the misspelled OrgnizationTeamListItem test file is renamed to OrganizationTeamListItem. |
SUMMARY
Converts the Organization screen's test suite from enzyme to React Testing Library, continuing the incremental enzyme → RTL migration (one screen directory per PR).
Files migrated off
mountWithContexts/enzyme ontorenderWithContexts:OrganizationList/OrganizationListItem— load, selection, bulk delete + related-delete-request count, deletion errorOrganizationDetail— detail fields, empty instance-groups/galaxy-credentials, related-delete-request countOrganizationAdd/OrganizationEdit— create/update with instance-group associate/disassociate, galaxy credentials, max-hosts (sharedOrganizationFormmocked)OrganizationForm— fields, lookups (mocked), default galaxy credential, instance group addOrganizationExecEnvList+ item,OrganizationTeamList+ item — list idiomsInteractions now go through accessible roles and real user events. Behaviour and assertions are preserved.
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
npm testfor the Organization directory: 12 suites, 62 tests, all passing. ESLint clean. No production code changed — test-only.Two redundant tests were folded rather than duplicated: an Add-mode "AnsibleSelect does not render" assertion (it tested the real form's internal rendering, which is now mocked in the Add container suite and covered by the
OrganizationFormsuite) and two trivial "should mount successfully" duplicates subsumed by stronger row-render assertions.