1+ import NodeMacOSBridge from '../../../src/platformBridges/NodeMacOSBridge' ;
2+
13/* eslint-disable global-require */
24let TextStyles ;
35let doc ;
@@ -7,7 +9,8 @@ beforeEach(() => {
79 jest . resetModules ( ) ;
810
911 jest . mock ( '../../../src/utils/getSketchVersion' , ( ) => ( {
10- getSketchVersion : jest . fn ( ( ) => 51 ) ,
12+ __esModule : true ,
13+ default : jest . fn ( ( ) => '51' ) ,
1114 } ) ) ;
1215
1316 TextStyles = require ( '../../../src/sharedStyles/TextStyles' ) ;
@@ -16,12 +19,7 @@ beforeEach(() => {
1619
1720 jest . mock ( '../../../src/utils/sharedTextStyles' ) ;
1821
19- jest . mock ( '../../../src/jsonUtils/sketchImpl/createStringMeasurer' ) ;
20- jest . mock ( '../../../src/jsonUtils/sketchImpl/findFontName' ) ;
21- jest . mock ( '../../../src/jsonUtils/sketchImpl/makeImageDataFromUrl' ) ;
22- jest . mock ( '../../../src/jsonUtils/sketchImpl/makeSvgLayer' ) ;
23-
24- TextStyles = TextStyles . default ;
22+ TextStyles = TextStyles . default ( ( ) => NodeMacOSBridge ) ;
2523 sharedTextStyles = sharedTextStyles . default ;
2624
2725 sharedTextStyles . setDocument = jest . fn ( doc => {
@@ -115,41 +113,32 @@ describe('create', () => {
115113 } ) ;
116114
117115 it ( 'only stores text attributes' , ( ) => {
118- const whitelist = [
119- 'color' ,
120- 'fontFamily' ,
121- 'fontSize' ,
122- 'fontStyle' ,
123- 'fontWeight' ,
124- 'textShadowOffset' ,
125- 'textShadowRadius' ,
126- 'textShadowColor' ,
127- 'textTransform' ,
128- 'letterSpacing' ,
129- 'lineHeight' ,
130- 'textAlign' ,
131- 'writingDirection' ,
132- ] ;
133-
134- const blacklist = [ 'foo' , 'bar' , 'baz' ] ;
135-
136- const input = [ ...whitelist , ...blacklist ] . reduce (
137- ( acc , key ) => ( {
138- ...acc ,
139- [ key ] : true ,
140- } ) ,
141- { } ,
142- ) ;
116+ const whitelist = {
117+ color : 'red' ,
118+ fontFamily : 'Helvetica' ,
119+ fontSize : 14 ,
120+ fontStyle : 'italic' ,
121+ fontWeight : 'bold' ,
122+ textShadowOffset : 2 ,
123+ textShadowRadius : 1 ,
124+ textShadowColor : 'black' ,
125+ textTransform : 'uppercase' ,
126+ letterSpacing : 1 ,
127+ lineHeight : 18 ,
128+ textAlign : 'left' ,
129+ writingDirection : 'ltr' ,
130+ } ;
143131
144- const res = TextStyles . create ( { foo : input } , { document : doc } ) ;
132+ const blacklist = { foo : 1 , bar : 2 , baz : 3 } ;
145133
134+ const res = TextStyles . create ( { foo : { ...whitelist , ...blacklist } } , { document : doc } ) ;
146135 const firstStoredStyle = res [ Object . keys ( res ) [ 0 ] ] . cssStyle ;
147136
148- whitelist . forEach ( key => {
149- expect ( firstStoredStyle ) . toHaveProperty ( key , true ) ;
137+ Object . keys ( whitelist ) . forEach ( key => {
138+ expect ( firstStoredStyle ) . toHaveProperty ( key , whitelist [ key ] ) ;
150139 } ) ;
151140
152- blacklist . forEach ( key => {
141+ Object . keys ( blacklist ) . forEach ( key => {
153142 expect ( firstStoredStyle ) . not . toHaveProperty ( key ) ;
154143 } ) ;
155144 } ) ;
0 commit comments