1
- /* eslint no-unused-expressions: 0 */
2
1
import { Helpers } from "victory-core" ;
3
2
4
3
describe ( "victory-util/helpers" , ( ) => {
5
4
describe ( "omit" , ( ) => {
6
5
const data = { x : 3 , y : 2 , z : 1 } ;
6
+
7
7
it ( "removes omitted keys and preserves all others" , ( ) => {
8
8
const newData = Helpers . omit ( data , [ "x" ] ) ;
9
9
expect ( newData . x ) . toBeUndefined ( ) ;
10
10
expect ( newData . y ) . toEqual ( 2 ) ;
11
11
expect ( newData . z ) . toEqual ( 1 ) ;
12
12
} ) ;
13
+
13
14
it ( "creates a copy of the original object" , ( ) => {
14
15
const newData = Helpers . omit ( data , [ ] ) ;
15
16
newData . x = 10 ;
16
17
expect ( data . x ) . toEqual ( 3 ) ;
17
18
expect ( newData . x ) . toEqual ( 10 ) ;
18
19
} ) ;
20
+
19
21
it ( "defaults to an empty object" , ( ) => {
20
22
const newData = Helpers . omit ( ) ;
21
23
expect ( newData ) . toEqual ( { } ) ;
22
24
} ) ;
25
+
23
26
it ( "defaults to simple shallow copy" , ( ) => {
24
27
const newData = Helpers . omit ( data ) ;
25
28
expect ( newData ) . toEqual ( data ) ;
@@ -30,6 +33,7 @@ describe("victory-util/helpers", () => {
30
33
it ( "defaults to an empty object" , ( ) => {
31
34
expect ( Helpers . modifyProps ( { } ) ) . toEqual ( { } ) ;
32
35
} ) ;
36
+
33
37
it ( "removes the theme role's style" , ( ) => {
34
38
const role = "legend" ;
35
39
const props = {
@@ -51,6 +55,7 @@ describe("victory-util/helpers", () => {
51
55
modifiedProps
52
56
) ;
53
57
} ) ;
58
+
54
59
it ( "uses fallbackProps" , ( ) => {
55
60
const props = { x : 2 , y : 3 } ;
56
61
const fallbackProps = { x : 12 , y : 13 , z : 14 } ;
@@ -61,10 +66,12 @@ describe("victory-util/helpers", () => {
61
66
62
67
describe ( "evaluateProp" , ( ) => {
63
68
const data = { x : 3 , y : 2 } ;
69
+
64
70
it ( "evaluates functional props" , ( ) => {
65
71
const testProp = ( datum ) => ( datum . y > 0 ? "red" : "blue" ) ;
66
72
expect ( Helpers . evaluateProp ( testProp , data ) ) . toEqual ( "red" ) ;
67
73
} ) ;
74
+
68
75
it ( "doesn't alter non-functional props" , ( ) => {
69
76
const testProp = "blue" ;
70
77
expect ( Helpers . evaluateProp ( testProp , data ) ) . toEqual ( "blue" ) ;
@@ -73,6 +80,7 @@ describe("victory-util/helpers", () => {
73
80
74
81
describe ( "evaluateStyle" , ( ) => {
75
82
const data = { x : 3 , y : 2 } ;
83
+
76
84
it ( "evaluates functional styles, without altering others" , ( ) => {
77
85
const style = {
78
86
color : ( datum ) => ( datum . y > 0 ? "red" : "blue" ) ,
@@ -83,6 +91,7 @@ describe("victory-util/helpers", () => {
83
91
size : 5
84
92
} ) ;
85
93
} ) ;
94
+
86
95
it ( "returns no styles if disableInlineStyles is true" , ( ) => {
87
96
const style = {
88
97
color : "blue"
@@ -100,6 +109,7 @@ describe("victory-util/helpers", () => {
100
109
height : 200 ,
101
110
padding : 0
102
111
} ;
112
+
103
113
it ( "returns a range based on props and axis" , ( ) => {
104
114
const x = Helpers . getRange ( props , "x" ) ;
105
115
expect ( Array . isArray ( x ) ) . toBe ( true ) ;
@@ -119,6 +129,7 @@ describe("victory-util/helpers", () => {
119
129
data : { fill : "blue" , stroke : "black" } ,
120
130
labels : { fontSize : 10 , fontFamily : "Helvetica" }
121
131
} ;
132
+
122
133
it ( "merges styles" , ( ) => {
123
134
const style = { data : { fill : "red" } , labels : { fontSize : 12 } } ;
124
135
const styles = Helpers . getStyles ( style , defaultStyles ) ;
@@ -145,12 +156,14 @@ describe("victory-util/helpers", () => {
145
156
right : 40
146
157
} ) ;
147
158
} ) ;
159
+
148
160
it ( "sets padding from a complete object" , ( ) => {
149
161
const props = {
150
162
padding : { top : 20 , bottom : 40 , left : 60 , right : 80 }
151
163
} ;
152
164
expect ( Helpers . getPadding ( props ) ) . toEqual ( props . padding ) ;
153
165
} ) ;
166
+
154
167
it ( "fills missing values with 0" , ( ) => {
155
168
const props = {
156
169
padding : { top : 40 , bottom : 40 }
0 commit comments