-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: Improve conditional rendering in ChartWidget #36806
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 all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
12dd9af
refactor: Improve conditional rendering in ChartWidget
rahulbarwal 97fd509
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal 2b7813a
refactor: Improve conditional rendering in ChartWidget
rahulbarwal 5727959
Adds ChartWidget rendering unit tests
rahulbarwal 26533d6
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
rahulbarwal b1db1b6
refactor: Improve conditional rendering in ChartWidget unit tests
rahulbarwal fc812fd
refactor: Remove unused snapshot file for ChartWidget unit tests
rahulbarwal d76fd56
Removes unnecessary lines
rahulbarwal fa8f9c3
Refactor ChartWidget unit tests and improve conditional rendering
rahulbarwal 09b7635
Refactor ChartWidget unit tests: Remove unnecessary lines and improve…
rahulbarwal 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
125 changes: 125 additions & 0 deletions
125
app/client/src/widgets/ChartWidget/widget/ChartsRendered.test.tsx
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,125 @@ | ||
| import { RenderModes } from "constants/WidgetConstants"; | ||
| import ChartWidget, { type ChartWidgetProps } from "."; | ||
| import { LabelOrientation, type ChartData } from "../constants"; | ||
| import { EmptyChartData } from "../component/EmptyChartData"; | ||
| import type { WidgetError } from "widgets/BaseWidget"; | ||
|
|
||
| describe("ChartWidget getWidgetView", () => { | ||
| let chartWidget: ChartWidget; | ||
|
|
||
| const seriesData1: ChartData = { | ||
| seriesName: "series1", | ||
| data: [{ x: "x1", y: 1 }], | ||
| color: "series1color", | ||
| }; | ||
| const seriesData2: ChartData = { | ||
| seriesName: "series2", | ||
| data: [{ x: "x1", y: 2 }], | ||
| color: "series2color", | ||
| }; | ||
| const defaultProps: ChartWidgetProps = { | ||
| allowScroll: true, | ||
| showDataPointLabel: true, | ||
| chartData: { | ||
| seriesID1: seriesData1, | ||
| seriesID2: seriesData2, | ||
| }, | ||
| chartName: "chart name", | ||
| type: "CHART_WIDGET", | ||
| chartType: "AREA_CHART", | ||
| customEChartConfig: {}, | ||
| customFusionChartConfig: { type: "type", dataSource: undefined }, | ||
| hasOnDataPointClick: true, | ||
| isVisible: true, | ||
| isLoading: false, | ||
| setAdaptiveYMin: false, | ||
| labelOrientation: LabelOrientation.AUTO, | ||
| onDataPointClick: "", | ||
| widgetId: "widgetID", | ||
| xAxisName: "xaxisname", | ||
| yAxisName: "yaxisname", | ||
| borderRadius: "1", | ||
| boxShadow: "1", | ||
| primaryColor: "primarycolor", | ||
| fontFamily: "fontfamily", | ||
| dimensions: { componentWidth: 11, componentHeight: 11 }, | ||
| parentColumnSpace: 1, | ||
| parentRowSpace: 1, | ||
| topRow: 0, | ||
| bottomRow: 0, | ||
| leftColumn: 0, | ||
| rightColumn: 0, | ||
| widgetName: "widgetName", | ||
| version: 1, | ||
| renderMode: RenderModes.CANVAS, | ||
| }; | ||
| const errors: WidgetError[] = [ | ||
| { | ||
| name: "error", | ||
| type: "configuration", | ||
| message: "We have a error", | ||
| }, | ||
| ]; | ||
|
|
||
| describe("loading state", () => { | ||
| it("isLoading: true", () => { | ||
| chartWidget = new ChartWidget({ ...defaultProps, isLoading: true }); | ||
|
|
||
| const view = chartWidget.getWidgetView(); | ||
|
|
||
| expect(view.props.children.props.isLoading).toBe(true); | ||
| }); | ||
|
|
||
| it("isLoading: true + errors", () => { | ||
| chartWidget = new ChartWidget({ | ||
| ...defaultProps, | ||
| isLoading: true, | ||
| errors, | ||
| }); | ||
|
|
||
| const view = chartWidget.getWidgetView(); | ||
|
|
||
| expect(view.props.children.props.isLoading).toBe(true); | ||
| }); | ||
| it("isLoading: true + emptyChartData", () => { | ||
| chartWidget = new ChartWidget({ | ||
| ...defaultProps, | ||
| isLoading: true, | ||
| chartData: {}, | ||
| }); | ||
|
|
||
| const view = chartWidget.getWidgetView(); | ||
|
|
||
| expect(view.props.children.props.isLoading).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it("renders error state", () => { | ||
| chartWidget = new ChartWidget({ | ||
| ...defaultProps, | ||
| errors, | ||
| }); | ||
|
|
||
| const view = chartWidget.getWidgetView(); | ||
|
|
||
| expect(view.props.error.message).toBe("We have a error"); | ||
| }); | ||
|
|
||
| it("renders empty chart data state", () => { | ||
| chartWidget = new ChartWidget({ ...defaultProps, chartData: {} }); | ||
|
|
||
| const view = chartWidget.getWidgetView(); | ||
|
|
||
| expect(view.type).toEqual(EmptyChartData); | ||
| }); | ||
|
|
||
| it("renders chart with data", () => { | ||
| chartWidget = new ChartWidget(defaultProps); | ||
| const view = chartWidget.getWidgetView(); | ||
|
|
||
| expect(view.props.children.props.chartData).toEqual({ | ||
| seriesID1: seriesData1, | ||
| seriesID2: seriesData2, | ||
| }); | ||
| }); | ||
| }); |
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
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.