-
Notifications
You must be signed in to change notification settings - Fork 48
WIP - SAT-38755 - Convert RH Cloud Host Details snapshots to RTL #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| import { noop } from 'foremanReact/common/helpers'; | ||
| import InsightsCloudSync from './InsightsCloudSync'; | ||
|
|
||
| // Mock webpack share scopes for module federation |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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 🤔
This relates to converting the following tests to RTL using AI :)
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:
Tests:
Chores: