|
| 1 | +import {stripIndent} from 'common-tags'; |
| 2 | + |
| 3 | +import transform from '../updateSidePanelVariant'; |
| 4 | +import {expectTransformFactory} from './expectTransformFactory'; |
| 5 | + |
| 6 | +const expectTransform = expectTransformFactory(transform); |
| 7 | + |
| 8 | +describe('updateSidePanelVariant', () => { |
| 9 | + it('should convert variant="alternate" to variant="overlay" on package root imports', () => { |
| 10 | + const input = stripIndent` |
| 11 | + import {SidePanel} from '@workday/canvas-kit-react' |
| 12 | + <SidePanel variant="alternate">Content</SidePanel> |
| 13 | + `; |
| 14 | + |
| 15 | + const expected = stripIndent` |
| 16 | + import {SidePanel} from '@workday/canvas-kit-react' |
| 17 | + <SidePanel variant="overlay">Content</SidePanel> |
| 18 | + `; |
| 19 | + expectTransform(input, expected); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should convert variant="alternate" to variant="overlay" on slash imports', () => { |
| 23 | + const input = stripIndent` |
| 24 | + import {SidePanel} from '@workday/canvas-kit-react/side-panel' |
| 25 | + <SidePanel variant="alternate">Content</SidePanel> |
| 26 | + `; |
| 27 | + |
| 28 | + const expected = stripIndent` |
| 29 | + import {SidePanel} from '@workday/canvas-kit-react/side-panel' |
| 30 | + <SidePanel variant="overlay">Content</SidePanel> |
| 31 | + `; |
| 32 | + expectTransform(input, expected); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should transform aliased imports', () => { |
| 36 | + const input = stripIndent` |
| 37 | + import {SidePanel as Panel} from '@workday/canvas-kit-react/side-panel' |
| 38 | + <Panel variant="alternate">Content</Panel> |
| 39 | + `; |
| 40 | + |
| 41 | + const expected = stripIndent` |
| 42 | + import {SidePanel as Panel} from '@workday/canvas-kit-react/side-panel' |
| 43 | + <Panel variant="overlay">Content</Panel> |
| 44 | + `; |
| 45 | + expectTransform(input, expected); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should handle variant={"alternate"} expression values', () => { |
| 49 | + const input = stripIndent` |
| 50 | + import {SidePanel} from '@workday/canvas-kit-react/side-panel' |
| 51 | + <SidePanel variant={'alternate'}>Content</SidePanel> |
| 52 | + `; |
| 53 | + |
| 54 | + const expected = stripIndent` |
| 55 | + import {SidePanel} from '@workday/canvas-kit-react/side-panel' |
| 56 | + <SidePanel variant="overlay">Content</SidePanel> |
| 57 | + `; |
| 58 | + expectTransform(input, expected); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should transform styled-wrapped components', () => { |
| 62 | + const input = stripIndent` |
| 63 | + import styled from '@emotion/styled'; |
| 64 | + import {SidePanel} from '@workday/canvas-kit-react/side-panel' |
| 65 | + const StyledPanel = styled(SidePanel)({color: '#000'}); |
| 66 | + <StyledPanel variant="alternate">Content</StyledPanel> |
| 67 | + `; |
| 68 | + |
| 69 | + const expected = stripIndent` |
| 70 | + import styled from '@emotion/styled'; |
| 71 | + import {SidePanel} from '@workday/canvas-kit-react/side-panel' |
| 72 | + const StyledPanel = styled(SidePanel)({color: '#000'}); |
| 73 | + <StyledPanel variant="overlay">Content</StyledPanel> |
| 74 | + `; |
| 75 | + expectTransform(input, expected); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should transform styled-wrapped components from package root imports', () => { |
| 79 | + const input = stripIndent` |
| 80 | + import styled from '@emotion/styled'; |
| 81 | + import {SidePanel} from '@workday/canvas-kit-react' |
| 82 | + const StyledPanel = styled(SidePanel)({color: '#000'}); |
| 83 | + <StyledPanel variant="alternate">Content</StyledPanel> |
| 84 | + `; |
| 85 | + |
| 86 | + const expected = stripIndent` |
| 87 | + import styled from '@emotion/styled'; |
| 88 | + import {SidePanel} from '@workday/canvas-kit-react' |
| 89 | + const StyledPanel = styled(SidePanel)({color: '#000'}); |
| 90 | + <StyledPanel variant="overlay">Content</StyledPanel> |
| 91 | + `; |
| 92 | + expectTransform(input, expected); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should not transform variant="standard"', () => { |
| 96 | + const input = stripIndent` |
| 97 | + import {SidePanel} from '@workday/canvas-kit-react/side-panel' |
| 98 | + <SidePanel variant="standard">Content</SidePanel> |
| 99 | + `; |
| 100 | + |
| 101 | + const expected = stripIndent` |
| 102 | + import {SidePanel} from '@workday/canvas-kit-react/side-panel' |
| 103 | + <SidePanel variant="standard">Content</SidePanel> |
| 104 | + `; |
| 105 | + expectTransform(input, expected); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should not transform when SidePanel is not imported', () => { |
| 109 | + const input = stripIndent` |
| 110 | + import {Button} from '@workday/canvas-kit-react' |
| 111 | + <Button variant="alternate">Click me</Button> |
| 112 | + `; |
| 113 | + |
| 114 | + const expected = stripIndent` |
| 115 | + import {Button} from '@workday/canvas-kit-react' |
| 116 | + <Button variant="alternate">Click me</Button> |
| 117 | + `; |
| 118 | + expectTransform(input, expected); |
| 119 | + }); |
| 120 | + |
| 121 | + it('should not transform SidePanel imported from the preview package', () => { |
| 122 | + const input = stripIndent` |
| 123 | + import {SidePanel} from '@workday/canvas-kit-preview-react/side-panel' |
| 124 | + <SidePanel variant="alternate">Content</SidePanel> |
| 125 | + `; |
| 126 | + |
| 127 | + const expected = stripIndent` |
| 128 | + import {SidePanel} from '@workday/canvas-kit-preview-react/side-panel' |
| 129 | + <SidePanel variant="alternate">Content</SidePanel> |
| 130 | + `; |
| 131 | + expectTransform(input, expected); |
| 132 | + }); |
| 133 | +}); |
0 commit comments