@@ -297,4 +297,195 @@ describe('updateVariables', () => {
297297 // Verify that 2rem was converted to 30px (2 * 15)
298298 expect ( mockSetValueForMode ) . toHaveBeenCalledWith ( '1:1' , 30 ) ;
299299 } ) ;
300+
301+ it ( 'should handle numeric baseFontSize results from getAliasValue (math evaluated)' , async ( ) => {
302+ mockSetValueForMode . mockClear ( ) ;
303+
304+ const baselineVariable = {
305+ name : 'typography/baseline' ,
306+ variableCollectionId : 'VariableCollectionId:1:0' ,
307+ resolvedType : 'FLOAT' ,
308+ setValueForMode : mockSetValueForMode ,
309+ id : 'VariableID:1:3' ,
310+ key : 'VariableID:1:3' ,
311+ description : '' ,
312+ valuesByMode : { '1:0' : 16 } ,
313+ remote : false ,
314+ remove : jest . fn ( ) ,
315+ } ;
316+
317+ const newVarForTest = {
318+ name : 'sizing/test' ,
319+ variableCollectionId : 'VariableCollectionId:1:0' ,
320+ resolvedType : 'FLOAT' ,
321+ setValueForMode : mockSetValueForMode ,
322+ id : 'VariableID:1:new' ,
323+ key : 'VariableID:1:new' ,
324+ description : '' ,
325+ valuesByMode : { '1:0' : 0 } ,
326+ remote : false ,
327+ remove : jest . fn ( ) ,
328+ } ;
329+
330+ figma . variables . createVariable = jest . fn ( ) . mockImplementation ( ( name ) => {
331+ if ( name === 'typography/baseline' ) return baselineVariable ;
332+ if ( name === 'sizing/test' ) return newVarForTest ;
333+ return newVariable ;
334+ } ) ;
335+
336+ figma . variables . getLocalVariables = jest . fn ( ) . mockReturnValue ( [ ] ) ;
337+
338+ const theme = {
339+ id : 'ThemeId:test' ,
340+ name : 'Test' ,
341+ group : 'Test group' ,
342+ selectedTokenSets : { core : TokenSetStatus . ENABLED } ,
343+ } ;
344+
345+ const tokens = {
346+ core : [
347+ {
348+ name : 'typography.baseline' ,
349+ value : '16' ,
350+ type : TokenTypes . FONT_SIZES ,
351+ } ,
352+ {
353+ name : 'sizing.test' ,
354+ value : '1.5rem' ,
355+ type : TokenTypes . SIZING ,
356+ } ,
357+ ] ,
358+ } ;
359+
360+ const settingsWithAlias = {
361+ ...settings ,
362+ aliasBaseFontSize : '{typography.baseline}' ,
363+ } ;
364+
365+ await updateVariables ( {
366+ collection : { id : 'VariableCollectionId:1:0' } as any ,
367+ mode : '1:0' ,
368+ theme,
369+ tokens,
370+ settings : settingsWithAlias ,
371+ overallConfig : { core : TokenSetStatus . ENABLED } ,
372+ } ) ;
373+
374+ // 1.5rem * 16 = 24
375+ expect ( mockSetValueForMode ) . toHaveBeenCalledWith ( '1:0' , 24 ) ;
376+ } ) ;
377+
378+ it ( 'should apply different baseFontSize for different modes in the same collection' , async ( ) => {
379+ mockSetValueForMode . mockClear ( ) ;
380+ const mockSpacingSetValueForMode = jest . fn ( ) ;
381+ const mockBaseFontSizeSetValueForMode = jest . fn ( ) ;
382+
383+ const collection : any = {
384+ id : 'collection1' ,
385+ modes : [
386+ { modeId : 'mode-a' , name : 'Mode A' } ,
387+ { modeId : 'mode-b' , name : 'Mode B' } ,
388+ ] ,
389+ } ;
390+
391+ const tokens : any = {
392+ core : [
393+ { name : 'base.font-size' , value : '16' , type : TokenTypes . NUMBER } ,
394+ { name : 'spacing.small' , value : '1rem' , type : TokenTypes . SPACING } ,
395+ ] ,
396+ dark : [
397+ { name : 'base.font-size' , value : '20' , type : TokenTypes . NUMBER } ,
398+ ] ,
399+ } ;
400+
401+ const settings : any = {
402+ aliasBaseFontSize : '{base.font-size}' ,
403+ variablesNumber : true ,
404+ variablesColor : false ,
405+ variablesString : false ,
406+ variablesBoolean : false ,
407+ renameExistingStylesAndVariables : false ,
408+ removeStylesAndVariablesWithoutConnection : false ,
409+ } ;
410+
411+ const themeA : any = {
412+ id : 'theme-a' ,
413+ name : 'Theme A' ,
414+ selectedTokenSets : { core : TokenSetStatus . ENABLED } ,
415+ $figmaModeId : 'mode-a' ,
416+ } ;
417+
418+ const themeB : any = {
419+ id : 'theme-b' ,
420+ name : 'Theme B' ,
421+ selectedTokenSets : {
422+ core : TokenSetStatus . ENABLED ,
423+ dark : TokenSetStatus . ENABLED ,
424+ } ,
425+ $figmaModeId : 'mode-b' ,
426+ } ;
427+
428+ const mockSpacingVariable : any = {
429+ id : 'var1' ,
430+ key : 'var1-key' ,
431+ name : 'spacing/small' ,
432+ resolvedType : 'FLOAT' ,
433+ variableCollectionId : 'collection1' ,
434+ valuesByMode : { 'mode-a' : 0 , 'mode-b' : 0 } , // Initial values changed to 0
435+ setValueForMode : mockSpacingSetValueForMode ,
436+ } ;
437+
438+ const mockBaseFontSizeVariable : any = {
439+ id : 'var2' ,
440+ key : 'var2-key' ,
441+ name : 'base/font-size' ,
442+ resolvedType : 'FLOAT' ,
443+ variableCollectionId : 'collection1' ,
444+ valuesByMode : { 'mode-a' : 0 , 'mode-b' : 0 } , // Initial values changed to 0
445+ setValueForMode : mockBaseFontSizeSetValueForMode ,
446+ } ;
447+
448+ ( figma . variables . getLocalVariables as jest . Mock ) . mockReturnValue ( [
449+ mockSpacingVariable ,
450+ mockBaseFontSizeVariable ,
451+ ] ) ;
452+ ( figma . variables . getVariableByIdAsync as jest . Mock ) . mockImplementation ( async ( id : string ) => {
453+ if ( id === mockSpacingVariable . id ) return mockSpacingVariable ;
454+ if ( id === mockBaseFontSizeVariable . id ) return mockBaseFontSizeVariable ;
455+ return null ;
456+ } ) ;
457+
458+ // Call updateVariables for Theme A (Mode A)
459+ await updateVariables ( {
460+ collection,
461+ mode : 'mode-a' ,
462+ theme : themeA ,
463+ tokens,
464+ settings,
465+ overallConfig : { core : TokenSetStatus . ENABLED } ,
466+ } ) ;
467+
468+ // Call updateVariables for Theme B (Mode B)
469+ await updateVariables ( {
470+ collection,
471+ mode : 'mode-b' ,
472+ theme : themeB ,
473+ tokens,
474+ settings,
475+ overallConfig : {
476+ core : TokenSetStatus . ENABLED ,
477+ dark : TokenSetStatus . ENABLED ,
478+ } ,
479+ } ) ;
480+
481+ // Verify spacing/small got 16px for Mode A (1rem * 16)
482+ // Note: It might not be called if value is already 16, but we check consistency
483+ expect ( mockSpacingSetValueForMode ) . toHaveBeenCalledWith ( 'mode-a' , 16 ) ;
484+ // Verify spacing/small got 20px for Mode B (1rem * 20)
485+ expect ( mockSpacingSetValueForMode ) . toHaveBeenCalledWith ( 'mode-b' , 20 ) ;
486+
487+ // Verify base/font-size updates
488+ expect ( mockBaseFontSizeSetValueForMode ) . toHaveBeenCalledWith ( 'mode-a' , 16 ) ;
489+ expect ( mockBaseFontSizeSetValueForMode ) . toHaveBeenCalledWith ( 'mode-b' , 20 ) ;
490+ } ) ;
300491} ) ;
0 commit comments