Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const config: Config = {
'^.+\\.m?[jt]sx?$': 'babel-jest',
'^.+\\.svg$': 'jest-transform-stub'
},
setupFilesAfterEnv: ['<rootDir>/packages/testSetup.ts'],
setupFilesAfterEnv: ['<rootDir>/packages/testSetup.ts', 'jest-canvas-mock'],
testPathIgnorePatterns: ['<rootDir>/packages/react-integration/'],
transformIgnorePatterns: ['node_modules/victory-*/', '/node_modules/(?!(case-anything)/)'],
transformIgnorePatterns: ['/node_modules/victory-*/', '/node_modules/(?!(chart\\.js|echarts|zrender)).*\\.js$'],
coveragePathIgnorePatterns: ['/dist/'],
moduleNameMapper: {
'\\.(css|less)$': '<rootDir>/packages/react-styles/__mocks__/styleMock.js'
Expand Down
16 changes: 12 additions & 4 deletions packages/react-charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"types": "dist/esm/index.d.ts",
"typesVersions": {
"*": {
"echarts": [
"dist/esm/echarts/index.d.ts"
],
"victory": [
"dist/esm/victory/index.d.ts"
]
Expand Down Expand Up @@ -42,7 +45,13 @@
"lodash": "^4.17.21",
"tslib": "^2.8.1"
},
"devDependencies": {
"@types/lodash": "^4.17.16",
"fs-extra": "^11.3.0",
"jest-canvas-mock": "^2.5.2"
},
"peerDependencies": {
"echarts": "^5.6.0",
"react": "^17 || ^18",
"react-dom": "^17 || ^18",
"victory-area": "^37.3.6",
Expand All @@ -64,6 +73,9 @@
"victory-zoom-container": "^37.3.6"
},
"peerDependenciesMeta": {
"echarts": {
"optional": true
},
"victory-area": {
"optional": true
},
Expand Down Expand Up @@ -120,9 +132,5 @@
"clean": "rimraf dist echarts victory",
"build:single:packages": "node ../../scripts/build-single-packages.mjs --config single-packages.config.json",
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
},
"devDependencies": {
"@types/lodash": "^4.17.16",
"fs-extra": "^11.3.0"
}
}
2 changes: 1 addition & 1 deletion packages/react-charts/single-packages.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packageName": "@patternfly/react-charts",
"exclude": ["dist/esm/deprecated/index.js", "dist/esm/next/index.js"]
"exclude": ["dist/esm/deprecated/index.js"]
}
6 changes: 6 additions & 0 deletions packages/react-charts/src/echarts/__mocks__/echarts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const echarts: any = jest.createMockFromModule('echarts');
echarts.init = jest.fn(() => ({
setOption: jest.fn(),
dispose: jest.fn()
}));
module.exports = echarts;
22 changes: 22 additions & 0 deletions packages/react-charts/src/echarts/components/charts/Line/Line.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import defaultsDeep from 'lodash/defaultsDeep';

import { ThemeDefinition } from '../../themes/Theme';

/**
* Returns series properties for Line chart
*
* @param serie
* @param theme
* @param isSkeleton
* @private
*/
export const getLineSeries = (serie: any, theme: ThemeDefinition, isSkeleton: boolean) => {
const defaults = {
emphasis: {
...(isSkeleton ? { disabled: true } : { focus: 'adjacency' })
},
showSymbol: false,
type: 'line'
};
return defaultsDeep(serie, defaults);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react';

Check warning on line 1 in packages/react-charts/src/echarts/components/charts/Line/__tests__/Line.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

'default' import from 'react' is restricted. Please use named imports when importing from React

Check warning on line 1 in packages/react-charts/src/echarts/components/charts/Line/__tests__/Line.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

'default' import from 'react' is restricted. Please use named imports when importing from React
import { setupJestCanvasMock } from 'jest-canvas-mock';
import { render, screen } from '@testing-library/react';
import { PatternflyECharts } from '../../PatternflyECharts';

import * as echarts from 'echarts/core';
import { LineChart } from 'echarts/charts';
import { GridComponent, TitleComponent, TooltipComponent } from 'echarts/components';
import { SVGRenderer } from 'echarts/renderers';

// Register required components
echarts.use([GridComponent, LineChart, SVGRenderer, TitleComponent, TooltipComponent]);

beforeEach(() => {
jest.resetAllMocks();
jest.mock('echarts');
setupJestCanvasMock();
});

const props: any = {
height: 400,
id: 'line-chart',
option: {
xAxis: {
type: 'category',
data: ['2015', '2016', '2017', '2018']
},
yAxis: {
axisLabel: {
formatter: (value) => (value !== 0 ? `${value}` : '')
},
splitNumber: 3,
type: 'value'
},
series: [
{
data: [1, 2, 5, 3],
name: 'Cats',
type: 'line'
},
{
data: [2, 1, 7, 4],
name: 'Dogs',
lineStyle: {
type: 'dashed'
},
type: 'line'
},
{
data: [3, 4, 9, 5],
name: 'Birds',
type: 'line'
},
{
data: [3, 3, 8, 7],
name: 'Mice',
type: 'line'
}
],
title: {
text: 'This is a Line chart'
}
},
width: 800
};

// Remove dynamic _echarts_instance_ ID
const removeInstanceID = (fragment) => {
fragment.getElementById('line-chart').removeAttribute('_echarts_instance_');
return fragment;
};

test('renders component', () => {
const { asFragment } = render(<PatternflyECharts {...props} />);
expect(removeInstanceID(asFragment())).toMatchSnapshot();
});

test('renders title', async () => {
render(<PatternflyECharts {...props} />);

const title = await screen.findByText(props.option.title.text);
expect(title).toMatchSnapshot();
});

test('renders height and width', async () => {
const { asFragment } = render(<PatternflyECharts {...props} />);

const svg = asFragment().querySelector('svg');
expect(svg).toHaveAttribute('height', `${props.height}`);
expect(svg).toHaveAttribute('width', `${props.width}`);
});
Loading
Loading