|
| 1 | +import { applyTransform } from '@hypermod/utils'; |
| 2 | +import transformer from '..'; |
| 3 | + |
| 4 | +it('should update token for dashboard sidebar example', async () => { |
| 5 | + const result = await applyTransform( |
| 6 | + transformer, |
| 7 | + ` |
| 8 | + export const SidebarContainer = styled.div<SidebarContainerProps>( |
| 9 | + ({ theme, isRTUXHomepage, isVisible, isMobile }) => \` |
| 10 | + display: flex; |
| 11 | + flex-direction: column; |
| 12 | + position: fixed; |
| 13 | + top: 0; |
| 14 | + bottom: 0; |
| 15 | + background-color: \${ |
| 16 | + isRTUXHomepage |
| 17 | + ? isMobile |
| 18 | + ? theme.colors.surface.background.cloud.subtle |
| 19 | + : 'transparent' |
| 20 | + : '#2e3345' |
| 21 | + }; |
| 22 | + transform: translate(-100%,0); |
| 23 | + transition: transform \${makeMotionTime(theme.motion.delay.short)} \${ |
| 24 | + theme.motion.easing.standard.effective |
| 25 | + }; |
| 26 | + \`); |
| 27 | + `, |
| 28 | + { parser: 'tsx' }, |
| 29 | + ); |
| 30 | + |
| 31 | + expect(result).toMatchInlineSnapshot(` |
| 32 | + "export const SidebarContainer = styled.div<SidebarContainerProps>( |
| 33 | + ({ theme, isRTUXHomepage, isVisible, isMobile }) => \` |
| 34 | + display: flex; |
| 35 | + flex-direction: column; |
| 36 | + position: fixed; |
| 37 | + top: 0; |
| 38 | + bottom: 0; |
| 39 | + background-color: \${ |
| 40 | + isRTUXHomepage |
| 41 | + ? isMobile |
| 42 | + ? theme.colors.surface.background.cloud.subtle |
| 43 | + : 'transparent' |
| 44 | + : '#2e3345' |
| 45 | + }; |
| 46 | + transform: translate(-100%,0); |
| 47 | + transition: transform \${makeMotionTime(theme.motion.delay.short)} \${ |
| 48 | + theme.motion.easing.standard |
| 49 | + }; |
| 50 | + \`);" |
| 51 | + `); |
| 52 | +}); |
| 53 | + |
| 54 | +it('should update token when used as prop', async () => { |
| 55 | + const result = await applyTransform( |
| 56 | + transformer, |
| 57 | + ` |
| 58 | + function App() { |
| 59 | + const { theme } = useTheme(); |
| 60 | +
|
| 61 | + return <Box easing={theme.motion.easing.standard.wary} /> |
| 62 | + } |
| 63 | + `, |
| 64 | + { parser: 'tsx' }, |
| 65 | + ); |
| 66 | + |
| 67 | + expect(result).toMatchInlineSnapshot(` |
| 68 | + "function App() { |
| 69 | + const { theme } = useTheme(); |
| 70 | +
|
| 71 | + return <Box easing={theme.motion.easing.shake} /> |
| 72 | + }" |
| 73 | + `); |
| 74 | +}); |
| 75 | + |
| 76 | +it('should update token as used in X payroll', async () => { |
| 77 | + const result = await applyTransform( |
| 78 | + transformer, |
| 79 | + ` |
| 80 | + export const AnimatedContainer = styled.div<{ delay?: number }>(({ theme, delay = 0 }) => { |
| 81 | + return css\` |
| 82 | + animation: \${entry} \${makeMotionTime(theme.motion.duration['2xgentle'])} |
| 83 | + \${theme.motion.easing.entrance.revealing} forwards; |
| 84 | + animation-delay: \${delay}ms; |
| 85 | + opacity: 0; |
| 86 | + \`; |
| 87 | + }); |
| 88 | + `, |
| 89 | + { parser: 'tsx' }, |
| 90 | + ); |
| 91 | + |
| 92 | + expect(result).toMatchInlineSnapshot(` |
| 93 | + "export const AnimatedContainer = styled.div<{ delay?: number }>(({ theme, delay = 0 }) => { |
| 94 | + return css\` |
| 95 | + animation: \${entry} \${makeMotionTime(theme.motion.duration['2xgentle'])} |
| 96 | + \${theme.motion.easing.entrance} forwards; |
| 97 | + animation-delay: \${delay}ms; |
| 98 | + opacity: 0; |
| 99 | + \`; |
| 100 | + });" |
| 101 | + `); |
| 102 | +}); |
| 103 | + |
| 104 | +it('should update token when variable name is not "theme"', async () => { |
| 105 | + const result = await applyTransform( |
| 106 | + transformer, |
| 107 | + ` |
| 108 | + export const AnimatedContainer = styled.div<{ delay?: number }>(({ theme, delay = 0 }) => { |
| 109 | + return css\` |
| 110 | + animation: \${entry} \${makeMotionTime(paymentTheme.motion.duration['2xgentle'])} |
| 111 | + \${paymentTheme.motion.easing.exit.effective} forwards; |
| 112 | + animation-delay: \${delay}ms; |
| 113 | + opacity: 0; |
| 114 | + \`; |
| 115 | + }); |
| 116 | + `, |
| 117 | + { parser: 'tsx' }, |
| 118 | + ); |
| 119 | + |
| 120 | + expect(result).toMatchInlineSnapshot(` |
| 121 | + "export const AnimatedContainer = styled.div<{ delay?: number }>(({ theme, delay = 0 }) => { |
| 122 | + return css\` |
| 123 | + animation: \${entry} \${makeMotionTime(paymentTheme.motion.duration['2xgentle'])} |
| 124 | + \${paymentTheme.motion.easing.exit} forwards; |
| 125 | + animation-delay: \${delay}ms; |
| 126 | + opacity: 0; |
| 127 | + \`; |
| 128 | + });" |
| 129 | + `); |
| 130 | +}); |
0 commit comments