1
1
import {
2
2
combine ,
3
+ parseHexColor ,
3
4
parseStyles ,
4
5
parseValues ,
5
6
split ,
6
7
} from '../parse'
7
8
8
9
describe ( 'parse' , ( ) => {
9
10
describe ( 'combine' , ( ) => {
10
- test ( 'returns value for unknown properties ' , ( ) => {
11
+ test ( 'returns value for unknown props ' , ( ) => {
11
12
expect ( combine ( 'foo' , 'bar' ) ) . toEqual ( 'bar' )
12
13
} )
13
14
test ( 'returns value for non-array values' , ( ) => {
14
15
expect ( combine ( 'border' , 'bar' ) ) . toEqual ( 'bar' )
15
16
} )
16
17
test ( 'returns combined value for array values' , ( ) => {
17
- expect ( combine ( 'border' , [ '1px' , 'solid' , '#f00' ] ) ) . toEqual ( '1px solid #f00' )
18
+ expect ( combine ( 'border' , [ '1px' , 'solid' , '#f00' ] ) )
19
+ . toEqual ( '1px solid #f00' )
18
20
} )
19
21
} )
20
22
21
23
describe ( 'parseStyles' , ( ) => {
22
- test ( 'only parses properties that exist in both start and end styles' , ( ) => {
24
+ test ( 'only parses props that exist in both start and end styles' , ( ) => {
23
25
expect (
24
26
parseStyles ( { margin : '0 0 10px 10px' } , { padding : '10px 10px 0 0' } )
25
27
) . toEqual ( [ ] )
26
28
} )
27
- test ( 'only parses properties that have the same number of values' , ( ) => {
29
+ test ( 'only parses props that have the same number of values' , ( ) => {
28
30
expect (
29
31
parseStyles ( { margin : '0 0 10px 10px' } , { margin : '10px 0 0' } )
30
32
) . toEqual ( [ ] )
31
33
} )
32
- test ( 'only parses properties where every start/end combination can be parsed ' , ( ) => {
34
+ test ( 'fails parse on equal number of props but different type ' , ( ) => {
33
35
expect (
34
36
parseStyles ( { margin : '0 0 10px 10px' } , { margin : '10px foo 0 0' } )
35
37
) . toEqual ( [ ] )
36
38
} )
37
39
test ( 'returns parsed information object' , ( ) => {
38
40
expect (
39
- parseStyles ( { border : '0 solid #f00' , opacity : 0 } , { border : '10px solid #f00' , opacity : 1 } )
41
+ parseStyles (
42
+ { border : '0 solid #f00' , opacity : 0 } ,
43
+ { border : '10px solid #f00' , opacity : 1 }
44
+ )
40
45
) . toEqual ( [
41
46
{ prop : 'border' , start : 0 , end : 10 , unit : 'px' } ,
42
47
{ prop : 'border' , fixed : 'solid' } ,
@@ -50,27 +55,48 @@ describe('parse', () => {
50
55
test ( 'returns fixed when both values are equal' , ( ) => {
51
56
expect ( parseValues ( 'solid' , 'solid' ) ) . toEqual ( { fixed : 'solid' } )
52
57
} )
53
- test ( 'returns undefined when one of the values is not numeric' , ( ) => {
58
+ test ( 'returns rgb colors when both values are colors' , ( ) => {
59
+ expect ( parseValues ( '#f00' , '#00f' ) )
60
+ . toEqual ( { rgb : [ [ 255 , 0 , 0 ] , [ 0 , 0 , 255 ] ] } )
61
+ } )
62
+ test ( 'returns undefined otherwise' , ( ) => {
54
63
expect ( parseValues ( 'solid' , '1px' ) ) . toEqual ( undefined )
55
64
expect ( parseValues ( 0 , '#f00' ) ) . toEqual ( undefined )
56
65
} )
57
66
test ( 'returns start, end and unit otherwise' , ( ) => {
58
- expect ( parseValues ( '1px' , '10px' ) ) . toEqual ( { start : 1 , end : 10 , unit : 'px' } )
59
- expect ( parseValues ( 0 , 1 ) ) . toEqual ( { start : 0 , end : 1 , unit : '' } )
60
- expect ( parseValues ( 0 , '10rem' ) ) . toEqual ( { start : 0 , end : 10 , unit : 'rem' } )
61
- expect ( parseValues ( '0px' , 1 ) ) . toEqual ( { start : 0 , end : 1 , unit : 'px' } )
67
+ expect ( parseValues ( '1px' , '10px' ) )
68
+ . toEqual ( { start : 1 , end : 10 , unit : 'px' } )
69
+ expect ( parseValues ( 0 , 1 ) )
70
+ . toEqual ( { start : 0 , end : 1 , unit : '' } )
71
+ expect ( parseValues ( 0 , '10rem' ) )
72
+ . toEqual ( { start : 0 , end : 10 , unit : 'rem' } )
73
+ expect ( parseValues ( '0px' , 1 ) )
74
+ . toEqual ( { start : 0 , end : 1 , unit : 'px' } )
62
75
} )
63
76
} )
64
77
65
78
describe ( 'split' , ( ) => {
66
- test ( 'returns value for unknown properties ' , ( ) => {
79
+ test ( 'returns value for unknown props ' , ( ) => {
67
80
expect ( split ( 'foo' , 'bar' ) ) . toEqual ( 'bar' )
68
81
} )
69
82
test ( 'returns value for non-splittable values' , ( ) => {
70
83
expect ( split ( 'border' , 'bar' ) ) . toEqual ( 'bar' )
71
84
} )
72
85
test ( 'returns splitted value otherwise' , ( ) => {
73
- expect ( split ( 'border' , '1px solid #f00' ) ) . toEqual ( [ '1px' , 'solid' , '#f00' ] )
86
+ expect ( split ( 'border' , '1px solid #f00' ) )
87
+ . toEqual ( [ '1px' , 'solid' , '#f00' ] )
88
+ } )
89
+ } )
90
+
91
+ describe ( 'parseHexColor' , ( ) => {
92
+ test ( 'parses hex color shorthand' , ( ) => {
93
+ expect ( parseHexColor ( '#f00' ) ) . toEqual ( [ 255 , 0 , 0 ] )
94
+ } )
95
+ test ( 'parses hex color' , ( ) => {
96
+ expect ( parseHexColor ( '#00ff00' ) ) . toEqual ( [ 0 , 255 , 0 ] )
97
+ } )
98
+ test ( 'doesnt parse when not a hex color' , ( ) => {
99
+ expect ( parseHexColor ( 'wat' ) ) . toEqual ( undefined )
74
100
} )
75
101
} )
76
102
} )
0 commit comments