source: frontend/node_modules/postcss-clamp/index.test.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 6.3 KB
Line 
1let postcss = require('postcss')
2
3let clamp = require('./')
4
5async function run (input, output, opts) {
6 let result = await postcss([clamp(opts)]).process(input, {
7 from: '/test.css'
8 })
9 expect(result.css).toEqual(output)
10 expect(result.warnings()).toHaveLength(0)
11 return result
12}
13
14it('handle simple transformation (only values)', async () => {
15 await run(
16 'a{ width: clamp(10px, 64px, 80px); }',
17 'a{ width: max(10px, min(64px, 80px)); }'
18 )
19})
20
21it('handle simple transformation (only values) with preserve', async () => {
22 await run(
23 'a{ width: clamp(10px, 64px, 80px); }',
24 'a{ width: max(10px, min(64px, 80px)); width: clamp(10px, 64px, 80px); }',
25 { preserve: true }
26 )
27})
28
29it('handle transformation with functions', async () => {
30 await run(
31 'a{ width: clamp(calc(100% - 10px), min(10px, 100%), max(40px, 4em)); }',
32 'a{ width: max(calc(100% - 10px), min(min(10px, 100%), max(40px, 4em))); }'
33 )
34})
35
36it('handle transformation with functions with preserve', async () => {
37 await run(
38 'a{ width: clamp(calc(100% - 10px), min(10px, 100%), max(40px, 4em)); }',
39 'a{ width: max(calc(100% - 10px), min(min(10px, 100%), max(40px, 4em))); ' +
40 'width: clamp(calc(100% - 10px), min(10px, 100%), max(40px, 4em)); }',
41 { preserve: true }
42 )
43})
44
45it('handle transformation with different units', async () => {
46 await run(
47 'a{ width: clamp(10%, 2px, 4rem); }',
48 'a{ width: max(10%, min(2px, 4rem)); }'
49 )
50})
51
52it('handle transformation with different units and preserve', async () => {
53 await run(
54 'a{ width: clamp(10%, 2px, 4rem); }',
55 'a{ width: max(10%, min(2px, 4rem)); width: clamp(10%, 2px, 4rem); }',
56 { preserve: true }
57 )
58})
59
60it('transform only function with 3 parameters', async () => {
61 await run(
62 'a{ width: clamp(10%, 2px, 4rem);' +
63 '\nheight: clamp(10px, 20px, 30px, 40px); }',
64 'a{ width: max(10%, min(2px, 4rem));' +
65 '\nheight: clamp(10px, 20px, 30px, 40px); }'
66 )
67})
68
69it('transform only clamp function', async () => {
70 await run(
71 'a{ width: clamp(10%, 2px, 4rem);\nheight: calc(10px + 100%); }',
72 'a{ width: max(10%, min(2px, 4rem));\nheight: calc(10px + 100%); }'
73 )
74})
75
76it('precalculate second and third with the same unit (int values)', async () => {
77 await run('a{ width: clamp(10%, 2px, 5px); }', 'a{ width: max(10%, 7px); }', {
78 precalculate: true
79 })
80})
81
82it('precalculate second and third with the same unit (float values)', async () => {
83 await run(
84 'a{ width: clamp(10%, 2.5px, 5.1px); }',
85 'a{ width: max(10%, 7.6px); }',
86 { precalculate: true }
87 )
88})
89
90it('precalculate second and third with the same unit (float and int values)', async () => {
91 await run(
92 'a{ width: clamp(10%, 2.5px, 5px); }',
93 'a{ width: max(10%, 7.5px); }',
94 { precalculate: true }
95 )
96})
97
98it('precalculate 2nd & 3rd with the same unit (float and int vals) & preserve', async () => {
99 await run(
100 'a{ width: clamp(10%, 2.5px, 5px); }',
101 'a{ width: max(10%, 7.5px); width: clamp(10%, 2.5px, 5px); }',
102 { precalculate: true, preserve: true }
103 )
104})
105
106it('precalculate all values with the same unit (int values)', async () => {
107 await run('a{ width: clamp(10px, 2px, 5px); }', 'a{ width: 17px; }', {
108 precalculate: true
109 })
110})
111
112it('precalculate all values with the same unit (float values)', async () => {
113 await run(
114 'a{ width: clamp(10.4px, 2.11px, 5.9px); }',
115 'a{ width: 18.41px; }',
116 { precalculate: true }
117 )
118})
119
120it('precalculate all values with the same unit (int and float values)', async () => {
121 await run('a{ width: clamp(10.4px, 2px, 5.9px); }', 'a{ width: 18.3px; }', {
122 precalculate: true
123 })
124})
125
126it('handle function with enable precalculation as third', async () => {
127 await run(
128 'a{ width: clamp(10px, 2px, calc(10px + 100%)); }',
129 'a{ width: max(10px, min(2px, calc(10px + 100%))); }',
130 { precalculate: true }
131 )
132})
133
134it('handle function with enable precalculation as second', async () => {
135 await run(
136 'a{ width: clamp(10px, calc(10px + 100%), 2px); }',
137 'a{ width: max(10px, min(calc(10px + 100%), 2px)); }',
138 { precalculate: true }
139 )
140})
141
142it('handle function with enable precalculation as first', async () => {
143 await run(
144 'a{ width: clamp(calc(10px + 100%), 10px, 2px); }',
145 'a{ width: max(calc(10px + 100%), 12px); }',
146 { precalculate: true }
147 )
148})
149
150it('handle function with enable precalculation as all', async () => {
151 await run(
152 'a{ width: clamp(calc(10px + 100%), calc(10rem + 200%), 10px); }',
153 'a{ width: max(calc(10px + 100%), min(calc(10rem + 200%), 10px)); }',
154 { precalculate: true }
155 )
156})
157
158it('handle not valid values', async () => {
159 await run('a{ width: clamp(a, b, c); }', 'a{ width: max(a, min(b, c)); }', {
160 precalculate: true
161 })
162})
163
164it('handle not valid values with preserve', async () => {
165 await run(
166 'a{ width: clamp(a, b, c); }',
167 'a{ width: max(a, min(b, c)); width: clamp(a, b, c); }',
168 { precalculate: true, preserve: true }
169 )
170})
171
172it('handle not valid values mixed with valid', async () => {
173 await run(
174 'a{ width: clamp(a, 1px, 2em); }',
175 'a{ width: max(a, min(1px, 2em)); }',
176 { precalculate: true }
177 )
178})
179
180it('handle not valid values mixed with valid and preserve', async () => {
181 await run(
182 'a{ width: clamp(a, 1px, 2em); }',
183 'a{ width: max(a, min(1px, 2em)); width: clamp(a, 1px, 2em); }',
184 { precalculate: true, preserve: true }
185 )
186})
187
188it('handle complex values', async () => {
189 await run(
190 'a{ grid-template-columns: clamp(22rem, 40%, 32rem) minmax(0, 1fr); }',
191 'a{ grid-template-columns: max(22rem, min(40%, 32rem)) minmax(0, 1fr); }'
192 )
193})
194
195it('handle multiple complex values', async () => {
196 await run(
197 'a{ margin: clamp(1rem, 2%, 3rem) 4px clamp(5rem, 6%, 7rem) 8rem; }',
198 'a{ margin: max(1rem, min(2%, 3rem)) 4px max(5rem, min(6%, 7rem)) 8rem; }'
199 )
200})
201
202it('handle calc', async () => {
203 await run(
204 'a{ margin: 0 40px 0 calc(-1 * clamp(32px, 16vw, 64px)); }',
205 'a{ margin: 0 40px 0 calc(-1 * max(32px, min(16vw, 64px))); }'
206 )
207})
208
209it('handle multiple calc', async () => {
210 await run(
211 'a{ margin: calc(-1 * clamp(1px, 2vw, 3px)) calc(-1 * clamp(4px, 5vw, 6px)); }',
212 'a{ margin: calc(-1 * max(1px, min(2vw, 3px))) calc(-1 * max(4px, min(5vw, 6px))); }'
213 )
214})
215
216it('handle nested clamp', async () => {
217 await run(
218 'a{ font-size: clamp(clamp(1rem, 2vw, 3rem), 4vw, 5rem); }',
219 'a{ font-size: max(max(1rem, min(2vw, 3rem)), min(4vw, 5rem)); }'
220 )
221})
Note: See TracBrowser for help on using the repository browser.