|
| 1 | +import { run, html, css } from './util/run' |
| 2 | + |
| 3 | +// TODO: Remove this once we enable this by default |
| 4 | +it('should not generate nested selectors if the feature flag is not enabled', () => { |
| 5 | + let config = { |
| 6 | + content: [{ raw: html`<div class="md:(underline,italic)"></div>` }], |
| 7 | + corePlugins: { preflight: false }, |
| 8 | + plugins: [], |
| 9 | + } |
| 10 | + |
| 11 | + let input = css` |
| 12 | + @tailwind utilities; |
| 13 | + ` |
| 14 | + |
| 15 | + return run(input, config).then((result) => { |
| 16 | + expect(result.css).toMatchFormattedCss(css` |
| 17 | + .italic { |
| 18 | + font-style: italic; |
| 19 | + } |
| 20 | +
|
| 21 | + .underline { |
| 22 | + text-decoration-line: underline; |
| 23 | + } |
| 24 | + `) |
| 25 | + }) |
| 26 | +}) |
| 27 | + |
| 28 | +it('should be possible to group variants', () => { |
| 29 | + let config = { |
| 30 | + experimental: 'all', |
| 31 | + content: [{ raw: html`<div class="md:(underline,italic)"></div>` }], |
| 32 | + corePlugins: { preflight: false }, |
| 33 | + plugins: [], |
| 34 | + } |
| 35 | + |
| 36 | + let input = css` |
| 37 | + @tailwind utilities; |
| 38 | + ` |
| 39 | + |
| 40 | + return run(input, config).then((result) => { |
| 41 | + expect(result.css).toMatchFormattedCss(css` |
| 42 | + @media (min-width: 768px) { |
| 43 | + .md\:\(underline\2c italic\) { |
| 44 | + font-style: italic; |
| 45 | + text-decoration-line: underline; |
| 46 | + } |
| 47 | + } |
| 48 | + `) |
| 49 | + }) |
| 50 | +}) |
| 51 | + |
| 52 | +it('should be possible to group multiple variants', () => { |
| 53 | + let config = { |
| 54 | + experimental: 'all', |
| 55 | + content: [{ raw: html`<div class="md:dark:(underline,italic)"></div>` }], |
| 56 | + corePlugins: { preflight: false }, |
| 57 | + plugins: [], |
| 58 | + } |
| 59 | + |
| 60 | + let input = css` |
| 61 | + @tailwind utilities; |
| 62 | + ` |
| 63 | + |
| 64 | + return run(input, config).then((result) => { |
| 65 | + expect(result.css).toMatchFormattedCss(css` |
| 66 | + @media (min-width: 768px) { |
| 67 | + @media (prefers-color-scheme: dark) { |
| 68 | + .md\:dark\:\(underline\2c italic\) { |
| 69 | + font-style: italic; |
| 70 | + text-decoration-line: underline; |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + `) |
| 75 | + }) |
| 76 | +}) |
| 77 | + |
| 78 | +it('should be possible to group nested grouped variants', () => { |
| 79 | + let config = { |
| 80 | + experimental: 'all', |
| 81 | + content: [{ raw: html`<div class="md:(underline,italic,hover:(uppercase,font-bold))"></div>` }], |
| 82 | + corePlugins: { preflight: false }, |
| 83 | + plugins: [], |
| 84 | + } |
| 85 | + |
| 86 | + let input = css` |
| 87 | + @tailwind utilities; |
| 88 | + ` |
| 89 | + |
| 90 | + return run(input, config).then((result) => { |
| 91 | + expect(result.css).toMatchFormattedCss(css` |
| 92 | + @media (min-width: 768px) { |
| 93 | + .md\:\(underline\2c italic\2c hover\:\(uppercase\2c font-bold\)\) { |
| 94 | + font-style: italic; |
| 95 | + text-decoration-line: underline; |
| 96 | + } |
| 97 | +
|
| 98 | + .md\:\(underline\2c italic\2c hover\:\(uppercase\2c font-bold\)\):hover { |
| 99 | + font-weight: 700; |
| 100 | + text-transform: uppercase; |
| 101 | + } |
| 102 | + } |
| 103 | + `) |
| 104 | + }) |
| 105 | +}) |
| 106 | + |
| 107 | +it('should be possible to use nested multiple grouped variants', () => { |
| 108 | + let config = { |
| 109 | + experimental: 'all', |
| 110 | + content: [ |
| 111 | + { |
| 112 | + raw: html`<div class="md:(text-black,dark:(text-white,hover:focus:text-gray-100))"></div>`, |
| 113 | + }, |
| 114 | + ], |
| 115 | + corePlugins: { preflight: false }, |
| 116 | + plugins: [], |
| 117 | + } |
| 118 | + |
| 119 | + let input = css` |
| 120 | + @tailwind utilities; |
| 121 | + ` |
| 122 | + |
| 123 | + return run(input, config).then((result) => { |
| 124 | + expect(result.css).toMatchFormattedCss(css` |
| 125 | + @media (min-width: 768px) { |
| 126 | + .md\:\(text-black\2c dark\:\(text-white\2c hover\:focus\:text-gray-100\)\) { |
| 127 | + --tw-text-opacity: 1; |
| 128 | + color: rgb(0 0 0 / var(--tw-text-opacity)); |
| 129 | + } |
| 130 | +
|
| 131 | + @media (prefers-color-scheme: dark) { |
| 132 | + .md\:\(text-black\2c dark\:\(text-white\2c hover\:focus\:text-gray-100\)\) { |
| 133 | + --tw-text-opacity: 1; |
| 134 | + color: rgb(255 255 255 / var(--tw-text-opacity)); |
| 135 | + } |
| 136 | + .md\:\(text-black\2c dark\:\(text-white\2c hover\:focus\:text-gray-100\)\):focus:hover { |
| 137 | + --tw-text-opacity: 1; |
| 138 | + color: rgb(243 244 246 / var(--tw-text-opacity)); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + `) |
| 143 | + }) |
| 144 | +}) |
| 145 | + |
| 146 | +it('should group with variants defined in external plugins', () => { |
| 147 | + let config = { |
| 148 | + experimental: 'all', |
| 149 | + content: [ |
| 150 | + { |
| 151 | + raw: html` |
| 152 | + <div class="ui-active:(bg-black,text-white) ui-selected:(bg-indigo-500,underline)"></div> |
| 153 | + `, |
| 154 | + }, |
| 155 | + ], |
| 156 | + corePlugins: { preflight: false }, |
| 157 | + plugins: [ |
| 158 | + ({ addVariant }) => { |
| 159 | + addVariant('ui-active', ['&[data-ui-state~="active"]', '[data-ui-state~="active"] &']) |
| 160 | + addVariant('ui-selected', ['&[data-ui-state~="selected"]', '[data-ui-state~="selected"] &']) |
| 161 | + }, |
| 162 | + ], |
| 163 | + } |
| 164 | + |
| 165 | + let input = css` |
| 166 | + @tailwind utilities; |
| 167 | + ` |
| 168 | + |
| 169 | + return run(input, config).then((result) => { |
| 170 | + expect(result.css).toMatchFormattedCss(css` |
| 171 | + .ui-active\:\(bg-black\2c text-white\)[data-ui-state~='active'] { |
| 172 | + --tw-bg-opacity: 1; |
| 173 | + background-color: rgb(0 0 0 / var(--tw-bg-opacity)); |
| 174 | + --tw-text-opacity: 1; |
| 175 | + color: rgb(255 255 255 / var(--tw-text-opacity)); |
| 176 | + } |
| 177 | +
|
| 178 | + [data-ui-state~='active'] .ui-active\:\(bg-black\2c text-white\) { |
| 179 | + --tw-bg-opacity: 1; |
| 180 | + background-color: rgb(0 0 0 / var(--tw-bg-opacity)); |
| 181 | + --tw-text-opacity: 1; |
| 182 | + color: rgb(255 255 255 / var(--tw-text-opacity)); |
| 183 | + } |
| 184 | +
|
| 185 | + .ui-selected\:\(bg-indigo-500\2c underline\)[data-ui-state~='selected'] { |
| 186 | + --tw-bg-opacity: 1; |
| 187 | + background-color: rgb(99 102 241 / var(--tw-bg-opacity)); |
| 188 | + text-decoration-line: underline; |
| 189 | + } |
| 190 | +
|
| 191 | + [data-ui-state~='selected'] .ui-selected\:\(bg-indigo-500\2c underline\) { |
| 192 | + --tw-bg-opacity: 1; |
| 193 | + background-color: rgb(99 102 241 / var(--tw-bg-opacity)); |
| 194 | + text-decoration-line: underline; |
| 195 | + } |
| 196 | + `) |
| 197 | + }) |
| 198 | +}) |
0 commit comments