|
| 1 | +import {expectTransformFactory} from './expectTransformFactory'; |
| 2 | +import transform from '../addPillLabel'; |
| 3 | +import {stripIndent} from 'common-tags'; |
| 4 | + |
| 5 | +const expectTransform = expectTransformFactory(transform); |
| 6 | + |
| 7 | +describe('Pill', () => { |
| 8 | + it('should not change non-canvas imports', () => { |
| 9 | + const input = stripIndent` |
| 10 | + import {Pill} from '@workday/any-other-package' |
| 11 | + <> |
| 12 | + <Pill>Hello<Pill.Icon/></Pill> |
| 13 | + <Pill /> |
| 14 | + <Pill /> |
| 15 | + </> |
| 16 | + `; |
| 17 | + |
| 18 | + const expected = stripIndent` |
| 19 | + import {Pill} from '@workday/any-other-package' |
| 20 | + <> |
| 21 | + <Pill>Hello<Pill.Icon/></Pill> |
| 22 | + <Pill /> |
| 23 | + <Pill /> |
| 24 | + </> |
| 25 | + `; |
| 26 | + expectTransform(input, expected); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should not change if the only children of Pill is plain text', () => { |
| 30 | + const input = stripIndent` |
| 31 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 32 | + <> |
| 33 | + <Pill> |
| 34 | + Hello World |
| 35 | + </Pill> |
| 36 | + </> |
| 37 | + `; |
| 38 | + |
| 39 | + const expected = stripIndent` |
| 40 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 41 | + <> |
| 42 | + <Pill> |
| 43 | + Hello World |
| 44 | + </Pill> |
| 45 | + </> |
| 46 | + `; |
| 47 | + expectTransform(input, expected); |
| 48 | + }); |
| 49 | + it('should not change if Pill.Label exists', () => { |
| 50 | + const input = stripIndent` |
| 51 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 52 | + <> |
| 53 | + <Pill> |
| 54 | + <Pill.Label>Hello World</Pill.Label> |
| 55 | + </Pill> |
| 56 | + </> |
| 57 | + `; |
| 58 | + |
| 59 | + const expected = stripIndent` |
| 60 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 61 | + <> |
| 62 | + <Pill> |
| 63 | + <Pill.Label>Hello World</Pill.Label> |
| 64 | + </Pill> |
| 65 | + </> |
| 66 | + `; |
| 67 | + expectTransform(input, expected); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should wrap plain text in label if Pill.Icon is present and imported from main Preview package', () => { |
| 71 | + const input = stripIndent` |
| 72 | + import {Pill} from '@workday/canvas-kit-preview-react'; |
| 73 | + <> |
| 74 | + <Pill> |
| 75 | + <Pill.Icon /> |
| 76 | + Hello World |
| 77 | + </Pill> |
| 78 | + </> |
| 79 | + `; |
| 80 | + |
| 81 | + const expected = stripIndent` |
| 82 | + import {Pill} from '@workday/canvas-kit-preview-react'; |
| 83 | + <> |
| 84 | + <Pill> |
| 85 | + <Pill.Icon /><Pill.Label>Hello World</Pill.Label></Pill> |
| 86 | + </> |
| 87 | + `; |
| 88 | + expectTransform(input, expected); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should wrap plain text in label if Pill.Icon is present and Pill is renamed at the import level', () => { |
| 92 | + const input = stripIndent` |
| 93 | + import {Pill as MyPill} from '@workday/canvas-kit-preview-react'; |
| 94 | + <> |
| 95 | + <MyPill> |
| 96 | + <MyPill.Icon /> |
| 97 | + Hello World |
| 98 | + </MyPill> |
| 99 | + </> |
| 100 | + `; |
| 101 | + |
| 102 | + const expected = stripIndent` |
| 103 | + import {Pill as MyPill} from '@workday/canvas-kit-preview-react'; |
| 104 | + <> |
| 105 | + <MyPill> |
| 106 | + <MyPill.Icon /><MyPill.Label>Hello World</MyPill.Label></MyPill> |
| 107 | + </> |
| 108 | + `; |
| 109 | + expectTransform(input, expected); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should change styled Pill', () => { |
| 113 | + const input = stripIndent` |
| 114 | + import {Pill} from '@workday/canvas-kit-preview-react/pill' |
| 115 | + const StyledPill = styled(Pill)({color: "#000"}); |
| 116 | + <> |
| 117 | + <StyledPill> |
| 118 | + <StyledPill.Icon /> |
| 119 | + Hello World |
| 120 | + </StyledPill> |
| 121 | + </> |
| 122 | + `; |
| 123 | + |
| 124 | + const expected = stripIndent` |
| 125 | + import {Pill} from '@workday/canvas-kit-preview-react/pill' |
| 126 | + const StyledPill = styled(Pill)({color: "#000"}); |
| 127 | + <> |
| 128 | + <StyledPill> |
| 129 | + <StyledPill.Icon /><StyledPill.Label>Hello World</StyledPill.Label></StyledPill> |
| 130 | + </> |
| 131 | + `; |
| 132 | + expectTransform(input, expected); |
| 133 | + }); |
| 134 | + |
| 135 | + it('should wrap plain text in label if Pill.Icon is present and Pill is renamed at the import level', () => { |
| 136 | + const input = stripIndent` |
| 137 | + import {Pill as MyPill} from '@workday/canvas-kit-preview-react'; |
| 138 | + <> |
| 139 | + <MyPill> |
| 140 | + <MyPill.Icon /> |
| 141 | + Hello World |
| 142 | + </MyPill> |
| 143 | + </> |
| 144 | + `; |
| 145 | + |
| 146 | + const expected = stripIndent` |
| 147 | + import {Pill as MyPill} from '@workday/canvas-kit-preview-react'; |
| 148 | + <> |
| 149 | + <MyPill> |
| 150 | + <MyPill.Icon /><MyPill.Label>Hello World</MyPill.Label></MyPill> |
| 151 | + </> |
| 152 | + `; |
| 153 | + expectTransform(input, expected); |
| 154 | + }); |
| 155 | + |
| 156 | + it('should wrap plain text in label if Pill.Icon is present', () => { |
| 157 | + const input = stripIndent` |
| 158 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 159 | + <> |
| 160 | + <Pill> |
| 161 | + <Pill.Icon /> |
| 162 | + Hello World |
| 163 | + </Pill> |
| 164 | + </> |
| 165 | + `; |
| 166 | + |
| 167 | + const expected = stripIndent` |
| 168 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 169 | + <> |
| 170 | + <Pill> |
| 171 | + <Pill.Icon /><Pill.Label>Hello World</Pill.Label></Pill> |
| 172 | + </> |
| 173 | + `; |
| 174 | + expectTransform(input, expected); |
| 175 | + }); |
| 176 | + it('should wrap text in label if Pill.IconButton is present and the text is rendered as an expression', () => { |
| 177 | + const input = stripIndent` |
| 178 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 179 | + const myVar = 'Hello World'; |
| 180 | + <> |
| 181 | + <Pill> |
| 182 | + {myVar} |
| 183 | + <Pill.IconButton /> |
| 184 | + </Pill> |
| 185 | + </> |
| 186 | + `; |
| 187 | + |
| 188 | + const expected = stripIndent` |
| 189 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 190 | + const myVar = 'Hello World'; |
| 191 | + <> |
| 192 | + <Pill> |
| 193 | + <Pill.Label>{myVar}</Pill.Label> |
| 194 | + <Pill.IconButton /> |
| 195 | + </Pill> |
| 196 | + </> |
| 197 | + `; |
| 198 | + expectTransform(input, expected); |
| 199 | + }); |
| 200 | + it('should wrap text in label if Pill.IconButton is present and the text is rendered as an expression', () => { |
| 201 | + const input = stripIndent` |
| 202 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 203 | + const myVar = 'Hello World'; |
| 204 | + <> |
| 205 | + <Pill |
| 206 | + margin="auto" |
| 207 | + marginTop="xxl" |
| 208 | + variant="readOnly" |
| 209 | + backgroundColor="soap100" |
| 210 | + data-automation-id="branding-banner-pill" |
| 211 | + > |
| 212 | + {getText('Some.Text')} |
| 213 | + </Pill> |
| 214 | + </> |
| 215 | + `; |
| 216 | + |
| 217 | + const expected = stripIndent` |
| 218 | + import {Pill} from '@workday/canvas-kit-preview-react/pill'; |
| 219 | + const myVar = 'Hello World'; |
| 220 | + <> |
| 221 | + <Pill |
| 222 | + margin="auto" |
| 223 | + marginTop="xxl" |
| 224 | + variant="readOnly" |
| 225 | + backgroundColor="soap100" |
| 226 | + data-automation-id="branding-banner-pill" |
| 227 | + > |
| 228 | + {getText('Some.Text')} |
| 229 | + </Pill> |
| 230 | + </> |
| 231 | + `; |
| 232 | + expectTransform(input, expected); |
| 233 | + }); |
| 234 | +}); |
0 commit comments