Skip to content

enzyme -> RTL: convert the Search component suites - #471

Merged
cigamit merged 2 commits into
ctrliq:mainfrom
blaipr:feature/rtl-components-search
Jun 18, 2026
Merged

enzyme -> RTL: convert the Search component suites#471
cigamit merged 2 commits into
ctrliq:mainfrom
blaipr:feature/rtl-components-search

Conversation

@blaipr

@blaipr blaipr commented Jun 16, 2026

Copy link
Copy Markdown
Contributor
SUMMARY

Converts the Search component test suite (components/Search) from enzyme to React Testing Library, continuing the enzyme → RTL migration (components, one directory per PR).

Files migrated off mountWithContexts/enzyme onto renderWithContexts: Search, AdvancedSearch.

The search-column key Select, value input/date input/operator Select, and the AdvancedSearch type/key/lookup typeaheads are driven through the real PF controls (scoped by data-ouia-component-id); filter chips and the onSearch callback are asserted via the rendered DOM. Behaviour and assertions are preserved.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • UI
ADDITIONAL INFORMATION

npm test for components/Search: 3 suites, 29 tests, all passing (the 2 converted suites + the pre-existing getChipsByKey util test). ESLint clean (--no-ignore) on the converted files. No production code changed — test-only.

Migrate components/Search (Search and AdvancedSearch) off enzyme/mountWithContexts
onto renderWithContexts (React Testing Library). The key/value/date selects and
typeaheads are driven through the real PF controls (scoped by ouiaId); filter
chips and onSearch are asserted via the rendered DOM. Behaviour and assertions
are preserved.

Copilot AI 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.

Pull request overview

Migrates the components/Search UI test suites from Enzyme (mountWithContexts) to React Testing Library (renderWithContexts), continuing the ongoing enzyme → RTL conversion work without changing production code.

Changes:

  • Converted Search component tests to RTL, driving real PatternFly Select/Chip interactions via OUIA selectors and DOM assertions.
  • Converted AdvancedSearch tests to RTL, exercising the three typeahead Selects and value submission through the rendered UI.
  • Updated assertions to validate filter chips and callbacks via rendered output rather than Enzyme prop inspection.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
awx/ui/src/components/Search/Search.test.js Rewrites Search tests to RTL, using DOM-driven interactions and assertions for chips/callbacks.
awx/ui/src/components/Search/AdvancedSearch.test.js Rewrites AdvancedSearch tests to RTL, interacting with PF typeaheads via OUIA scoping.

Comment on lines +234 to +237
// empty-value chip has no visible text, so scope to the rendered chip and
// click its close button (the only button inside the chip)
const chip = document.querySelector('.pf-c-chip');
await user.click(within(chip).getByRole('button'));
Comment on lines +9 to +13
async function selectFrom(user, ouiaId, optionName) {
const wrap = document.querySelector(`[data-ouia-component-id="${ouiaId}"]`);
await user.click(within(wrap).getByRole('button', { name: 'Options menu' }));
fireEvent.click(await screen.findByRole('option', { name: optionName }));
}
Comment on lines +45 to +49
await user.click(
within(keyWrap).getByRole('button', { name: 'Options menu' })
);
// 'bar' is in both lists but must appear only once -> foo, bar, baz
expect(screen.getAllByRole('option')).toHaveLength(3);
Comment on lines +229 to +232
await user.click(within(wrap).getByRole('button', { name: 'Options menu' }));
// with negative filtering off, only "and" and "or" remain (no "not")
const options = screen.getAllByRole('option');
expect(options).toHaveLength(2);
Comment on lines +258 to +262
await user.click(within(wrap).getByRole('button', { name: 'Options menu' }));
// with fuzzy filtering off, the "search" (fuzzy id/name/description) option
// is removed -> name__icontains, name, id remain
const options = screen.getAllByRole('option');
expect(options).toHaveLength(3);
Assert exactly one chip before clicking its close button; use user.click for option selection in selectFrom; scope option counts to the Select under test so options from other open Selects aren't counted.
@blaipr

blaipr commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Pushed a commit: assert there is exactly one chip before clicking its close button, use user.click for the option selection in selectFrom, and scope the option counts to the select under test so options from other open selects are not counted.

@cigamit
cigamit merged commit 478874a into ctrliq:main Jun 18, 2026
@cigamit cigamit self-assigned this Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants