Skip to content

SAT-48787 - replace InsightsTab Enzyme integration test with RTL - #1250

Merged
chris1984 merged 1 commit into
theforeman:developfrom
tlabaj:SAT-48787-insights-tab-integration
Sep 2, 2026
Merged

chris1984 merged 1 commit into
theforeman:developfrom
tlabaj:SAT-48787-insights-tab-integration

Conversation

@tlabaj

@tlabaj tlabaj commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

What are the changes introduced in this pull request?

Replace the Enzyme InsightsTab integration test with React Testing Library so the connected host-details tab no longer depends on IntegrationTestHelper.
SAT-48787: https://redhat.atlassian.net/browse/SAT-48787
The connected tab now renders with a Redux store built from plugin reducers. API.get is mocked, and the test asserts:

  • empty heading when the hits API returns no recommendations
  • recommendation title when hits are returned
  • API.get is called with /insights_cloud/hits/:hostId

Considerations taken when implementing this change?

  • InsightsTab.test.js already covers the presentational component (empty vs list UI, sort by risk, fetchHits on mount). This file only covers Redux + API wiring.
  • Foreman’s renderWithStore uses core reducers, which do not include ForemanRhCloud.hostInsights. The test creates its own store from ForemanRhCloudReducers plus thunk, matching what IntegrationTestHelper used.
  • Inventory Dashboard and Toast Enzyme tests are out of scope for this ticket.

What are the testing steps for this pull request?

From the Foreman directory:

npx jest \
  --roots /home/vagrant/foreman_rh_cloud /home/vagrant/foreman/webpack \
  --config=/home/vagrant/foreman/webpack/jest.config.js \
  --setupFilesAfterEnv /home/vagrant/foreman_rh_cloud/webpack/test_setup.js \
  --setupFilesAfterEnv /home/vagrant/foreman/webpack/global_test_setup.js \
  --color \
  InsightsTab

That filter runs the InsightsTab suites, including InsightsTabIntegration.test.js. Both new cases should pass (empty state and hits list).

If the plugin is registered in Foreman, this is equivalent:

npm run test:plugins foreman_rh_cloud -- InsightsTab

Confirm webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js has no Enzyme imports (IntegrationTestHelper, mount, snapshots).

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js" line_range="41-44" />
<code_context>
+
+    renderConnectedTab();
+
+    expect(
+      await screen.findByRole('heading', {
+        name: 'No recommendations were found for this host!',
+      })
+    ).toBeInTheDocument();
+
</code_context>
<issue_to_address>
**issue (testing):** The empty-state assertion passes from the reducer's initial `hits: []` state before the mocked API request resolves, so this test also passes if the API response is never dispatched into Redux or the response-handling path is broken.

**Triggers:** When `API.get` remains pending or the success action fails to update the `hostInsights` reducer.

**Suggested fix:** Wait for the API request to resolve and assert that the empty state is rendered after the corresponding Redux update, or first assert the request is made and use an explicit state transition check.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js:44


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sourcery-ai sourcery-ai 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.

Sourcery assessment

Approved.

@MariaAga MariaAga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

code lgtm, and I ran the tests locally

@tlabaj
tlabaj force-pushed the SAT-48787-insights-tab-integration branch from 9039668 to 85c0af8 Compare September 2, 2026 13:25
@chris1984
chris1984 merged commit 69b0e95 into theforeman:develop Sep 2, 2026
17 checks passed
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.

3 participants