-
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
Draft
parthaa
wants to merge
7
commits into
theforeman:develop
Choose a base branch
from
parthaa:sat-38755
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ecc480
SAT-38755 - RH Cloud Host Details snapshots to RTL
parthaa 732ccd4
Addressing comments
parthaa ab7f3c9
Addressing comments
parthaa 6e7b57a
Addressing comments
parthaa d728cf0
more
parthaa 8d62b97
more
parthaa 56a2487
more
parthaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 19 additions & 7 deletions
26
webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,25 @@ | ||
| import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
|
|
||
| import InsightsTab from '../InsightsTab'; | ||
| import { props } from './InsightsTab.fixtures'; | ||
|
|
||
| const fixtures = { | ||
| 'render with props': props, | ||
| }; | ||
|
|
||
| describe('InsightsTab', () => { | ||
| describe('rendering', () => | ||
| testComponentSnapshotsWithFixtures(InsightsTab, fixtures)); | ||
| describe('rendering', () => { | ||
| it('should render with props', () => { | ||
| render(<InsightsTab {...props} />); | ||
| expect(screen.getByText('Recommendations')).toBeInTheDocument(); | ||
sourcery-ai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it('should render empty state when hits array is empty', () => { | ||
| render(<InsightsTab hostID={1} hits={[]} />); | ||
| expect(screen.getByText('No recommendations were found for this host!')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should use default props when hits is not provided', () => { | ||
| render(<InsightsTab hostID={1} />); | ||
| expect(screen.getByText('No recommendations were found for this host!')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
51 changes: 42 additions & 9 deletions
51
webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,52 @@ | ||
| import { testActionSnapshotWithFixtures } from '@theforeman/test'; | ||
| import { API } from 'foremanReact/redux/API'; | ||
| import { fetchHits } from '../InsightsTabActions'; | ||
| import { hostID, hits } from './InsightsTab.fixtures'; | ||
| import { | ||
| INSIGHTS_HITS_REQUEST, | ||
| INSIGHTS_HITS_SUCCESS, | ||
| INSIGHTS_HITS_FAILURE, | ||
| } from '../InsightsTabConstants'; | ||
|
|
||
| jest.mock('foremanReact/redux/API'); | ||
| API.get.mockImplementation(async () => ({ data: { hits } })); | ||
|
|
||
| const fixtures = { | ||
| 'should fetchHits': () => fetchHits(hostID), | ||
| 'should fetchHits with error': () => { | ||
| describe('InsightsTab actions', () => { | ||
| it('should fetchHits', async () => { | ||
| API.get.mockImplementation(async () => ({ data: { hits } })); | ||
| const dispatch = jest.fn(); | ||
|
|
||
| await fetchHits(hostID)(dispatch); | ||
|
|
||
| expect(dispatch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: INSIGHTS_HITS_REQUEST, | ||
| }) | ||
| ); | ||
| expect(dispatch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: INSIGHTS_HITS_SUCCESS, | ||
| payload: { hits }, | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it('should fetchHits with error', async () => { | ||
| API.get.mockImplementationOnce(() => | ||
| Promise.reject(new Error('Network error!')) | ||
| ); | ||
| return fetchHits(hostID); | ||
| }, | ||
| }; | ||
| const dispatch = jest.fn(); | ||
|
|
||
| await fetchHits(hostID)(dispatch); | ||
|
|
||
| describe('InsightsTab actions', () => testActionSnapshotWithFixtures(fixtures)); | ||
| expect(dispatch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: INSIGHTS_HITS_REQUEST, | ||
| }) | ||
| ); | ||
| // Error handling dispatches a toast notification, not INSIGHTS_HITS_FAILURE | ||
| expect(dispatch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: 'TOASTS_ADD', | ||
| }) | ||
| ); | ||
| }); | ||
| }); |
70 changes: 56 additions & 14 deletions
70
webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,68 @@ | ||
| import { testReducerSnapshotWithFixtures } from '@theforeman/test'; | ||
| import Immutable from 'seamless-immutable'; | ||
| import reducer from '../InsightsTabReducer'; | ||
| import { hits } from './InsightsTab.fixtures'; | ||
| import { | ||
| INSIGHTS_HITS_REQUEST, | ||
| INSIGHTS_HITS_SUCCESS, | ||
| } from '../InsightsTabConstants'; | ||
|
|
||
| const fixtures = { | ||
| 'should return the initial state': {}, | ||
| 'should handle INSIGHTS_HITS_REQUEST': { | ||
| action: { | ||
| describe('AccountList reducer', () => { | ||
| it('should return the initial state', () => { | ||
| const initialState = Immutable({ hits: [] }); | ||
| expect(reducer(undefined, {})).toEqual(initialState); | ||
| }); | ||
|
|
||
| it('should handle INSIGHTS_HITS_REQUEST', () => { | ||
| const initialState = Immutable({ hits: [] }); | ||
| const action = { | ||
| type: INSIGHTS_HITS_REQUEST, | ||
| payload: {}, | ||
| }, | ||
| }, | ||
| 'should handle INSIGHTS_HITS_SUCCESS': { | ||
| action: { | ||
| }; | ||
| const newState = reducer(initialState, action); | ||
| expect(newState).toHaveProperty('hits'); | ||
| expect(newState.hits).toEqual([]); | ||
| }); | ||
|
|
||
| it('should handle INSIGHTS_HITS_SUCCESS', () => { | ||
| const initialState = Immutable({ hits: [] }); | ||
| const action = { | ||
| type: INSIGHTS_HITS_SUCCESS, | ||
| payload: { hits }, | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| const newState = reducer(initialState, action); | ||
| expect(newState.hits).toEqual(hits); | ||
| }); | ||
|
|
||
| it('should handle INSIGHTS_HITS_SUCCESS with missing hits in payload', () => { | ||
| const initialState = Immutable({ hits: [] }); | ||
| const action = { | ||
| type: INSIGHTS_HITS_SUCCESS, | ||
| payload: {}, | ||
| }; | ||
| const newState = reducer(initialState, action); | ||
| expect(newState).toHaveProperty('hits'); | ||
| expect(newState.hits).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should handle INSIGHTS_HITS_SUCCESS with undefined hits', () => { | ||
| 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).toBeUndefined(); | ||
| }); | ||
|
|
||
| describe('AccountList reducer', () => | ||
| testReducerSnapshotWithFixtures(reducer, fixtures)); | ||
| it('should handle INSIGHTS_HITS_SUCCESS with null hits', () => { | ||
| 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).toBeNull(); | ||
| }); | ||
| }); |
12 changes: 5 additions & 7 deletions
12
webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| import { testSelectorsSnapshotWithFixtures } from '@theforeman/test'; | ||
| import { hostInsightsStateWrapper } from '../../ForemanRhCloudTestHelpers'; | ||
| import { hits } from './InsightsTab.fixtures'; | ||
| import { selectHits } from '../InsightsTabSelectors'; | ||
|
|
||
| const state = hostInsightsStateWrapper({ hits }); | ||
|
|
||
| const fixtures = { | ||
| 'should return hits': () => selectHits(state), | ||
| }; | ||
|
|
||
| describe('InsightsTab selectors', () => | ||
| testSelectorsSnapshotWithFixtures(fixtures)); | ||
| describe('InsightsTab selectors', () => { | ||
| it('should return hits', () => { | ||
| expect(selectHits(state)).toEqual(hits); | ||
| }); | ||
| }); |
34 changes: 0 additions & 34 deletions
34
webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?