Skip to content

Conversation

@parthaa
Copy link
Collaborator

@parthaa parthaa commented Nov 7, 2025

This relates to converting the following tests to RTL using AI :)

webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap
webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap
webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap
webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap
webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap
webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap
webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap
webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap
webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap

Summary by Sourcery

Convert RH Cloud Host Details and related test suites from snapshot-based testing to explicit Jest and React Testing Library tests, removing legacy snapshot files

Enhancements:

  • Replace snapshot-testing utilities with manual Jest tests for selectors, reducers, actions, and helpers
  • Migrate component tests to React Testing Library with render and screen assertions

Tests:

  • Add unit tests for foremanUrl, vulnerabilityDisabled, and hasNoInsightsFacet helpers
  • Rewrite InsightsTab actions, reducer, and selectors tests to verify dispatches and state changes
  • Add RTL tests for state wrapper helpers, SwitcherPF4, HelpLabel, and InsightsTab components

Chores:

  • Remove outdated snapshots directories and snapshot files

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 7, 2025

Reviewer's Guide

This PR standardizes tests by replacing snapshot-driven patterns with explicit React Testing Library and Jest assertions across helpers, actions, reducers, selectors, and components, and removes obsolete snapshot files.

File-Level Changes

Change Details Files
Convert helpers and selectors tests from snapshot-based to explicit jest tests
  • Replace testSelectorsSnapshotWithFixtures with describe/it blocks
  • Use expect assertions in place of fixtures and snapshots
  • Remove fixtures object definitions and snapshot files
webpack/__tests__/ForemanRhCloudHelpers.test.js
webpack/__tests__/ForemanRhCloudSelectors.test.js
webpack/__tests__/ForemanRhCloudTestHelpers.test.js
webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js
Convert action tests to explicit dispatch and assertion pattern
  • Import INSIGHTS_HITS_* constants and mock API.get in each it block
  • Use dispatch mock and expect calls for request, success, and error handling
  • Remove testActionSnapshotWithFixtures usage
webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js
Convert reducer tests to explicit state assertions
  • Use Immutable() for initial state setup
  • Write separate it blocks for REQUEST and SUCCESS handling
  • Remove testReducerSnapshotWithFixtures usage
webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js
Convert component tests to React Testing Library
  • Import React, render, screen, and jest-dom
  • Replace testComponentSnapshotsWithFixtures with render and screen-based assertions
  • Assert presence and props of rendered elements
webpack/common/Switcher/__tests__/SwitcherPF4.test.js
webpack/common/Switcher/__tests__/HelpLabel.test.js
webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js
Remove obsolete snapshot files
  • Delete all .snap files under snapshots directories
webpack/**/__snapshots__/*.snap

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • You can move the import '@testing-library/jest-dom' into your Jest setup file to remove the boilerplate in every test.
  • Consider standardizing your describe/it naming conventions (e.g. module vs. helper names) across all test files for better consistency.
  • In your async action error test, you might also assert that the failure action (INSIGHTS_HITS_FAILURE) is not dispatched, to more fully cover the error path.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You can move the `import '@testing-library/jest-dom'` into your Jest setup file to remove the boilerplate in every test.
- Consider standardizing your describe/it naming conventions (e.g. module vs. helper names) across all test files for better consistency.
- In your async action error test, you might also assert that the failure action (INSIGHTS_HITS_FAILURE) is *not* dispatched, to more fully cover the error path.

## Individual Comments

### Comment 1
<location> `webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js:33-35` </location>
<code_context>
+    expect(newState.hits).toEqual([]);
+  });
+
+  it('should handle INSIGHTS_HITS_SUCCESS', () => {
+    const initialState = Immutable({ hits: [] });
+    const action = {
       type: INSIGHTS_HITS_SUCCESS,
       payload: { hits },
-    },
-  },
-};
-
-describe('AccountList reducer', () =>
-  testReducerSnapshotWithFixtures(reducer, fixtures));
+    };
+    const newState = reducer(initialState, action);
+    expect(newState.hits).toEqual(hits);
+  });
+});
</code_context>

<issue_to_address>
**suggestion (testing):** Add a test for handling unexpected payloads or missing hits in INSIGHTS_HITS_SUCCESS.

Please add a test where INSIGHTS_HITS_SUCCESS is dispatched with a payload missing the 'hits' property or with 'hits' as undefined/null to verify the reducer's behavior in these scenarios.

```suggestion
    expect(newState.hits).toEqual(hits);
  });

  it('should handle INSIGHTS_HITS_SUCCESS with missing hits property', () => {
    const initialState = Immutable({ hits: [] });
    const action = {
      type: INSIGHTS_HITS_SUCCESS,
      payload: {},
    };
    const newState = reducer(initialState, action);
    expect(newState).toHaveProperty('hits');
    expect(newState.hits).toEqual([]);
  });

  it('should handle INSIGHTS_HITS_SUCCESS with hits as undefined', () => {
    const initialState = Immutable({ hits: [] });
    const action = {
      type: INSIGHTS_HITS_SUCCESS,
      payload: { hits: undefined },
    };
    const newState = reducer(initialState, action);
    expect(newState).toHaveProperty('hits');
    expect(newState.hits).toEqual([]);
  });

  it('should handle INSIGHTS_HITS_SUCCESS with hits as null', () => {
    const initialState = Immutable({ hits: [] });
    const action = {
      type: INSIGHTS_HITS_SUCCESS,
      payload: { hits: null },
    };
    const newState = reducer(initialState, action);
    expect(newState).toHaveProperty('hits');
    expect(newState.hits).toEqual([]);
  });
});
```
</issue_to_address>

### Comment 2
<location> `webpack/common/Switcher/__tests__/SwitcherPF4.test.js:7-16` </location>
<code_context>
-  describe('rendering', () =>
-    testComponentSnapshotsWithFixtures(InsightsTab, fixtures));
+  describe('rendering', () => {
+    it('should render with props', () => {
+      render(<InsightsTab {...props} />);
+      expect(screen.getByText('Recommendations')).toBeInTheDocument();
</code_context>

<issue_to_address>
**suggestion (testing):** Add a test for the onChange callback to verify user interaction.

Please add a test that simulates user interaction and verifies the onChange callback is triggered.
</issue_to_address>

### Comment 3
<location> `webpack/common/Switcher/__tests__/HelpLabel.test.js:7-16` </location>
<code_context>
-  describe('rendering', () =>
-    testComponentSnapshotsWithFixtures(InsightsTab, fixtures));
+  describe('rendering', () => {
+    it('should render with props', () => {
+      render(<InsightsTab {...props} />);
+      expect(screen.getByText('Recommendations')).toBeInTheDocument();
</code_context>

<issue_to_address>
**suggestion (testing):** Add a test for accessibility attributes and user interaction.

Please add a test to check that the HelpLabel button includes accessibility attributes and handles user interactions like clicks.
</issue_to_address>

### Comment 4
<location> `webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js:10-12` </location>
<code_context>
-  describe('rendering', () =>
-    testComponentSnapshotsWithFixtures(InsightsTab, fixtures));
+  describe('rendering', () => {
+    it('should render with props', () => {
+      render(<InsightsTab {...props} />);
+      expect(screen.getByText('Recommendations')).toBeInTheDocument();
+    });
+  });
</code_context>

<issue_to_address>
**suggestion (testing):** Add tests for edge cases such as missing or partial props.

Please add tests for scenarios where props are missing or set to undefined/null to verify the component handles these cases without errors.
</issue_to_address>

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.

@parthaa parthaa changed the title SAT-38755 - Convert RH Cloud Host Details snapshots to RTL WIP - SAT-38755 - Convert RH Cloud Host Details snapshots to RTL Nov 7, 2025
@parthaa parthaa marked this pull request as draft November 7, 2025 19:01
import { noop } from 'foremanReact/common/helpers';
import InsightsCloudSync from './InsightsCloudSync';

// Mock webpack share scopes for module federation
Copy link
Member

Choose a reason for hiding this comment

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

@MariaAga We need to do it in the core

Copy link
Member

Choose a reason for hiding this comment

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

Probably, why was it needed for the test?

vulnerabilityDisabled({
describe('ForemanRhCloud helpers', () => {
it('should return foreman Url', () => {
expect(foremanUrl('/test_path')).toBe('MY_TEST_URL_PREFIX.example.com/test_path');
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a core function instead of creating our own one?

selectForemanInventoryUpload(state),
'should return InsightsCloudSync': () => selectInsightsCloudSync(state),
};
describe('ForemanRhCloud selectors', () => {
Copy link
Member

Choose a reason for hiding this comment

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

I would argue that if the selector is trivial, we may skip this test entirely and make sure we're testing the components that use those selectors

const fixtures = {
'should return rhCloud wrapper': () =>
rhCloudStateWrapper({ inventoryChild: {} }, { insightsChild: {} }),
describe('ForemanRhCloud helpers', () => {
Copy link
Member

Choose a reason for hiding this comment

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

This file feels a bit meta-testing. We're testing the test helpers 🤔

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