Skip to content

Commit 589f787

Browse files
fix(Charts): Show Loading Placeholder (#64)
Added snapshot tests for placeholders
1 parent 1df8c11 commit 589f787

File tree

24 files changed

+1117
-544
lines changed

24 files changed

+1117
-544
lines changed

config/jestsetup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Enzyme from 'enzyme';
22
import Adapter from 'enzyme-adapter-react-16';
33
import { createSerializer } from 'enzyme-to-json';
44
import jssSerializer from '@shared/tests/serializer/jss-snapshot-serializer';
5+
import contentLoaderSerializer from '@shared/tests/serializer/content-loader-serializer.js';
56

67
process.env.NODE_ENV = 'test';
78
process.env.BABEL_ENV = 'test';
@@ -22,6 +23,7 @@ expect.addSnapshotSerializer(
2223
})
2324
);
2425
expect.addSnapshotSerializer(jssSerializer);
26+
expect.addSnapshotSerializer(contentLoaderSerializer);
2527

2628
export const setupMatchMedia = () => {
2729
// @ts-ignore

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { BarChart } from './index';
55

66
describe('BarChart', () => {
77
test('Renders with data', () => {
8-
renderThemedComponent(<BarChart labels={labels} datasets={singleDataset} />);
8+
mountThemedComponent(<BarChart labels={labels} datasets={singleDataset} />);
99
});
1010

1111
test('custom colors', () => {
12-
renderThemedComponent(<BarChart labels={labels} datasets={singleDataset} colors={['#f0ab00']} />);
12+
mountThemedComponent(<BarChart labels={labels} datasets={singleDataset} colors={['#f0ab00']} />);
1313
});
1414

1515
test('valueAxisFormatter', () => {
16-
renderThemedComponent(<BarChart labels={labels} datasets={singleDataset} valueAxisFormatter={(d) => `${d}%`} />);
16+
mountThemedComponent(<BarChart labels={labels} datasets={singleDataset} valueAxisFormatter={(d) => `${d}%`} />);
1717
});
1818

1919
test('with Ref', () => {
@@ -23,12 +23,17 @@ describe('BarChart', () => {
2323
});
2424

2525
test('stacked', () => {
26-
renderThemedComponent(
26+
mountThemedComponent(
2727
<BarChart
2828
labels={labels}
2929
datasets={datasets}
3030
options={{ scales: { yAxes: [{ stacked: true }], xAxes: [{ stacked: true }] } }}
3131
/>
3232
);
3333
});
34+
35+
test('loading placeholder', () => {
36+
const wrapper = mountThemedComponent(<BarChart labels={labels} datasets={[]} loading />);
37+
expect(wrapper.render()).toMatchSnapshot();
38+
});
3439
});

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import ContentLoader from 'react-content-loader';
33

4-
export const BarChartPlaceholder = (props) => {
4+
export const BarChartPlaceholder = () => {
55
return (
66
<ContentLoader
77
height={145}
@@ -10,7 +10,6 @@ export const BarChartPlaceholder = (props) => {
1010
primaryColor="#6a6d70"
1111
secondaryColor="#d9d9d9"
1212
primaryOpacity={0.3}
13-
{...props}
1413
>
1514
<rect x="20" y="10" width="1" height="135" />
1615
<rect x="20" y="20" width="85" height="15" />
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`BarChart loading placeholder 1`] = `
4+
<div
5+
class="-chart- -chart-0-"
6+
style="position: relative; padding-top: 6px; width: 300px; height: 300px;"
7+
>
8+
<svg
9+
aria-label="Loading interface..."
10+
preserveAspectRatio="none"
11+
role="img"
12+
viewBox="0 0 165 145"
13+
>
14+
<title>
15+
Loading interface...
16+
</title>
17+
<rect
18+
clip-path="CLIP-PATH-URL"
19+
height="145"
20+
style="fill: url(#STYLE-URL);"
21+
width="165"
22+
x="0"
23+
y="0"
24+
/>
25+
<defs>
26+
<clipPath
27+
id="CLIP-PATH-URL"
28+
>
29+
<rect
30+
height="135"
31+
width="1"
32+
x="20"
33+
y="10"
34+
/>
35+
<rect
36+
height="15"
37+
width="85"
38+
x="20"
39+
y="20"
40+
/>
41+
<rect
42+
height="15"
43+
width="117"
44+
x="20"
45+
y="40"
46+
/>
47+
<rect
48+
height="15"
49+
width="67"
50+
x="20"
51+
y="60"
52+
/>
53+
<rect
54+
height="15"
55+
width="75"
56+
x="20"
57+
y="80"
58+
/>
59+
<rect
60+
height="15"
61+
width="125"
62+
x="20"
63+
y="100"
64+
/>
65+
<rect
66+
height="15"
67+
width="60"
68+
x="20"
69+
y="120"
70+
/>
71+
</clipPath>
72+
<linearGradient
73+
id="STYLE-URL"
74+
>
75+
<stop
76+
offset="0%"
77+
stop-color="#6a6d70"
78+
stop-opacity="0.3"
79+
>
80+
<animate
81+
attributeName="offset"
82+
dur="2s"
83+
keyTimes="0; 0.25; 1"
84+
repeatCount="indefinite"
85+
values="-2; -2; 1"
86+
/>
87+
</stop>
88+
<stop
89+
offset="50%"
90+
stop-color="#d9d9d9"
91+
stop-opacity="1"
92+
>
93+
<animate
94+
attributeName="offset"
95+
dur="2s"
96+
keyTimes="0; 0.25; 1"
97+
repeatCount="indefinite"
98+
values="-1; -1; 2"
99+
/>
100+
</stop>
101+
<stop
102+
offset="100%"
103+
stop-color="#6a6d70"
104+
stop-opacity="0.3"
105+
>
106+
<animate
107+
attributeName="offset"
108+
dur="2s"
109+
keyTimes="0; 0.25; 1"
110+
repeatCount="indefinite"
111+
values="0; 0; 3"
112+
/>
113+
</stop>
114+
</linearGradient>
115+
</defs>
116+
</svg>
117+
</div>
118+
`;

packages/charts/src/components/BarChart/demo.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ storiesOf('Charts | BarChart', module)
5353
options={options}
5454
loading={boolean('loading')}
5555
/>
56-
));
56+
))
57+
.add('Loading Placeholder', () => <BarChart labels={labels} loading={boolean('loading', true)} />);

0 commit comments

Comments
 (0)