1 | import {
|
2 | mqWithValidBreakpointsForRange,
|
3 | booleanValues,
|
4 | genericNumbers,
|
5 | } from './data';
|
6 | import cssSerialiser from './helpers/cssSerialiser';
|
7 |
|
8 | expect.addSnapshotSerializer(cssSerialiser);
|
9 |
|
10 | describe('query', () => {
|
11 | it('throws with no arguments', () => {
|
12 | const mq = mqWithValidBreakpointsForRange('width');
|
13 | const { query } = mq;
|
14 | expect(
|
15 | () =>
|
16 | query()`
|
17 | background-color: ${() => 'GhostWhite'};
|
18 | `
|
19 | ).toThrowErrorMatchingSnapshot();
|
20 | });
|
21 |
|
22 | const invalidValues = [
|
23 | ...booleanValues,
|
24 | ...genericNumbers,
|
25 | null,
|
26 | undefined,
|
27 | NaN,
|
28 | {},
|
29 | ];
|
30 | for (const value of invalidValues) {
|
31 | it(`throws with invalid argument ${value}`, () => {
|
32 | const mq = mqWithValidBreakpointsForRange('width');
|
33 | const { query } = mq;
|
34 | expect(
|
35 | () =>
|
36 | query(value)`
|
37 | background-color: ${() => 'GhostWhite'};
|
38 | `
|
39 | ).toThrowErrorMatchingSnapshot();
|
40 | });
|
41 | }
|
42 |
|
43 | it('renders query with single feature', () => {
|
44 |
|
45 | const mq = mqWithValidBreakpointsForRange('width');
|
46 | const { query, minWidth } = mq;
|
47 | expect(
|
48 | query(minWidth('small'))`
|
49 | background-color: ${() => 'GhostWhite'};
|
50 | `
|
51 | ).toMatchSnapshot();
|
52 | });
|
53 |
|
54 | describe('and', () => {
|
55 |
|
56 | it('renders query with two features anded together', () => {
|
57 | const mq = mqWithValidBreakpointsForRange('width');
|
58 | const { query, minWidth, orientation } = mq;
|
59 | expect(
|
60 | query([minWidth('small'), orientation('landscape')])`
|
61 | background-color: ${() => 'GhostWhite'};
|
62 | `
|
63 | ).toMatchSnapshot();
|
64 | });
|
65 |
|
66 | it('renders query with multiple features anded together', () => {
|
67 |
|
68 | const mq = mqWithValidBreakpointsForRange('width');
|
69 | const { query, colorGamut, grid, minWidth, orientation } = mq;
|
70 | expect(
|
71 | query([
|
72 | colorGamut('srgb'),
|
73 | minWidth('small'),
|
74 | orientation('landscape'),
|
75 | grid(),
|
76 | ])`
|
77 | background-color: ${() => 'GhostWhite'};
|
78 | `
|
79 | ).toMatchSnapshot();
|
80 | });
|
81 | });
|
82 |
|
83 | describe('or', () => {
|
84 | it('renders query with two features ored together', () => {
|
85 |
|
86 | const mq = mqWithValidBreakpointsForRange('width');
|
87 | const { query, minWidth, orientation } = mq;
|
88 | expect(
|
89 | query(minWidth('small'), orientation('landscape'))`
|
90 | background-color: ${() => 'GhostWhite'};
|
91 | `
|
92 | ).toMatchSnapshot();
|
93 | });
|
94 |
|
95 | it('renders query with multiple features ored together', () => {
|
96 |
|
97 | const mq = mqWithValidBreakpointsForRange('width');
|
98 | const { query, minWidth, orientation, colorGamut, grid } = mq;
|
99 | expect(
|
100 | query(
|
101 | colorGamut('srgb'),
|
102 | minWidth('small'),
|
103 | orientation('landscape'),
|
104 | grid()
|
105 | )`
|
106 | background-color: ${() => 'GhostWhite'};
|
107 | `
|
108 | ).toMatchSnapshot();
|
109 | });
|
110 | });
|
111 |
|
112 | describe('not', () => {
|
113 | it('negates anded queries', () => {
|
114 |
|
115 | const mq = mqWithValidBreakpointsForRange('width');
|
116 | const { displayMode, query, not, colorGamut, orientation } = mq;
|
117 | expect(
|
118 | query(
|
119 | not([
|
120 | displayMode('fullscreen'),
|
121 | colorGamut('p3'),
|
122 | orientation('landscape'),
|
123 | ])
|
124 | )`
|
125 | background-color: ${() => 'GhostWhite'};
|
126 | `
|
127 | ).toMatchSnapshot();
|
128 | });
|
129 |
|
130 | it('negates ored queries', () => {
|
131 |
|
132 | const mq = mqWithValidBreakpointsForRange('width');
|
133 | const { displayMode, query, not, colorGamut, orientation } = mq;
|
134 | expect(
|
135 | query(
|
136 | not(
|
137 | displayMode('fullscreen'),
|
138 | colorGamut('p3'),
|
139 | orientation('landscape')
|
140 | )
|
141 | )`
|
142 | background-color: ${() => 'GhostWhite'};
|
143 | `
|
144 | ).toMatchSnapshot();
|
145 | });
|
146 |
|
147 | describe('with media type', () => {
|
148 | it('renders single uquery with media type without adding default media type', () => {
|
149 |
|
150 | const mq = mqWithValidBreakpointsForRange('width');
|
151 | const { query, not, displayMode, mediaType } = mq;
|
152 | expect(
|
153 | query(not(mediaType(), displayMode('fullscreen')))`
|
154 | background-color: ${() => 'GhostWhite'};
|
155 | `
|
156 | ).toMatchSnapshot();
|
157 | });
|
158 |
|
159 | it('negates anded queries without adding default media type', () => {
|
160 |
|
161 | const mq = mqWithValidBreakpointsForRange('width');
|
162 | const {
|
163 | mediaType,
|
164 | displayMode,
|
165 | query,
|
166 | not,
|
167 | colorGamut,
|
168 | orientation,
|
169 | } = mq;
|
170 | expect(
|
171 | query(
|
172 | not([
|
173 | mediaType(),
|
174 | displayMode('fullscreen'),
|
175 | colorGamut('p3'),
|
176 | orientation('landscape'),
|
177 | ])
|
178 | )`
|
179 | background-color: ${() => 'GhostWhite'};
|
180 | `
|
181 | ).toMatchSnapshot();
|
182 | });
|
183 |
|
184 | it('negates ored queries without adding default media type', () => {
|
185 |
|
186 | const mq = mqWithValidBreakpointsForRange('width');
|
187 | const {
|
188 | mediaType,
|
189 | displayMode,
|
190 | query,
|
191 | not,
|
192 | colorGamut,
|
193 | orientation,
|
194 | } = mq;
|
195 | expect(
|
196 | query(
|
197 | not(
|
198 | mediaType(),
|
199 | displayMode('fullscreen'),
|
200 | colorGamut('p3'),
|
201 | orientation('landscape')
|
202 | )
|
203 | )`
|
204 | background-color: ${() => 'GhostWhite'};
|
205 | `
|
206 | ).toMatchSnapshot();
|
207 | });
|
208 | });
|
209 | });
|
210 |
|
211 | describe('mixed', () => {
|
212 | it('allows mixed queries (both and and or)', () => {
|
213 |
|
214 | const mq = mqWithValidBreakpointsForRange('width');
|
215 | const { displayMode, query, colorGamut, orientation } = mq;
|
216 | expect(
|
217 | query(displayMode('fullscreen'), colorGamut('rec2020'), [
|
218 | displayMode('standalone'),
|
219 | orientation('landscape'),
|
220 | ])`
|
221 | background-color: ${() => 'GhostWhite'};
|
222 | `
|
223 | ).toMatchSnapshot();
|
224 | });
|
225 |
|
226 | it('allows mixed not queries (both and and or)', () => {
|
227 |
|
228 | const mq = mqWithValidBreakpointsForRange('width');
|
229 | const { displayMode, query, not, colorGamut, orientation, grid } = mq;
|
230 | expect(
|
231 | query(
|
232 | not(displayMode('fullscreen'), colorGamut('rec2020'), [
|
233 | grid(0),
|
234 | orientation('landscape'),
|
235 | ])
|
236 | )`
|
237 | background-color: ${() => 'GhostWhite'};
|
238 | `
|
239 | ).toMatchSnapshot();
|
240 | });
|
241 |
|
242 | it('allows mixed queries and not queries (both and and or)', () => {
|
243 |
|
244 | const mq = mqWithValidBreakpointsForRange('width');
|
245 | const { grid, atWidth, query, not, colorGamut, orientation } = mq;
|
246 | expect(
|
247 | query(
|
248 | grid(),
|
249 | colorGamut('rec2020'),
|
250 | [grid(1), orientation('landscape')],
|
251 | not(grid(), [atWidth('large'), orientation('portrait')])
|
252 | )`
|
253 | background-color: ${() => 'GhostWhite'};
|
254 | `
|
255 | ).toMatchSnapshot();
|
256 | });
|
257 | });
|
258 | });
|