|
| 1 | +import {processCompositeTokenReferences} from './processCompositeTokenReferences.js' |
| 2 | + |
| 3 | +describe('processCompositeTokenReferences', () => { |
| 4 | + // ... existing code ... |
| 5 | + |
| 6 | + test('should handle composite border token references', () => { |
| 7 | + const value = '1px solid #000000' |
| 8 | + const originalValue = { |
| 9 | + width: '{border.width.small}', |
| 10 | + style: '{border.style.solid}', |
| 11 | + color: '{color.black}', |
| 12 | + } |
| 13 | + const properties = ['width', 'style', 'color'] |
| 14 | + const refs = [ |
| 15 | + {path: ['border', 'width', 'small'], isSource: true}, |
| 16 | + {path: ['border', 'style', 'solid'], isSource: true}, |
| 17 | + {path: ['color', 'black'], isSource: true}, |
| 18 | + ] |
| 19 | + const sanitizeValue: string[] = [] |
| 20 | + |
| 21 | + const result = processCompositeTokenReferences(value, originalValue, properties, refs, sanitizeValue) |
| 22 | + expect(result).toBe('{border.width.small} {border.style.solid} {color.black}') |
| 23 | + }) |
| 24 | + |
| 25 | + test('should handle composite border token with mixed references', () => { |
| 26 | + const value = '1px solid #000000' |
| 27 | + const originalValue = { |
| 28 | + width: '{border.width.small}', |
| 29 | + style: 'solid', |
| 30 | + color: '{color.black}', |
| 31 | + } |
| 32 | + const properties = ['width', 'style', 'color'] |
| 33 | + const refs = [ |
| 34 | + {path: ['border', 'width', 'small'], isSource: true}, |
| 35 | + {path: ['color', 'black'], isSource: true}, |
| 36 | + ] |
| 37 | + const sanitizeValue = ['px'] |
| 38 | + |
| 39 | + const result = processCompositeTokenReferences(value, originalValue, properties, refs, sanitizeValue) |
| 40 | + expect(result).toBe('{border.width.small} solid {color.black}') |
| 41 | + }) |
| 42 | + |
| 43 | + test('should handle composite border token with invalid references', () => { |
| 44 | + const value = '1px solid #000000' |
| 45 | + const originalValue = { |
| 46 | + width: '{border.width.small}', |
| 47 | + style: '{border.style.solid}', |
| 48 | + color: '{color.black}', |
| 49 | + } |
| 50 | + const properties = ['width', 'style', 'color'] |
| 51 | + const refs = [ |
| 52 | + {path: ['border', 'width', 'small'], isSource: false}, |
| 53 | + {path: ['border', 'style', 'solid'], isSource: true}, |
| 54 | + {path: ['color', 'black'], isSource: false}, |
| 55 | + ] |
| 56 | + const sanitizeValue = ['px'] |
| 57 | + |
| 58 | + const result = processCompositeTokenReferences(value, originalValue, properties, refs, sanitizeValue) |
| 59 | + expect(result).toBe('1 {border.style.solid} #000000') |
| 60 | + }) |
| 61 | + |
| 62 | + test('should handle composite shadow token references', () => { |
| 63 | + const value = '0px 4px 6px -1px rgba(0, 0, 0, 0.1)' |
| 64 | + const originalValue = { |
| 65 | + offsetX: '{shadow.offsetX.none}', |
| 66 | + offsetY: '{shadow.offsetY.small}', |
| 67 | + blur: '{shadow.blur.medium}', |
| 68 | + spread: '{shadow.spread.small}', |
| 69 | + color: '{color.black.alpha10}', |
| 70 | + } |
| 71 | + const properties = ['offsetX', 'offsetY', 'blur', 'spread', 'color'] |
| 72 | + const refs = [ |
| 73 | + {path: ['shadow', 'offsetX', 'none'], isSource: true}, |
| 74 | + {path: ['shadow', 'offsetY', 'small'], isSource: true}, |
| 75 | + {path: ['shadow', 'blur', 'medium'], isSource: true}, |
| 76 | + {path: ['shadow', 'spread', 'small'], isSource: true}, |
| 77 | + {path: ['color', 'black', 'alpha10'], isSource: true}, |
| 78 | + ] |
| 79 | + const sanitizeValue: string[] = [] |
| 80 | + |
| 81 | + const result = processCompositeTokenReferences(value, originalValue, properties, refs, sanitizeValue) |
| 82 | + expect(result).toBe( |
| 83 | + '{shadow.offsetX.none} {shadow.offsetY.small} {shadow.blur.medium} {shadow.spread.small} {color.black.alpha10}', |
| 84 | + ) |
| 85 | + }) |
| 86 | + |
| 87 | + test('should handle composite shadow token with mixed references', () => { |
| 88 | + const value = 'inset 0px 4px 6px -1px rgba(0, 0, 0, 0.1)' |
| 89 | + const originalValue = { |
| 90 | + inset: true, |
| 91 | + offsetX: '{shadow.offsetX.none}', |
| 92 | + offsetY: '4px', |
| 93 | + blur: '{shadow.blur.medium}', |
| 94 | + spread: '-1px', |
| 95 | + color: '{color.black.alpha10}', |
| 96 | + } |
| 97 | + |
| 98 | + const properties = ['offsetX', 'offsetY', 'blur', 'spread', 'color'] |
| 99 | + const refs = [ |
| 100 | + {path: ['shadow', 'offsetX', 'none'], isSource: true}, |
| 101 | + {path: ['shadow', 'blur', 'medium'], isSource: true}, |
| 102 | + {path: ['color', 'black', 'alpha10'], isSource: true}, |
| 103 | + ] |
| 104 | + const sanitizeValue = ['inset'] |
| 105 | + |
| 106 | + const result = processCompositeTokenReferences(value, originalValue, properties, refs, sanitizeValue) |
| 107 | + expect(result).toBe('{shadow.offsetX.none} 4px {shadow.blur.medium} -1px {color.black.alpha10}') |
| 108 | + }) |
| 109 | + |
| 110 | + test('should handle composite shadow token with invalid references', () => { |
| 111 | + const value = '0px 4px 6px -1px rgba(0, 0, 0, 0.1)' |
| 112 | + const originalValue = { |
| 113 | + offsetX: '{shadow.offsetX.none}', |
| 114 | + offsetY: '{shadow.offsetY.small}', |
| 115 | + blur: '{shadow.blur.medium}', |
| 116 | + spread: '{shadow.spread.small}', |
| 117 | + color: '{color.black.alpha10}', |
| 118 | + } |
| 119 | + const properties = ['offsetX', 'offsetY', 'blur', 'spread', 'color'] |
| 120 | + const refs = [ |
| 121 | + {path: ['shadow', 'offsetX', 'none'], isSource: false}, |
| 122 | + {path: ['shadow', 'offsetY', 'small'], isSource: true}, |
| 123 | + {path: ['shadow', 'blur', 'medium'], isSource: false}, |
| 124 | + {path: ['shadow', 'spread', 'small'], isSource: true}, |
| 125 | + {path: ['color', 'black', 'alpha10'], isSource: false}, |
| 126 | + ] |
| 127 | + |
| 128 | + const result = processCompositeTokenReferences(value, originalValue, properties, refs) |
| 129 | + expect(result).toBe('0px {shadow.offsetY.small} 6px {shadow.spread.small} rgba(0, 0, 0, 0.1)') |
| 130 | + }) |
| 131 | + |
| 132 | + test('should handle complex shadow token with multiple values', () => { |
| 133 | + const value = '0px 4px 6px -1px rgba(0, 0, 0, 0.1), 0px 2px 4px -1px rgba(0, 0, 0, 0.06)' |
| 134 | + const originalValue = { |
| 135 | + shadow1: '{shadow.medium}', |
| 136 | + shadow2: '{shadow.small}', |
| 137 | + } |
| 138 | + const properties = ['shadow1', 'shadow2'] |
| 139 | + const refs = [ |
| 140 | + {path: ['shadow', 'medium'], isSource: true}, |
| 141 | + {path: ['shadow', 'small'], isSource: true}, |
| 142 | + ] |
| 143 | + |
| 144 | + const result = processCompositeTokenReferences(value, originalValue, properties, refs) |
| 145 | + expect(result).toBe('{shadow.medium} {shadow.small}') |
| 146 | + }) |
| 147 | + |
| 148 | + test('should not split rgb or rgba values', () => { |
| 149 | + const value = '0px 4px 6px -1px rgb(0, 0, 0)' |
| 150 | + const originalValue = { |
| 151 | + offsetX: '{shadow.offsetX.none}', |
| 152 | + offsetY: '{shadow.offsetY.small}', |
| 153 | + blur: '{shadow.blur.medium}', |
| 154 | + spread: '{shadow.spread.small}', |
| 155 | + color: '{color.black}', |
| 156 | + } |
| 157 | + const properties = ['offsetX', 'offsetY', 'blur', 'spread', 'color'] |
| 158 | + const refs = [ |
| 159 | + {path: ['shadow', 'offsetX', 'none'], isSource: false}, |
| 160 | + {path: ['shadow', 'offsetY', 'small'], isSource: true}, |
| 161 | + {path: ['shadow', 'blur', 'medium'], isSource: false}, |
| 162 | + {path: ['shadow', 'spread', 'small'], isSource: true}, |
| 163 | + {path: ['color', 'black'], isSource: false}, |
| 164 | + ] |
| 165 | + |
| 166 | + const result = processCompositeTokenReferences(value, originalValue, properties, refs) |
| 167 | + expect(result).toBe('0px {shadow.offsetY.small} 6px {shadow.spread.small} rgb(0, 0, 0)') |
| 168 | + }) |
| 169 | +}) |
0 commit comments