@@ -2,6 +2,7 @@ import React from 'react';
2
2
import { expect } from 'chai' ;
3
3
import { Surface , ScatterChart , Scatter , LineChart , Line , XAxis , YAxis , CartesianAxis } from 'recharts' ;
4
4
import { mount , render } from 'enzyme' ;
5
+ import { Bar , BarChart } from '../../../src' ;
5
6
6
7
describe ( '<XAxis />' , ( ) => {
7
8
const data = [
@@ -21,35 +22,34 @@ describe('<XAxis />', () => {
21
22
{ name : 'Page F' , uv : 189 , pv : 4800 , amt : 2400 } ,
22
23
] ;
23
24
24
-
25
25
it ( 'Render 1 x-CartesianAxis and 1 y-CartesianAxis ticks in ScatterChart' , ( ) => {
26
26
const wrapper = mount (
27
27
< ScatterChart width = { 400 } height = { 400 } margin = { { top : 20 , right : 20 , bottom : 20 , left : 20 } } >
28
- < XAxis dataKey = { 'x' } name = "stature" unit = "cm" />
29
- < YAxis dataKey = { 'y' } name = "weight" unit = "kg" />
28
+ < XAxis dataKey = "x" name = "stature" unit = "cm" />
29
+ < YAxis dataKey = "y" name = "weight" unit = "kg" />
30
30
< Scatter name = "A school" data = { data } fill = "#ff7300" />
31
- </ ScatterChart >
31
+ </ ScatterChart > ,
32
32
) ;
33
33
expect ( wrapper . find ( CartesianAxis ) . length ) . to . equal ( 2 ) ;
34
34
} ) ;
35
35
36
- it ( ' Don\ 't render anything' , ( ) => {
36
+ it ( " Don't render anything" , ( ) => {
37
37
const wrapper = render (
38
38
< Surface width = { 500 } height = { 500 } >
39
- < XAxis dataKey = { 'x' } name = "stature" unit = "cm" />
40
- </ Surface >
39
+ < XAxis dataKey = "x" name = "stature" unit = "cm" />
40
+ </ Surface > ,
41
41
) ;
42
42
43
43
expect ( wrapper . find ( 'svg' ) . children . length ) . to . equal ( 1 ) ;
44
44
expect ( wrapper . find ( 'svg noscript' ) . children . length ) . to . equal ( 1 ) ;
45
45
} ) ;
46
46
47
- it ( ' Don\ 't render x-axis when hide is setted to be true' , ( ) => {
47
+ it ( " Don't render x-axis when hide is setted to be true" , ( ) => {
48
48
const wrapper = render (
49
49
< LineChart width = { 400 } height = { 400 } data = { lineData } margin = { { top : 20 , right : 20 , bottom : 20 , left : 20 } } >
50
50
< XAxis hide />
51
51
< Line type = "monotone" dataKey = "uv" stroke = "#ff7300" />
52
- </ LineChart >
52
+ </ LineChart > ,
53
53
) ;
54
54
expect ( wrapper . find ( '.recharts-x-axis' ) . length ) . to . equal ( 0 ) ;
55
55
} ) ;
@@ -59,7 +59,7 @@ describe('<XAxis />', () => {
59
59
< LineChart width = { 400 } height = { 400 } data = { lineData } margin = { { top : 20 , right : 20 , bottom : 20 , left : 20 } } >
60
60
< XAxis ticks = { [ 0 , 4 ] } />
61
61
< Line type = "monotone" dataKey = "uv" stroke = "#ff7300" />
62
- </ LineChart >
62
+ </ LineChart > ,
63
63
) ;
64
64
expect ( wrapper . find ( '.xAxis .recharts-cartesian-axis-tick' ) . length ) . to . equal ( 2 ) ;
65
65
} ) ;
@@ -69,107 +69,98 @@ describe('<XAxis />', () => {
69
69
< LineChart width = { 400 } height = { 400 } data = { lineData } margin = { { top : 20 , right : 20 , bottom : 20 , left : 20 } } >
70
70
< XAxis dataKey = "name" tickFormatter = { ( value , i ) => `${ i } ` } />
71
71
< Line type = "monotone" dataKey = "uv" stroke = "#ff7300" />
72
- </ LineChart >
72
+ </ LineChart > ,
73
73
) ;
74
74
expect ( wrapper . find ( '.xAxis .recharts-cartesian-axis-tick' ) . first ( ) ) . text ( ) . to . equal ( '0' ) ;
75
75
} ) ;
76
76
77
77
it ( 'Render duplicated ticks of XAxis' , ( ) => {
78
78
const lineData = [
79
- { name : " 03/07/2017" , balance : 23126.11 } ,
80
- { name : " 03/02/2017" , balance : 23137.39 } ,
81
- { name : " 03/01/2017" , balance : 24609.55 } ,
82
- { name : " 03/01/2017" , balance : 26827.66 } ,
83
- { name : " 02/24/2017" , balance : 26807.66 } ,
84
- { name : " 02/21/2017" , balance : 23835.62 } ,
85
- { name : " 02/16/2017" , balance : 23829.62 }
79
+ { name : ' 03/07/2017' , balance : 23126.11 } ,
80
+ { name : ' 03/02/2017' , balance : 23137.39 } ,
81
+ { name : ' 03/01/2017' , balance : 24609.55 } ,
82
+ { name : ' 03/01/2017' , balance : 26827.66 } ,
83
+ { name : ' 02/24/2017' , balance : 26807.66 } ,
84
+ { name : ' 02/21/2017' , balance : 23835.62 } ,
85
+ { name : ' 02/16/2017' , balance : 23829.62 } ,
86
86
] ;
87
87
88
88
const wrapper = render (
89
- < LineChart
90
- width = { 600 }
91
- height = { 300 }
92
- data = { lineData }
93
- margin = { { top : 5 , right : 30 , left : 20 , bottom : 5 } }
94
- >
89
+ < LineChart width = { 600 } height = { 300 } data = { lineData } margin = { { top : 5 , right : 30 , left : 20 , bottom : 5 } } >
95
90
< XAxis dataKey = "name" interval = { 0 } />
96
91
< YAxis />
97
92
< Line type = "monotone" dataKey = "balance" stroke = "#8884d8" activeDot = { { r : 8 } } />
98
- </ LineChart >
93
+ </ LineChart > ,
99
94
) ;
100
95
expect ( wrapper . find ( '.recharts-xAxis .recharts-cartesian-axis-tick' ) . length ) . to . equal ( lineData . length ) ;
101
96
} ) ;
102
97
103
98
it ( 'Render ticks of when the scale of XAxis is time' , ( ) => {
104
99
const timeData = [
105
100
{
106
- x : new Date ( " 2019-07-04T00:00:00.000Z" ) ,
107
- y : 5
101
+ x : new Date ( ' 2019-07-04T00:00:00.000Z' ) ,
102
+ y : 5 ,
108
103
} ,
109
104
{
110
- x : new Date ( " 2019-07-05T00:00:00.000Z" ) ,
111
- y : 30
105
+ x : new Date ( ' 2019-07-05T00:00:00.000Z' ) ,
106
+ y : 30 ,
112
107
} ,
113
108
{
114
- x : new Date ( " 2019-07-06T00:00:00.000Z" ) ,
115
- y : 50
109
+ x : new Date ( ' 2019-07-06T00:00:00.000Z' ) ,
110
+ y : 50 ,
116
111
} ,
117
112
{
118
- x : new Date ( " 2019-07-07T00:00:00.000Z" ) ,
119
- y : 43
113
+ x : new Date ( ' 2019-07-07T00:00:00.000Z' ) ,
114
+ y : 43 ,
120
115
} ,
121
116
{
122
- x : new Date ( " 2019-07-08T00:00:00.000Z" ) ,
123
- y : 20
117
+ x : new Date ( ' 2019-07-08T00:00:00.000Z' ) ,
118
+ y : 20 ,
124
119
} ,
125
120
{
126
- x : new Date ( " 2019-07-09T00:00:00.000Z" ) ,
127
- y : - 20
121
+ x : new Date ( ' 2019-07-09T00:00:00.000Z' ) ,
122
+ y : - 20 ,
128
123
} ,
129
124
{
130
- x : new Date ( " 2019-07-10T00:00:00.000Z" ) ,
131
- y : 30
132
- }
125
+ x : new Date ( ' 2019-07-10T00:00:00.000Z' ) ,
126
+ y : 30 ,
127
+ } ,
133
128
] ;
134
129
135
130
const wrapper = render (
136
- < LineChart
137
- width = { 600 }
138
- height = { 300 }
139
- data = { timeData }
140
- margin = { { top : 5 , right : 30 , left : 20 , bottom : 5 } }
141
- >
142
- < XAxis dataKey = "x" domain = { [ timeData [ 0 ] . x . getTime ( ) , timeData [ timeData . length - 1 ] . x . getTime ( ) ] } scale = "time" type = "number" />
131
+ < LineChart width = { 600 } height = { 300 } data = { timeData } margin = { { top : 5 , right : 30 , left : 20 , bottom : 5 } } >
132
+ < XAxis
133
+ dataKey = "x"
134
+ domain = { [ timeData [ 0 ] . x . getTime ( ) , timeData [ timeData . length - 1 ] . x . getTime ( ) ] }
135
+ scale = "time"
136
+ type = "number"
137
+ />
143
138
< YAxis />
144
139
< Line type = "monotone" dataKey = "y" stroke = "#8884d8" activeDot = { { r : 8 } } />
145
- </ LineChart >
140
+ </ LineChart > ,
146
141
) ;
147
142
expect ( wrapper . find ( '.recharts-xAxis .recharts-cartesian-axis-tick' ) . length ) . to . equal ( 1 ) ;
148
143
} ) ;
149
144
150
- it ( 'Render duplicated ticks of XAxis ' , ( ) => {
151
- const lineData = [
152
- { name : "03/07/2017" , balance : 23126.11 } ,
153
- { name : "03/02/2017" , balance : 23137.39 } ,
154
- { name : "03/01/2017" , balance : 24609.55 } ,
155
- { name : "03/01/2017" , balance : 26827.66 } ,
156
- { name : "02/24/2017" , balance : 26807.66 } ,
157
- { name : "02/21/2017" , balance : 23835.62 } ,
158
- { name : "02/16/2017" , balance : 23829.62 }
159
- ] ;
145
+ it ( 'Render Bars with gap ' , ( ) => {
146
+ const wrapper = mount (
147
+ < BarChart width = { 300 } height = { 300 } data = { data } >
148
+ < Bar dataKey = "y" />
149
+ < XAxis dataKey = "x" type = "number" domain = { [ 'dataMin' , 'dataMax' ] } padding = "gap" />
150
+ < YAxis dataKey = "y" />
151
+ </ BarChart > ,
152
+ ) ;
153
+ expect ( parseInt ( wrapper . find ( Bar ) . prop ( 'data' ) [ 0 ] . x , 10 ) ) . to . equal ( 70 ) ;
154
+ } ) ;
160
155
161
- const wrapper = render (
162
- < LineChart
163
- width = { 600 }
164
- height = { 300 }
165
- data = { lineData }
166
- margin = { { top : 5 , right : 30 , left : 20 , bottom : 5 } }
167
- >
168
- < XAxis dataKey = "name" scale = "time" interval = { 0 } />
169
- < YAxis />
170
- < Line type = "monotone" dataKey = "balance" stroke = "#8884d8" activeDot = { { r : 8 } } />
171
- </ LineChart >
156
+ it ( 'Render Bars with no gap' , ( ) => {
157
+ const wrapper = mount (
158
+ < BarChart width = { 300 } height = { 300 } data = { data } >
159
+ < Bar dataKey = "y" />
160
+ < XAxis dataKey = "x" type = "number" domain = { [ 'dataMin' , 'dataMax' ] } padding = "no-gap" />
161
+ < YAxis dataKey = "y" />
162
+ </ BarChart > ,
172
163
) ;
173
- expect ( wrapper . find ( '.recharts-xAxis .recharts-cartesian-axis-tick' ) . length ) . to . equal ( lineData . length ) ;
164
+ expect ( parseInt ( wrapper . find ( Bar ) . prop ( 'data' ) [ 0 ] . x , 10 ) ) . to . equal ( 66 ) ;
174
165
} ) ;
175
166
} ) ;
0 commit comments