-
Notifications
You must be signed in to change notification settings - Fork 69
SAT-48787 - replace InsightsTab Enzyme integration test with RTL #1250
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
Merged
chris1984
merged 1 commit into
theforeman:develop
from
tlabaj:SAT-48787-insights-tab-integration
Sep 2, 2026
Merged
Changes from all commits
Commits
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
There are no files selected for viewing
77 changes: 69 additions & 8 deletions
77
webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.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,17 +1,78 @@ | ||
| import React from 'react'; | ||
| import { IntegrationTestHelper } from '@theforeman/test'; | ||
| import { screen, waitFor } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import { Provider } from 'react-redux'; | ||
| import { applyMiddleware, combineReducers, createStore } from 'redux'; | ||
| import thunk from 'redux-thunk'; | ||
| import { rtlHelpers } from 'foremanReact/common/rtlTestHelpers'; | ||
| import { API } from 'foremanReact/redux/API'; | ||
|
|
||
| import InsightsTab from '../index'; | ||
| import reducers from '../../ForemanRhCloudReducers'; | ||
| import { hostID } from './InsightsTab.fixtures'; | ||
| import { INSIGHTS_HITS_SUCCESS } from '../InsightsTabConstants'; | ||
| import { hostID, hits } from './InsightsTab.fixtures'; | ||
|
|
||
| describe('InsightsTab integration test', () => { | ||
| it('should flow', async () => { | ||
| const integrationTestHelper = new IntegrationTestHelper(reducers); | ||
| const component = integrationTestHelper.mount( | ||
| const { renderWithI18n } = rtlHelpers; | ||
|
|
||
| jest.mock('foremanReact/redux/API'); | ||
|
|
||
| const recommendationTitle = | ||
| 'New Ansible Engine packages are inaccessible when dedicated Ansible repo is not enabled'; | ||
|
|
||
| const createTabStore = () => | ||
| createStore(combineReducers({ ...reducers }), applyMiddleware(thunk)); | ||
|
|
||
| const renderConnectedTab = (store = createTabStore()) => | ||
| renderWithI18n( | ||
| <Provider store={store}> | ||
| <InsightsTab hostID={hostID} /> | ||
| </Provider> | ||
| ); | ||
|
|
||
| describe('InsightsTab integration test', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('requests hits for the host and shows empty state when there are none', async () => { | ||
| let resolveHits; | ||
| API.get.mockReturnValue( | ||
| new Promise(resolve => { | ||
| resolveHits = resolve; | ||
| }) | ||
| ); | ||
| component.update(); | ||
| /** Create a Flow test */ | ||
|
|
||
| const store = createTabStore(); | ||
| store.dispatch({ | ||
| type: INSIGHTS_HITS_SUCCESS, | ||
| payload: { hits }, | ||
| }); | ||
|
|
||
| renderConnectedTab(store); | ||
|
|
||
| expect(await screen.findByText(recommendationTitle)).toBeInTheDocument(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(API.get).toHaveBeenCalledWith(`/insights_cloud/hits/${hostID}`); | ||
| }); | ||
|
|
||
| resolveHits({ data: { hits: [] } }); | ||
|
|
||
| expect( | ||
| await screen.findByRole('heading', { | ||
| name: 'No recommendations were found for this host!', | ||
| }) | ||
| ).toBeInTheDocument(); | ||
| expect(screen.queryByText(recommendationTitle)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows recommendation titles from the hits API response', async () => { | ||
| API.get.mockResolvedValue({ data: { hits } }); | ||
|
|
||
| renderConnectedTab(); | ||
|
|
||
| expect(await screen.findByText(recommendationTitle)).toBeInTheDocument(); | ||
|
|
||
| expect(API.get).toHaveBeenCalledWith(`/insights_cloud/hits/${hostID}`); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.