|
| 1 | +import path from 'path' |
| 2 | +import postcss from 'postcss' |
| 3 | +import tailwind from 'tailwindcss' |
| 4 | +import hui from './index' |
| 5 | + |
| 6 | +let html = String.raw |
| 7 | +let css = String.raw |
| 8 | + |
| 9 | +function run(input: string, config: any, plugin = tailwind) { |
| 10 | + let { currentTestName } = expect.getState() |
| 11 | + |
| 12 | + return postcss(plugin(config)).process(input, { |
| 13 | + from: `${path.resolve(__filename)}?test=${currentTestName}`, |
| 14 | + }) |
| 15 | +} |
| 16 | + |
| 17 | +it('should generate css for an exposed state', async () => { |
| 18 | + let config = { |
| 19 | + content: [{ raw: html`<div class="ui-open:underline"></div>` }], |
| 20 | + plugins: [hui], |
| 21 | + } |
| 22 | + |
| 23 | + return run('@tailwind utilities', config).then((result) => { |
| 24 | + expect(result.css).toMatchFormattedCss(css` |
| 25 | + .ui-open\:underline[data-headlessui-state~='open'] { |
| 26 | + text-decoration-line: underline; |
| 27 | + } |
| 28 | + :where([data-headlessui-state~='open']) .ui-open\:underline { |
| 29 | + text-decoration-line: underline; |
| 30 | + } |
| 31 | + `) |
| 32 | + }) |
| 33 | +}) |
| 34 | + |
| 35 | +it('should generate the inverse "not" css for an exposed state', async () => { |
| 36 | + let config = { |
| 37 | + content: [{ raw: html`<div class="ui-not-open:underline"></div>` }], |
| 38 | + plugins: [hui], |
| 39 | + } |
| 40 | + |
| 41 | + return run('@tailwind utilities', config).then((result) => { |
| 42 | + expect(result.css).toMatchFormattedCss(css` |
| 43 | + .ui-not-open\:underline[data-headlessui-state]:not([data-headlessui-state~='open']) { |
| 44 | + text-decoration-line: underline; |
| 45 | + } |
| 46 | +
|
| 47 | + :where([data-headlessui-state]:not([data-headlessui-state~='open'])) |
| 48 | + .ui-not-open\:underline:not([data-headlessui-state]) { |
| 49 | + text-decoration-line: underline; |
| 50 | + } |
| 51 | + `) |
| 52 | + }) |
| 53 | +}) |
| 54 | + |
| 55 | +describe('custom prefix', () => { |
| 56 | + it('should generate css for an exposed state', async () => { |
| 57 | + let config = { |
| 58 | + content: [{ raw: html`<div class="hui-open:underline"></div>` }], |
| 59 | + plugins: [hui({ prefix: 'hui' })], |
| 60 | + } |
| 61 | + |
| 62 | + return run('@tailwind utilities', config).then((result) => { |
| 63 | + expect(result.css).toMatchFormattedCss(css` |
| 64 | + .hui-open\:underline[data-headlessui-state~='open'] { |
| 65 | + text-decoration-line: underline; |
| 66 | + } |
| 67 | + :where([data-headlessui-state~='open']) .hui-open\:underline { |
| 68 | + text-decoration-line: underline; |
| 69 | + } |
| 70 | + `) |
| 71 | + }) |
| 72 | + }) |
| 73 | + |
| 74 | + it('should generate the inverse "not" css for an exposed state', async () => { |
| 75 | + let config = { |
| 76 | + content: [{ raw: html`<div class="hui-not-open:underline"></div>` }], |
| 77 | + plugins: [hui({ prefix: 'hui' })], |
| 78 | + } |
| 79 | + |
| 80 | + return run('@tailwind utilities', config).then((result) => { |
| 81 | + expect(result.css).toMatchFormattedCss(css` |
| 82 | + .hui-not-open\:underline[data-headlessui-state]:not([data-headlessui-state~='open']) { |
| 83 | + text-decoration-line: underline; |
| 84 | + } |
| 85 | +
|
| 86 | + :where([data-headlessui-state]:not([data-headlessui-state~='open'])) |
| 87 | + .hui-not-open\:underline:not([data-headlessui-state]) { |
| 88 | + text-decoration-line: underline; |
| 89 | + } |
| 90 | + `) |
| 91 | + }) |
| 92 | + }) |
| 93 | +}) |
0 commit comments