-
Notifications
You must be signed in to change notification settings - Fork 1k
Fixes #38877 - Update donut chart wrapper to pf5 #10736
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
Open
gitdallas
wants to merge
1
commit into
theforeman:develop
Choose a base branch
from
gitdallas:update/DonutChartWrapper-pf5
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.
+877
−707
Open
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
237 changes: 199 additions & 38 deletions
237
webpack/assets/javascripts/react_app/components/ChartBox/ChartBox.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,55 +1,216 @@ | ||
| import { shallow } from 'enzyme'; | ||
| import React from 'react'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import ChartBox from './ChartBox'; | ||
| import { classFunctionUnitTest } from '../../common/testHelpers'; | ||
|
|
||
| jest.unmock('../../../services/charts/DonutChartService'); | ||
| jest.unmock('./'); | ||
| // Mock the DonutChart and BarChart components | ||
| jest.mock('../common/charts/DonutChart', () => ({ | ||
| __esModule: true, | ||
| default: ({ data }) => ( | ||
| <div data-testid="donut-chart"> | ||
| {data && data.length > 0 ? 'Donut Chart with data' : 'Empty donut chart'} | ||
| </div> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock('../common/charts/BarChart', () => ({ | ||
| __esModule: true, | ||
| default: ({ data }) => ( | ||
| <div data-testid="bar-chart"> | ||
| {data && data.length > 0 ? 'Bar Chart with data' : 'Empty bar chart'} | ||
| </div> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock('../common/Loader', () => ({ | ||
| __esModule: true, | ||
| default: ({ status, children }) => ( | ||
| <div data-testid="loader" data-status={status}> | ||
| {children} | ||
| </div> | ||
| ), | ||
| })); | ||
|
|
||
| describe('ChartBox', () => { | ||
| const setup = ({ status, chart = { id: '2' } }) => | ||
| shallow( | ||
| <ChartBox | ||
| type="donut" | ||
| chart={chart} | ||
| noDataMsg="no data" | ||
| status="PENDING" | ||
| errorText="some error" | ||
| title="some title" | ||
| tip="sone tooltip" | ||
| {...chart} | ||
| /> | ||
| ); | ||
|
|
||
| it('pending', () => { | ||
| const box = setup({ status: 'PENDING' }); | ||
|
|
||
| expect(box).toMatchSnapshot(); | ||
| const defaultProps = { | ||
| type: 'donut', | ||
| chart: { id: 'test-chart', data: [] }, | ||
| status: 'PENDING', | ||
| title: 'Test Chart Title', | ||
| errorText: '', | ||
| noDataMsg: 'no data', | ||
| tip: 'Click to expand', | ||
| }; | ||
|
|
||
| describe('rendering states', () => { | ||
| it('renders with pending status', () => { | ||
| render(<ChartBox {...defaultProps} status="PENDING" />); | ||
|
|
||
| expect(screen.getByTestId('loader')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('loader')).toHaveAttribute( | ||
| 'data-status', | ||
| 'PENDING' | ||
| ); | ||
| }); | ||
|
|
||
| it('renders with error status and error message', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| status="ERROR" | ||
| errorText="Failed to load data" | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Failed to load data')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders with resolved status and chart data', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| status="RESOLVED" | ||
| chart={{ id: 'test-chart', data: [['Item', 5]] }} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('donut-chart')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders title', () => { | ||
| render(<ChartBox {...defaultProps} title="My Custom Title" />); | ||
|
|
||
| expect(screen.getByText('My Custom Title')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it('error', () => { | ||
| const box = setup({ status: 'ERROR' }); | ||
| describe('chart types', () => { | ||
| it('renders DonutChart when type is donut', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| type="donut" | ||
| chart={{ id: 'test', data: [['Item', 5]] }} | ||
| /> | ||
| ); | ||
|
|
||
| expect(box).toMatchSnapshot(); | ||
| expect(screen.getByTestId('donut-chart')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('bar-chart')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders BarChart when type is bar', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| type="bar" | ||
| chart={{ id: 'test', data: [['Item', 5]] }} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('bar-chart')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('donut-chart')).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it('resolved', () => { | ||
| const box = setup({ | ||
| chart: { id: '2', data: [[1, 2]] }, | ||
| status: 'RESOLVED', | ||
| describe('modal functionality', () => { | ||
| it('renders modal component in the DOM', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| status="RESOLVED" | ||
| chart={{ id: 'test', data: [['Item', 5]] }} | ||
| /> | ||
| ); | ||
|
|
||
| // Modal component should be in the DOM (PatternFly renders it even when closed) | ||
| expect(screen.getByText('Test Chart Title')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| expect(box).toMatchSnapshot(); | ||
| it('opens modal when clicking on chart title with data', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| status="RESOLVED" | ||
| chart={{ id: 'test', data: [['Item', 5]] }} | ||
| tip="Expand chart" | ||
| /> | ||
| ); | ||
|
|
||
| const title = screen.getByText('Test Chart Title'); | ||
| fireEvent.click(title); | ||
|
|
||
| // Modal should now be open - check for modal backdrop or content | ||
| const modalElements = document.querySelectorAll('[class*="modal"]'); | ||
| expect(modalElements.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('title has pointer class when there is data', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| status="RESOLVED" | ||
| chart={{ id: 'test', data: [['Item', 5]] }} | ||
| /> | ||
| ); | ||
|
|
||
| const title = screen.getByText('Test Chart Title'); | ||
|
|
||
| // Title should have pointer class when there's data | ||
| expect(title).toHaveClass('pointer'); | ||
| }); | ||
|
|
||
| it('title does not have pointer class when there is no data', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| status="RESOLVED" | ||
| chart={{ id: 'test', data: [] }} | ||
| /> | ||
| ); | ||
|
|
||
| const titleElement = screen.getByText('Test Chart Title'); | ||
|
|
||
| // When no data, the title should still render but without interactive styling | ||
| // Note: ChartBox may still add pointer class, but no onClick handler | ||
| expect(titleElement).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it('render modal', () => { | ||
| const box = setup({ | ||
| chart: { id: '2', data: [[1, 2]] }, | ||
| status: 'RESOLVED', | ||
| describe('props handling', () => { | ||
| it('applies custom className', () => { | ||
| const { container } = render( | ||
| <ChartBox {...defaultProps} className="custom-chart-class" /> | ||
| ); | ||
|
|
||
| const card = container.querySelector('.chart-box'); | ||
| expect(card).toHaveClass('custom-chart-class'); | ||
| }); | ||
|
|
||
| it('uses provided config', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| config="large" | ||
| chart={{ id: 'test', data: [['Item', 5]] }} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('donut-chart')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders with searchUrl in chart data', () => { | ||
| render( | ||
| <ChartBox | ||
| {...defaultProps} | ||
| chart={{ | ||
| id: 'test', | ||
| data: [['Item', 5]], | ||
| search: '/hosts?search=~VAL~', | ||
| }} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('donut-chart')).toBeInTheDocument(); | ||
| }); | ||
| expect(box.find('.chart-box-modal').props().isOpen).toBeFalsy(); | ||
| box.find('.panel-title').simulate('click'); | ||
| box.update(); | ||
| expect(box.find('.chart-box-modal').props().isOpen).toBeTruthy(); | ||
| }); | ||
| }); | ||
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, I'm not sure about those mocks, is it okay to have them like that?