Skip to content

Commit 5094fd1

Browse files
authored
refactor(charts): migrate Cypress tests to Playwright Component Tests (#8609)
1 parent 9deea50 commit 5094fd1

50 files changed

Lines changed: 3035 additions & 1678 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ jobs:
5656
- name: Install
5757
run: yarn install --immutable
5858

59+
- name: Override react-is for charts
60+
if: ${{ matrix.react == '18' }}
61+
run: jq '.resolutions["react-is"] = "18"' package.json > tmp.json && mv tmp.json package.json
62+
5963
- name: Install React 18
6064
if: ${{ matrix.react == '18' }}
6165
run: |
@@ -88,7 +92,6 @@ jobs:
8892
matrix:
8993
spec:
9094
- base
91-
- charts
9295
- cypress-commands
9396
- main/src/components
9497
- main/src/webComponents
@@ -108,10 +111,6 @@ jobs:
108111
- name: Install
109112
run: yarn install --immutable
110113

111-
- name: Override react-is for charts
112-
if: ${{ matrix.react == '18' && matrix.spec == 'charts' }}
113-
run: jq '.resolutions["react-is"] = "18"' package.json > tmp.json && mv tmp.json package.json
114-
115114
- name: Install 18
116115
if: ${{ matrix.react == '18' }}
117116
run: |
@@ -154,4 +153,4 @@ jobs:
154153
with:
155154
github-token: ${{ secrets.GITHUB_TOKEN }}
156155
parallel-finished: true
157-
carryforward: 'base,charts,cypress-commands,main/src/components,main/src/internal,playwright'
156+
carryforward: 'base,cypress-commands,main/src/components,main/src/internal,playwright'

cypress.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
'**/src/enums/*',
1111
'**/*.stories.tsx',
1212
'**/*.test.{ts,tsx}',
13+
'**/*.module.css.ts',
1314
'**/node_modules/**',
1415
'**/dist/**',
1516
'packages/*/src/index.ts',

packages/charts/src/components/BarChart/BarChart.cy.tsx

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { expect, test } from '../../../../../../playwright/fixtures/main-fixtures.js';
2+
import { complexDataSet } from '../../../resources/DemoProps.js';
3+
import {
4+
testLoadingStates,
5+
testPassThroughProps,
6+
testStackAggregateTotals,
7+
testZoomingTool,
8+
} from '../../../test-utils/sharedTests.js';
9+
import { BarChart } from '../index.js';
10+
import {
11+
BarChartClickTest,
12+
BarChartDataPointClickTest,
13+
BarChartHighlightColorTest,
14+
BarChartLegendConfigTest,
15+
BarChartSecondYAxisTest,
16+
} from './BarChartTestComponents.js';
17+
18+
const dimensions = [{ accessor: 'name', interval: 0 }];
19+
const measures = [
20+
{ accessor: 'users', label: 'Users' },
21+
{ accessor: 'sessions', label: 'Active Sessions' },
22+
{ accessor: 'volume', label: 'Vol.' },
23+
];
24+
const baseProps = { dataset: complexDataSet, dimensions, measures };
25+
26+
test.describe('BarChart', () => {
27+
test('Basic', async ({ mount, page }) => {
28+
await mount(<BarChart {...baseProps} />);
29+
await expect(page.locator('.recharts-responsive-container')).toBeVisible();
30+
await expect(page.locator('.recharts-bar')).toHaveCount(3);
31+
await expect(page.locator('.recharts-bar-rectangles')).toHaveCount(3);
32+
});
33+
34+
test('click handlers', async ({ mount, page }) => {
35+
await mount(<BarChartClickTest />);
36+
37+
await page.getByText('January').click();
38+
await expect(page.getByTestId('click-count')).toHaveText('1');
39+
40+
await page.locator('[name="January"]').first().click();
41+
await expect(page.getByTestId('click-count')).toHaveText('2');
42+
await expect(page.getByTestId('last-payload')).toHaveText(JSON.stringify(complexDataSet[0]));
43+
44+
await page.locator('.recharts-legend-item-text').filter({ hasText: 'Users' }).click();
45+
await expect(page.getByTestId('legend-click-count')).toHaveText('1');
46+
await expect(page.getByTestId('last-legend-value')).toHaveText('Users');
47+
48+
await page.locator('.recharts-legend-item-text').filter({ hasText: 'Vol.' }).click();
49+
await expect(page.getByTestId('last-legend-datakey')).toHaveText('volume');
50+
});
51+
52+
testLoadingStates(BarChart, baseProps, { dimensions: [], measures: [] }, '.recharts-bar');
53+
54+
test('legendConfig', async ({ mount, page }) => {
55+
await mount(<BarChartLegendConfigTest />);
56+
await expect(page.getByTestId('catval').first()).toBeVisible();
57+
});
58+
59+
testZoomingTool(BarChart, baseProps);
60+
61+
testPassThroughProps(BarChart, { dimensions: [], measures: [] });
62+
63+
testStackAggregateTotals(BarChart, { dataset: complexDataSet.slice(0, 3), dimensions }, [
64+
{ accessor: 'users', stackId: 'A', label: 'Users' },
65+
{ accessor: 'sessions', stackId: 'A', label: 'Active Sessions' },
66+
]);
67+
68+
test('onDataPointClick', async ({ mount, page }) => {
69+
await mount(<BarChartDataPointClickTest />);
70+
71+
await page.locator('[name="January"]').first().click();
72+
await expect(page.getByTestId('dp-click-count')).toHaveText('1');
73+
await expect(page.getByTestId('dp-last-datakey')).not.toHaveText('');
74+
await expect(page.getByTestId('dp-last-value')).not.toHaveText('');
75+
await expect(page.getByTestId('dp-last-data-index')).not.toHaveText('-1');
76+
await expect(page.getByTestId('dp-last-payload')).toHaveText(JSON.stringify(complexDataSet[0]));
77+
});
78+
79+
test('highlightColor', async ({ mount, page }) => {
80+
await mount(<BarChartHighlightColorTest />);
81+
82+
// January has users=100 (<=200 → green), February has users=230 (>200 → red)
83+
await expect(page.locator('.recharts-bar-rectangle [fill="green"]').first()).toBeAttached();
84+
await expect(page.locator('.recharts-bar-rectangle [fill="red"]').first()).toBeAttached();
85+
});
86+
87+
test('secondYAxis', async ({ mount, page }) => {
88+
await mount(<BarChartSecondYAxisTest />);
89+
// BarChart is horizontal so the secondary "Y" axis renders as an additional XAxis
90+
await expect(page.locator('.recharts-xAxis')).toHaveCount(2);
91+
});
92+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { complexDataSet } from '../../../resources/DemoProps.js';
2+
import {
3+
createClickTestComponent,
4+
createDataPointClickTestComponent,
5+
createHighlightColorTestComponent,
6+
createLegendConfigTestComponent,
7+
createSecondYAxisTestComponent,
8+
} from '../../../test-utils/componentFactories.js';
9+
import { BarChart } from '../index.js';
10+
11+
const dimensions = [{ accessor: 'name', interval: 0 }];
12+
13+
const measures = [
14+
{
15+
accessor: (data: Record<string, number>) => data.users,
16+
label: 'Users',
17+
formatter: (val: number) => val.toLocaleString('en'),
18+
},
19+
{
20+
accessor: (data: Record<string, number>) => data.sessions,
21+
label: 'Active Sessions',
22+
formatter: (val: number) => `${val} sessions`,
23+
hideDataLabel: true,
24+
},
25+
{ accessor: 'volume', label: 'Vol.' },
26+
];
27+
28+
const baseProps = { dataset: complexDataSet, dimensions, measures };
29+
30+
export const BarChartClickTest = createClickTestComponent(BarChart, baseProps, {
31+
trackLegendValue: true,
32+
});
33+
34+
export const BarChartLegendConfigTest = createLegendConfigTestComponent(BarChart, baseProps);
35+
36+
export const BarChartDataPointClickTest = createDataPointClickTestComponent(BarChart, baseProps);
37+
38+
export const BarChartHighlightColorTest = createHighlightColorTestComponent(BarChart, baseProps, [
39+
{
40+
accessor: 'users',
41+
label: 'Users',
42+
highlightColor: (value: number) => (value > 200 ? 'red' : 'green'),
43+
},
44+
{ accessor: 'sessions', label: 'Active Sessions' },
45+
{ accessor: 'volume', label: 'Vol.' },
46+
]);
47+
48+
export const BarChartSecondYAxisTest = createSecondYAxisTestComponent(BarChart, baseProps, 'volume');

packages/charts/src/components/BulletChart/BulletChart.cy.tsx

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)