11import {
22 combine ,
3+ parseHexColor ,
34 parseStyles ,
45 parseValues ,
56 split ,
67} from '../parse'
78
89describe ( 'parse' , ( ) => {
910 describe ( 'combine' , ( ) => {
10- test ( 'returns value for unknown properties ' , ( ) => {
11+ test ( 'returns value for unknown props ' , ( ) => {
1112 expect ( combine ( 'foo' , 'bar' ) ) . toEqual ( 'bar' )
1213 } )
1314 test ( 'returns value for non-array values' , ( ) => {
1415 expect ( combine ( 'border' , 'bar' ) ) . toEqual ( 'bar' )
1516 } )
1617 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' )
1820 } )
1921 } )
2022
2123 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' , ( ) => {
2325 expect (
2426 parseStyles ( { margin : '0 0 10px 10px' } , { padding : '10px 10px 0 0' } )
2527 ) . toEqual ( [ ] )
2628 } )
27- test ( 'only parses properties that have the same number of values' , ( ) => {
29+ test ( 'only parses props that have the same number of values' , ( ) => {
2830 expect (
2931 parseStyles ( { margin : '0 0 10px 10px' } , { margin : '10px 0 0' } )
3032 ) . toEqual ( [ ] )
3133 } )
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 ' , ( ) => {
3335 expect (
3436 parseStyles ( { margin : '0 0 10px 10px' } , { margin : '10px foo 0 0' } )
3537 ) . toEqual ( [ ] )
3638 } )
3739 test ( 'returns parsed information object' , ( ) => {
3840 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+ )
4045 ) . toEqual ( [
4146 { prop : 'border' , start : 0 , end : 10 , unit : 'px' } ,
4247 { prop : 'border' , fixed : 'solid' } ,
@@ -50,27 +55,48 @@ describe('parse', () => {
5055 test ( 'returns fixed when both values are equal' , ( ) => {
5156 expect ( parseValues ( 'solid' , 'solid' ) ) . toEqual ( { fixed : 'solid' } )
5257 } )
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' , ( ) => {
5463 expect ( parseValues ( 'solid' , '1px' ) ) . toEqual ( undefined )
5564 expect ( parseValues ( 0 , '#f00' ) ) . toEqual ( undefined )
5665 } )
5766 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' } )
6275 } )
6376 } )
6477
6578 describe ( 'split' , ( ) => {
66- test ( 'returns value for unknown properties ' , ( ) => {
79+ test ( 'returns value for unknown props ' , ( ) => {
6780 expect ( split ( 'foo' , 'bar' ) ) . toEqual ( 'bar' )
6881 } )
6982 test ( 'returns value for non-splittable values' , ( ) => {
7083 expect ( split ( 'border' , 'bar' ) ) . toEqual ( 'bar' )
7184 } )
7285 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 )
74100 } )
75101 } )
76102} )
0 commit comments