File tree 2 files changed +62
-1
lines changed 2 files changed +62
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { getMockToken } from '../test-utilities'
2
+ import { floatToPixel } from './floatToPixel'
3
+
4
+ describe ( 'Transformer: floatToPixel' , ( ) => {
5
+ it ( 'transforms float to pixel' , ( ) => {
6
+ const input = [
7
+ getMockToken ( {
8
+ value : 1.5 ,
9
+ $extensions : {
10
+ 'org.primer.data' : {
11
+ fontSize : 16 ,
12
+ } ,
13
+ } ,
14
+ } ) ,
15
+ ]
16
+ const expectedOutput = [ '24px' ]
17
+ expect ( input . map ( item => floatToPixel . transformer ( item , { } ) ) ) . toStrictEqual ( expectedOutput )
18
+ } )
19
+
20
+ it ( 'transforms 0 to 0' , ( ) => {
21
+ const input = [
22
+ getMockToken ( {
23
+ value : 0 ,
24
+ $extensions : {
25
+ 'org.primer.data' : {
26
+ fontSize : 16 ,
27
+ } ,
28
+ } ,
29
+ } ) ,
30
+ getMockToken ( {
31
+ value : 0 ,
32
+ } ) ,
33
+ ]
34
+ const expectedOutput = [ 0 , 0 ]
35
+ expect ( input . map ( item => floatToPixel . transformer ( item , { } ) ) ) . toStrictEqual ( expectedOutput )
36
+ } )
37
+
38
+ it ( 'ignore invalid' , ( ) => {
39
+ const input = [
40
+ getMockToken ( {
41
+ value : '1.5' ,
42
+ $extensions : {
43
+ 'org.primer.data' : {
44
+ fontSize : 16 ,
45
+ } ,
46
+ } ,
47
+ } ) ,
48
+ getMockToken ( {
49
+ value : 1.5 ,
50
+ } ) ,
51
+ getMockToken ( {
52
+ value : 2 ,
53
+ $extensions : {
54
+ 'org.primer.data' : { } ,
55
+ } ,
56
+ } ) ,
57
+ ]
58
+ const expectedOutput = [ '1.5' , 1.5 , 2 ]
59
+ expect ( input . map ( item => floatToPixel . transformer ( item , { } ) ) ) . toStrictEqual ( expectedOutput )
60
+ } )
61
+ } )
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export const convertFloatToPixel = (token: StyleDictionary.TransformedToken) =>
17
17
// convert value
18
18
const convertedValue = token . $extensions ?. [ 'org.primer.data' ] ?. fontSize * token . value
19
19
// return converted value
20
- return `${ convertedValue } px`
20
+ return convertedValue === 0 ? 0 : `${ convertedValue } px`
21
21
}
22
22
/**
23
23
* @description converts a float value to a pixel value based on the provided fontSize on the tokersn extension
You can’t perform that action at this time.
0 commit comments