-
Notifications
You must be signed in to change notification settings - Fork 22
Fixes #38958 - Add basic Leapp preupgrade report table to the new job invocation page #165
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
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2baca5e
Fixes #38958 - Add leapp preupgrade table to job invocation page
kmalyjur 76c9218
Fix ESLint errors in plugin code
adamruzicka ca3b1e1
Fix test failures in PreupgradeReportsTable
adamruzicka ba5ec56
Drop trailing whitespace
adamruzicka b419319
Drop all (but one) global foremanReact mocks
adamruzicka 4a97492
Drop some more mocks
adamruzicka e369a39
Drop even more mocks
adamruzicka 24efc66
Migrate PreupgradeReportsList tests from snapshots to RTL
adamruzicka 7fbd625
Address review comments
adamruzicka f0f99ec
Move columns back to the table itself
adamruzicka 2c260dd
Pagination changes
adamruzicka 6a684d4
Address comments
adamruzicka b7fb96c
Drop custom perPageOptions
adamruzicka 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
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,4 +1,4 @@ | ||
| object @preupgrade_report_entry | ||
|
|
||
| attributes :id, :preupgrade_report_id, :host_id, :hostname, :title, :actor, :audience, | ||
| attributes :id, :detail, :preupgrade_report_id, :host_id, :hostname, :title, :actor, :audience, | ||
| :severity, :leapp_run_id, :summary, :tags, :flags, :created_at, :updated_at |
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
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,2 +1,28 @@ | ||
| const Pagination = () => jest.fn(); | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const Pagination = ({ page, perPage, onChange }) => ( | ||
| <div data-testid="pagination"> | ||
| <span>Page {page}</span> | ||
| <span>Per Page {perPage}</span> | ||
| <button onClick={() => onChange({ page: page + 1, perPage })}> | ||
| Next Page | ||
| </button> | ||
| <button onClick={() => onChange({ page: 1, perPage: 10 })}>Set 10</button> | ||
| <button onClick={() => onChange({ page: 1, perPage: 5 })}>Set 5</button> | ||
| </div> | ||
| ); | ||
|
|
||
| Pagination.propTypes = { | ||
| page: PropTypes.number, | ||
| perPage: PropTypes.number, | ||
| onChange: PropTypes.func, | ||
| }; | ||
|
|
||
| Pagination.defaultProps = { | ||
| page: 1, | ||
| perPage: 20, | ||
| onChange: () => {}, | ||
| }; | ||
|
|
||
| export default Pagination; |
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export const APIActions = { | ||
| get: jest.fn(), | ||
| }; |
kmalyjur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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
4 changes: 4 additions & 0 deletions
4
webpack/components/PreupgradeReportsTable/PreupgradeReportsTable.scss
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .leapp-report-section .table-title-section, | ||
| .leapp-report-section .table-toolbar-section { | ||
| padding-top: 0 !important; | ||
| } | ||
kmalyjur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
54 changes: 54 additions & 0 deletions
54
webpack/components/PreupgradeReportsTable/PreupgradeReportsTableConstants.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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import React from 'react'; | ||
| import { translate as __ } from 'foremanReact/common/I18n'; | ||
| import { Label } from '@patternfly/react-core'; | ||
|
|
||
| export const STATUS = { | ||
| PENDING: 'PENDING', | ||
| RESOLVED: 'RESOLVED', | ||
| ERROR: 'ERROR', | ||
| }; | ||
kmalyjur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
kmalyjur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export const PER_PAGE_OPTIONS = [ | ||
| { title: '5', value: 5 }, | ||
| { title: '10', value: 10 }, | ||
| { title: '20', value: 20 }, | ||
| { title: '50', value: 50 }, | ||
| ]; | ||
|
|
||
| export const columns = { | ||
| title: { | ||
| title: __('Title'), | ||
| wrapper: () => null, | ||
| }, | ||
| host: { | ||
| title: __('Host'), | ||
| wrapper: () => null, | ||
| }, | ||
| risk_factor: { | ||
| title: __('Risk Factor'), | ||
| wrapper: () => null, | ||
| }, | ||
| has_remediation: { | ||
| title: __('Has Remediation?'), | ||
| wrapper: () => null, | ||
| }, | ||
| inhibitor: { | ||
| title: __('Inhibitor?'), | ||
| wrapper: () => null, | ||
| }, | ||
| }; | ||
|
|
||
kmalyjur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export const renderSeverityLabel = severity => { | ||
| switch (severity) { | ||
| case 'high': | ||
| return <Label color="red">{__('High')}</Label>; | ||
| case 'medium': | ||
| return <Label color="orange">{__('Medium')}</Label>; | ||
| case 'low': | ||
| return <Label color="blue">{__('Low')}</Label>; | ||
| case 'info': | ||
| return <Label color="grey">{__('Info')}</Label>; | ||
| default: | ||
| return <Label color="grey">{severity || __('Info')}</Label>; | ||
| } | ||
| }; | ||
155 changes: 155 additions & 0 deletions
155
webpack/components/PreupgradeReportsTable/__tests__/PreupgradeReportsTable.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 |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import React from 'react'; | ||
| import { render, screen, waitFor, fireEvent } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom/extend-expect'; | ||
| import { Provider } from 'react-redux'; | ||
| import configureMockStore from 'redux-mock-store'; | ||
| import thunk from 'redux-thunk'; | ||
| import { APIActions } from 'foremanReact/redux/API'; | ||
| import PreupgradeReportsTable from '../index'; | ||
|
|
||
| jest.mock('foremanReact/redux/API'); | ||
| jest.mock('foremanReact/common/I18n', () => ({ | ||
| translate: text => text, | ||
| })); | ||
| jest.mock('foremanReact/components/PF4/TableIndexPage/Table/Table', () => ({ | ||
| Table: ({ children, customEmptyState, childrenOutsideTbody }) => ( | ||
| <table data-testid="table"> | ||
| {childrenOutsideTbody ? children : null} | ||
| <tbody> | ||
| {customEmptyState} | ||
| {!childrenOutsideTbody ? children : null} | ||
| </tbody> | ||
| </table> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock( | ||
| 'foremanReact/components/PF4/TableIndexPage/TableIndexPage', | ||
| () => ({ | ||
| __esModule: true, | ||
| default: ({ children, customToolbarItems }) => ( | ||
| <div data-testid="table-index-page"> | ||
| <div className="toolbar">{customToolbarItems}</div> | ||
| {children} | ||
| </div> | ||
| ), | ||
| }), | ||
| { virtual: true } | ||
| ); | ||
|
|
||
| jest.mock( | ||
| 'foremanReact/Root/Context/ForemanContext', | ||
| () => ({ | ||
| useForemanSettings: () => ({ | ||
| perPage: 20, | ||
| perPageOptions: [5, 10, 20, 50], | ||
| }), | ||
| }), | ||
| { virtual: true } | ||
| ); | ||
|
|
||
| const mockStore = configureMockStore([thunk]); | ||
|
|
||
| const mockJobId = 42; | ||
| const mockReportId = 999; | ||
| const mockJobData = { | ||
| id: mockJobId, | ||
| template_name: 'Run preupgrade via Leapp', | ||
| }; | ||
|
|
||
| const mockEntries = Array.from({ length: 12 }, (_, i) => ({ | ||
| id: i + 1, | ||
| title: `Report Entry ${i + 1}`, | ||
| hostname: 'example.com', | ||
| severity: i === 0 ? 'high' : 'low', | ||
| flags: i === 0 ? ['inhibitor'] : [], | ||
| detail: { remediations: i === 0 ? [{ type: 'cmd' }] : [] }, | ||
| })); | ||
|
|
||
| describe('PreupgradeReportsTable', () => { | ||
| let store; | ||
|
|
||
| beforeEach(() => { | ||
| store = mockStore({}); | ||
| jest.clearAllMocks(); | ||
|
|
||
| APIActions.get.mockImplementation(({ key, handleSuccess }) => { | ||
| return dispatch => { | ||
| if (key.includes('GET_LEAPP_REPORT_LIST')) | ||
| handleSuccess({ results: [{ id: mockReportId }] }); | ||
| if (key.includes('GET_LEAPP_REPORT_DETAIL')) | ||
| handleSuccess({ | ||
| id: mockReportId, | ||
| preupgrade_report_entries: mockEntries, | ||
| }); | ||
| return { type: 'MOCK_API_SUCCESS' }; | ||
| }; | ||
| }); | ||
| }); | ||
|
|
||
| const renderComponent = () => | ||
| render( | ||
| <Provider store={store}> | ||
| <PreupgradeReportsTable data={mockJobData} /> | ||
| </Provider> | ||
| ); | ||
|
|
||
| const expandSection = () => { | ||
| fireEvent.click(screen.getByText('Leapp preupgrade report')); | ||
| }; | ||
|
|
||
| it('renders data', async () => { | ||
| renderComponent(); | ||
| expandSection(); | ||
|
|
||
| await waitFor(() => screen.getByText('Report Entry 1')); | ||
|
|
||
| expect(screen.getByText('Report Entry 1')).toBeInTheDocument(); | ||
| expect(screen.getByText('Report Entry 5')).toBeInTheDocument(); | ||
| expect(screen.queryByText('Report Entry 6')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('paginates to the next page', async () => { | ||
| renderComponent(); | ||
| expandSection(); | ||
| await waitFor(() => screen.getByText('Report Entry 1')); | ||
|
|
||
| fireEvent.click(screen.getAllByText('Next Page')[0]); | ||
|
|
||
| await waitFor(() => screen.getByText('Report Entry 6')); | ||
| expect(screen.getByText('Report Entry 10')).toBeInTheDocument(); | ||
| expect(screen.queryByText('Report Entry 1')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('changes per_page limit to 10', async () => { | ||
| renderComponent(); | ||
| expandSection(); | ||
| await waitFor(() => screen.getByText('Report Entry 1')); | ||
|
|
||
| fireEvent.click(screen.getAllByText('Set 10')[0]); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Report Entry 10')).toBeInTheDocument(); | ||
| expect(screen.queryByText('Report Entry 11')).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it('renders empty state message when no issues found', async () => { | ||
| APIActions.get.mockImplementation(({ key, handleSuccess }) => { | ||
| return () => { | ||
| if (key.includes('GET_LEAPP_REPORT_LIST')) | ||
| handleSuccess({ results: [{ id: mockReportId }] }); | ||
| if (key.includes('GET_LEAPP_REPORT_DETAIL')) | ||
| handleSuccess({ id: mockReportId, preupgrade_report_entries: [] }); | ||
| return { type: 'EMPTY' }; | ||
| }; | ||
| }); | ||
|
|
||
| renderComponent(); | ||
| expandSection(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('No issues found')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); |
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.