|
| 1 | +import _ from 'lodash' |
| 2 | +import postcss from 'postcss' |
| 3 | +import processPlugins from '../src/util/processPlugins' |
| 4 | +import container from '../src/plugins/container' |
| 5 | + |
| 6 | +function css(nodes) { |
| 7 | + return postcss.root({ nodes }).toString() |
| 8 | +} |
| 9 | + |
| 10 | +function processPluginsWithValidConfig(config) { |
| 11 | + return processPlugins( |
| 12 | + _.defaultsDeep(config, { |
| 13 | + screens: { |
| 14 | + sm: '576px', |
| 15 | + md: '768px', |
| 16 | + lg: '992px', |
| 17 | + xl: '1200px', |
| 18 | + }, |
| 19 | + options: { |
| 20 | + prefix: '', |
| 21 | + important: false, |
| 22 | + separator: ':', |
| 23 | + }, |
| 24 | + }) |
| 25 | + ) |
| 26 | +} |
| 27 | + |
| 28 | +test('options are not required', () => { |
| 29 | + const [components] = processPluginsWithValidConfig({ |
| 30 | + plugins: [container()], |
| 31 | + }) |
| 32 | + |
| 33 | + expect(css(components)).toMatchCss(` |
| 34 | + .container { width: 100% } |
| 35 | + @media (min-width: 576px) { |
| 36 | + .container { max-width: 576px } |
| 37 | + } |
| 38 | + @media (min-width: 768px) { |
| 39 | + .container { max-width: 768px } |
| 40 | + } |
| 41 | + @media (min-width: 992px) { |
| 42 | + .container { max-width: 992px } |
| 43 | + } |
| 44 | + @media (min-width: 1200px) { |
| 45 | + .container { max-width: 1200px } |
| 46 | + } |
| 47 | + `) |
| 48 | +}) |
| 49 | + |
| 50 | +test('screens can be specified explicitly', () => { |
| 51 | + const [components] = processPluginsWithValidConfig({ |
| 52 | + plugins: [ |
| 53 | + container({ |
| 54 | + screens: { |
| 55 | + sm: '400px', |
| 56 | + lg: '500px', |
| 57 | + }, |
| 58 | + }), |
| 59 | + ], |
| 60 | + }) |
| 61 | + |
| 62 | + expect(css(components)).toMatchCss(` |
| 63 | + .container { width: 100% } |
| 64 | + @media (min-width: 400px) { |
| 65 | + .container { max-width: 400px } |
| 66 | + } |
| 67 | + @media (min-width: 500px) { |
| 68 | + .container { max-width: 500px } |
| 69 | + } |
| 70 | + `) |
| 71 | +}) |
| 72 | + |
| 73 | +test('the container can be centered by default', () => { |
| 74 | + const [components] = processPluginsWithValidConfig({ |
| 75 | + plugins: [ |
| 76 | + container({ |
| 77 | + center: true, |
| 78 | + }), |
| 79 | + ], |
| 80 | + }) |
| 81 | + |
| 82 | + expect(css(components)).toMatchCss(` |
| 83 | + .container { |
| 84 | + width: 100%; |
| 85 | + margin-right: auto; |
| 86 | + margin-left: auto |
| 87 | + } |
| 88 | + @media (min-width: 576px) { |
| 89 | + .container { max-width: 576px } |
| 90 | + } |
| 91 | + @media (min-width: 768px) { |
| 92 | + .container { max-width: 768px } |
| 93 | + } |
| 94 | + @media (min-width: 992px) { |
| 95 | + .container { max-width: 992px } |
| 96 | + } |
| 97 | + @media (min-width: 1200px) { |
| 98 | + .container { max-width: 1200px } |
| 99 | + } |
| 100 | + `) |
| 101 | +}) |
| 102 | + |
| 103 | +test('horizontal padding can be included by default', () => { |
| 104 | + const [components] = processPluginsWithValidConfig({ |
| 105 | + plugins: [ |
| 106 | + container({ |
| 107 | + padding: '2rem', |
| 108 | + }), |
| 109 | + ], |
| 110 | + }) |
| 111 | + |
| 112 | + expect(css(components)).toMatchCss(` |
| 113 | + .container { |
| 114 | + width: 100%; |
| 115 | + padding-right: 2rem; |
| 116 | + padding-left: 2rem |
| 117 | + } |
| 118 | + @media (min-width: 576px) { |
| 119 | + .container { max-width: 576px } |
| 120 | + } |
| 121 | + @media (min-width: 768px) { |
| 122 | + .container { max-width: 768px } |
| 123 | + } |
| 124 | + @media (min-width: 992px) { |
| 125 | + .container { max-width: 992px } |
| 126 | + } |
| 127 | + @media (min-width: 1200px) { |
| 128 | + .container { max-width: 1200px } |
| 129 | + } |
| 130 | + `) |
| 131 | +}) |
| 132 | + |
| 133 | +test('setting all options at once', () => { |
| 134 | + const [components] = processPluginsWithValidConfig({ |
| 135 | + plugins: [ |
| 136 | + container({ |
| 137 | + screens: { |
| 138 | + sm: '400px', |
| 139 | + lg: '500px', |
| 140 | + }, |
| 141 | + center: true, |
| 142 | + padding: '2rem', |
| 143 | + }), |
| 144 | + ], |
| 145 | + }) |
| 146 | + |
| 147 | + expect(css(components)).toMatchCss(` |
| 148 | + .container { |
| 149 | + width: 100%; |
| 150 | + margin-right: auto; |
| 151 | + margin-left: auto; |
| 152 | + padding-right: 2rem; |
| 153 | + padding-left: 2rem |
| 154 | + } |
| 155 | + @media (min-width: 400px) { |
| 156 | + .container { max-width: 400px } |
| 157 | + } |
| 158 | + @media (min-width: 500px) { |
| 159 | + .container { max-width: 500px } |
| 160 | + } |
| 161 | + `) |
| 162 | +}) |
0 commit comments