@oanda/labs-widget-common 1.0.196 → 1.0.198
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1556 -0
- package/dist/main/chart/BaseChart.js +35 -0
- package/dist/main/chart/BaseChart.js.map +1 -0
- package/dist/main/chart/index.js +22 -0
- package/dist/main/chart/index.js.map +1 -1
- package/dist/main/chart/types.js +6 -0
- package/dist/main/chart/types.js.map +1 -0
- package/dist/main/components/Error/Error.js +5 -2
- package/dist/main/components/Error/Error.js.map +1 -1
- package/dist/main/components/Table/Table.js +5 -2
- package/dist/main/components/Table/Table.js.map +1 -1
- package/dist/main/translations/sources/en.json +1 -0
- package/dist/module/chart/BaseChart.js +26 -0
- package/dist/module/chart/BaseChart.js.map +1 -0
- package/dist/module/chart/index.js +2 -0
- package/dist/module/chart/index.js.map +1 -1
- package/dist/module/chart/types.js +2 -0
- package/dist/module/chart/types.js.map +1 -0
- package/dist/module/components/Error/Error.js +5 -2
- package/dist/module/components/Error/Error.js.map +1 -1
- package/dist/module/components/Table/Table.js +5 -2
- package/dist/module/components/Table/Table.js.map +1 -1
- package/dist/module/translations/sources/en.json +1 -0
- package/dist/types/chart/BaseChart.d.ts +7 -0
- package/dist/types/chart/index.d.ts +2 -0
- package/dist/types/chart/types.d.ts +2 -0
- package/dist/types/components/Error/Error.d.ts +3 -1
- package/package.json +2 -2
- package/src/chart/BaseChart.tsx +37 -0
- package/src/chart/index.ts +2 -0
- package/src/chart/types.ts +3 -0
- package/src/components/Error/Error.tsx +8 -2
- package/src/components/Table/Table.tsx +6 -2
- package/src/translations/sources/en.json +1 -0
- package/test/chart/BaseChart.test.tsx +121 -0
- package/test/setup.ts +16 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
2
|
+
import { act, render, screen } from '@testing-library/react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import { BaseChart } from '../../src/chart/BaseChart';
|
|
6
|
+
import type { BaseChartRef } from '../../src/chart/types';
|
|
7
|
+
|
|
8
|
+
jest.mock('echarts-for-react/lib/core', () => {
|
|
9
|
+
const ReactMock = require('react');
|
|
10
|
+
const MockEChartsCore = ReactMock.forwardRef(
|
|
11
|
+
(props: any, ref: React.Ref<any>) => (
|
|
12
|
+
<div
|
|
13
|
+
ref={ref as any}
|
|
14
|
+
data-loading={props.showLoading}
|
|
15
|
+
data-testid="charts-container"
|
|
16
|
+
data-theme={props.theme}
|
|
17
|
+
style={props.style}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
MockEChartsCore.displayName = 'MockEChartsCore';
|
|
22
|
+
return MockEChartsCore;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('BaseChart component', () => {
|
|
26
|
+
const defaultProps = {
|
|
27
|
+
isDark: false,
|
|
28
|
+
chartHeight: 400,
|
|
29
|
+
option: {
|
|
30
|
+
xAxis: {
|
|
31
|
+
type: 'category',
|
|
32
|
+
data: ['Mon', 'Tue', 'Wed'],
|
|
33
|
+
},
|
|
34
|
+
yAxis: {
|
|
35
|
+
type: 'value',
|
|
36
|
+
},
|
|
37
|
+
series: [
|
|
38
|
+
{
|
|
39
|
+
data: [120, 200, 150],
|
|
40
|
+
type: 'line',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let resolveFontsReady: (value?: unknown) => void;
|
|
47
|
+
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
Object.defineProperty(document, 'fonts', {
|
|
50
|
+
value: {
|
|
51
|
+
ready: new Promise((resolve) => {
|
|
52
|
+
resolveFontsReady = resolve;
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
writable: true,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should show loading state initially', () => {
|
|
60
|
+
render(<BaseChart {...defaultProps} />);
|
|
61
|
+
const chart = screen.getByTestId('charts-container');
|
|
62
|
+
expect(chart).toHaveAttribute('data-loading', 'true');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should render chart after fonts are ready', async () => {
|
|
66
|
+
render(<BaseChart {...defaultProps} />);
|
|
67
|
+
|
|
68
|
+
const chart = screen.getByTestId('charts-container');
|
|
69
|
+
expect(chart).toHaveAttribute('data-loading', 'true');
|
|
70
|
+
|
|
71
|
+
await act(async () => {
|
|
72
|
+
resolveFontsReady();
|
|
73
|
+
await document.fonts.ready;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(chart).toHaveAttribute('data-loading', 'false');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should apply dark theme when isDark is true', async () => {
|
|
80
|
+
render(<BaseChart {...defaultProps} isDark={true} />);
|
|
81
|
+
|
|
82
|
+
await act(async () => {
|
|
83
|
+
resolveFontsReady();
|
|
84
|
+
await document.fonts.ready;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const chart = screen.getByTestId('charts-container');
|
|
88
|
+
expect(chart).toHaveAttribute('data-theme', 'dark_theme');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should apply light theme when isDark is false', async () => {
|
|
92
|
+
render(<BaseChart {...defaultProps} isDark={false} />);
|
|
93
|
+
|
|
94
|
+
await act(async () => {
|
|
95
|
+
resolveFontsReady();
|
|
96
|
+
await document.fonts.ready;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const chart = screen.getByTestId('charts-container');
|
|
100
|
+
expect(chart).toHaveAttribute('data-theme', 'light_theme');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should set correct chart height', async () => {
|
|
104
|
+
const height = 500;
|
|
105
|
+
render(<BaseChart {...defaultProps} chartHeight={height} />);
|
|
106
|
+
|
|
107
|
+
await act(async () => {
|
|
108
|
+
resolveFontsReady();
|
|
109
|
+
await document.fonts.ready;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const chart = screen.getByTestId('charts-container');
|
|
113
|
+
expect(chart).toHaveStyle({ height: `${height}px` });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should forward ref to BaseChartRef', () => {
|
|
117
|
+
const ref = React.createRef<BaseChartRef>();
|
|
118
|
+
render(<BaseChart {...defaultProps} ref={ref} />);
|
|
119
|
+
expect(ref.current).toBeTruthy();
|
|
120
|
+
});
|
|
121
|
+
});
|
package/test/setup.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Mock document.fonts.ready
|
|
2
|
+
if (!document.fonts) {
|
|
3
|
+
Object.defineProperty(document, 'fonts', {
|
|
4
|
+
value: {
|
|
5
|
+
ready: Promise.resolve(),
|
|
6
|
+
check: () => true,
|
|
7
|
+
load: () => Promise.resolve([]),
|
|
8
|
+
},
|
|
9
|
+
configurable: true,
|
|
10
|
+
});
|
|
11
|
+
} else if (!('ready' in document.fonts)) {
|
|
12
|
+
Object.defineProperty(document.fonts, 'ready', {
|
|
13
|
+
value: Promise.resolve(),
|
|
14
|
+
configurable: true,
|
|
15
|
+
});
|
|
16
|
+
}
|