1
1
var assert = require ( 'chai' ) . assert ,
2
2
doesMQMatch = require ( '../' ) ;
3
3
4
+ describe ( '#doesMQMatch() Type' , function ( ) {
5
+ describe ( 'Type' , function ( ) {
6
+ it ( 'should return true for a correct match' , function ( ) {
7
+ assert . equal ( doesMQMatch ( 'screen and (color)' , { type : 'screen' , color : 1 } ) , true ) ;
8
+ } ) ;
9
+
10
+ it ( 'should return true for when type === all' , function ( ) {
11
+ assert . equal ( doesMQMatch ( 'screen and (min-width: 48em)' , { type : 'all' , width : 1000 } ) , true ) ;
12
+ } ) ;
13
+
14
+ it ( 'should return false for an incorrect match' , function ( ) {
15
+ assert . equal ( doesMQMatch ( 'screen and (min-width: 48em)' , { type : 'handheld' } ) , false ) ;
16
+ } ) ;
17
+
18
+ it ( 'should return true when no type values are passed in' , function ( ) {
19
+ assert . equal ( doesMQMatch ( 'screen and (min-width: 48em)' , { width : 1000 } ) , true ) ;
20
+ } ) ;
21
+ } ) ;
22
+ } ) ;
4
23
5
- describe ( '#doesMQMatch()' , function ( ) {
24
+ describe ( '#doesMQMatch() Media Features ' , function ( ) {
6
25
describe ( 'Width' , function ( ) {
7
26
it ( 'should return true for a width higher than a min-width' , function ( ) {
8
27
assert . equal ( doesMQMatch ( '(min-width: 48em)' , { width : '80em' } ) , true ) ;
@@ -12,8 +31,8 @@ describe('#doesMQMatch()', function(){
12
31
assert . equal ( doesMQMatch ( '(min-width: 48em)' , { width : '20em' } ) , false ) ;
13
32
} ) ;
14
33
15
- it ( 'should return true when no width values are passed in' , function ( ) {
16
- assert . equal ( doesMQMatch ( '(min-width: 48em)' , { resolution : 72 } ) , true ) ;
34
+ it ( 'should return false when no width values are passed in' , function ( ) {
35
+ assert . equal ( doesMQMatch ( '(min-width: 48em)' , { resolution : 72 } ) , false ) ;
17
36
} ) ;
18
37
19
38
it ( 'should return true with multiple properties' , function ( ) {
@@ -34,8 +53,8 @@ describe('#doesMQMatch()', function(){
34
53
assert . equal ( doesMQMatch ( '(min-height: 48em)' , { height : '20em' } ) , false ) ;
35
54
} ) ;
36
55
37
- it ( 'should return true when no height values are passed in' , function ( ) {
38
- assert . equal ( doesMQMatch ( '(min-height: 48em)' , { resolution : 72 } ) , true ) ;
56
+ it ( 'should return false when no height values are passed in' , function ( ) {
57
+ assert . equal ( doesMQMatch ( '(min-height: 48em)' , { resolution : 72 } ) , false ) ;
39
58
} ) ;
40
59
41
60
it ( 'should return true with multiple properties' , function ( ) {
@@ -57,8 +76,8 @@ describe('#doesMQMatch()', function(){
57
76
assert . equal ( doesMQMatch ( '(min-device-width: 48em)' , { 'device-width' : '20em' } ) , false ) ;
58
77
} ) ;
59
78
60
- it ( 'should return true when no device-width values are passed in' , function ( ) {
61
- assert . equal ( doesMQMatch ( '(min-device-width: 48em)' , { resolution : 72 } ) , true ) ;
79
+ it ( 'should return false when no device-width values are passed in' , function ( ) {
80
+ assert . equal ( doesMQMatch ( '(min-device-width: 48em)' , { resolution : 72 } ) , false ) ;
62
81
} ) ;
63
82
64
83
it ( 'should return true with multiple properties' , function ( ) {
@@ -79,8 +98,8 @@ describe('#doesMQMatch()', function(){
79
98
assert . equal ( doesMQMatch ( '(min-device-height: 48em)' , { 'device-height' : '20em' } ) , false ) ;
80
99
} ) ;
81
100
82
- it ( 'should return true when no device-height values are passed in' , function ( ) {
83
- assert . equal ( doesMQMatch ( '(min-device-height: 48em)' , { resolution : 72 } ) , true ) ;
101
+ it ( 'should return false when no device-height values are passed in' , function ( ) {
102
+ assert . equal ( doesMQMatch ( '(min-device-height: 48em)' , { resolution : 72 } ) , false ) ;
84
103
} ) ;
85
104
86
105
it ( 'should return true with multiple properties' , function ( ) {
@@ -103,8 +122,8 @@ describe('#doesMQMatch()', function(){
103
122
assert . equal ( doesMQMatch ( '(max-color: 2)' , { color : 4 } ) , false ) ;
104
123
} ) ;
105
124
106
- it ( 'should return true if color isnt passed in' , function ( ) {
107
- assert . equal ( doesMQMatch ( 'max-width: 767px and (color)' , { width : 300 } ) , true ) ;
125
+ it ( 'should return false if color isnt passed in' , function ( ) {
126
+ assert . equal ( doesMQMatch ( 'max-width: 767px and (color)' , { width : 300 } ) , false ) ;
108
127
} ) ;
109
128
110
129
it ( 'should work for undefined color values' , function ( ) {
@@ -122,8 +141,8 @@ describe('#doesMQMatch()', function(){
122
141
assert . equal ( doesMQMatch ( '(max-color-index: 256)' , { 'color-index' : 512 } ) , false ) ;
123
142
} ) ;
124
143
125
- it ( 'should return true if color-index isnt passed in' , function ( ) {
126
- assert . equal ( doesMQMatch ( 'max-width: 767px and (color-index)' , { width : 300 } ) , true ) ;
144
+ it ( 'should return false if color-index isnt passed in' , function ( ) {
145
+ assert . equal ( doesMQMatch ( 'max-width: 767px and (color-index)' , { width : 300 } ) , false ) ;
127
146
} ) ;
128
147
129
148
it ( 'should work for undefined color-index values' , function ( ) {
@@ -142,8 +161,8 @@ describe('#doesMQMatch()', function(){
142
161
assert . equal ( doesMQMatch ( '(max-monochrome: 3)' , { monochrome : 4 } ) , false ) ;
143
162
} ) ;
144
163
145
- it ( 'should return true if monochrome isnt passed in' , function ( ) {
146
- assert . equal ( doesMQMatch ( 'max-width: 767px and (monochrome)' , { width : 300 } ) , true ) ;
164
+ it ( 'should return false if monochrome isnt passed in' , function ( ) {
165
+ assert . equal ( doesMQMatch ( 'max-width: 767px and (monochrome)' , { width : 300 } ) , false ) ;
147
166
} ) ;
148
167
149
168
it ( 'should work for undefined monochrome values' , function ( ) {
@@ -162,8 +181,8 @@ describe('#doesMQMatch()', function(){
162
181
assert . equal ( doesMQMatch ( '(max-resolution: 72dpi)' , { resolution : 300 } ) , false ) ;
163
182
} ) ;
164
183
165
- it ( 'should return true if resolution isnt passed in' , function ( ) {
166
- assert . equal ( doesMQMatch ( '(max-resolution: 72dpi)' , { width : 300 } ) , true ) ;
184
+ it ( 'should return false if resolution isnt passed in' , function ( ) {
185
+ assert . equal ( doesMQMatch ( '(max-resolution: 72dpi)' , { width : 300 } ) , false ) ;
167
186
} ) ;
168
187
169
188
it ( 'should convert units properly' , function ( ) {
@@ -180,8 +199,8 @@ describe('#doesMQMatch()', function(){
180
199
assert . equal ( doesMQMatch ( '(max-aspect-ratio: 4/3)' , { 'aspect-ratio' : '16/9' } ) , false ) ;
181
200
} ) ;
182
201
183
- it ( 'should return true if aspect-ratio isnt passed in' , function ( ) {
184
- assert . equal ( doesMQMatch ( '(max-aspect-ratio: 72dpi)' , { width : 300 } ) , true ) ;
202
+ it ( 'should return false if aspect-ratio isnt passed in' , function ( ) {
203
+ assert . equal ( doesMQMatch ( '(max-aspect-ratio: 72dpi)' , { width : 300 } ) , false ) ;
185
204
} ) ;
186
205
187
206
it ( 'should work with strings and numbers' , function ( ) {
@@ -208,8 +227,8 @@ describe('#doesMQMatch()', function(){
208
227
assert . equal ( doesMQMatch ( 'screen and (orientation: landscape)' , { orientation : 'portrait' } ) , false ) ;
209
228
} ) ;
210
229
211
- it ( 'should return true if orientation isnt passed in' , function ( ) {
212
- assert . equal ( doesMQMatch ( 'screen and (orientation: landscape)' , { width : '50em' } ) , true ) ;
230
+ it ( 'should return false if orientation isnt passed in' , function ( ) {
231
+ assert . equal ( doesMQMatch ( 'screen and (orientation: landscape)' , { width : '50em' } ) , false ) ;
213
232
} ) ;
214
233
} ) ;
215
234
@@ -218,12 +237,57 @@ describe('#doesMQMatch()', function(){
218
237
assert . equal ( doesMQMatch ( 'handheld and (grid)' , { grid : true } ) , true ) ;
219
238
} ) ;
220
239
221
- it ( 'should return true if grid isnt passed in' , function ( ) {
222
- assert . equal ( doesMQMatch ( 'tv and (grid)' , { scan : 'interlace' } ) , true ) ;
240
+ it ( 'should return false if grid isnt passed in' , function ( ) {
241
+ assert . equal ( doesMQMatch ( 'tv and (grid)' , { scan : 'interlace' } ) , false ) ;
223
242
} ) ;
224
243
225
244
it ( 'should return false if grid is explictly set to false' , function ( ) {
226
245
assert . equal ( doesMQMatch ( 'tv and (grid)' , { scan : 'interlace' , grid : false } ) , false ) ;
227
246
} ) ;
228
247
} ) ;
229
248
} ) ;
249
+
250
+ describe ( '#doesMQMatch() Integration Tests' , function ( ) {
251
+ describe ( 'Real World Use Cases' , function ( ) {
252
+ it ( 'should return true because of width and type match' , function ( ) {
253
+ assert . equal ( doesMQMatch ( 'screen and (min-width: 767px)' , { type : 'screen' , width : 980 } ) , true ) ;
254
+ } ) ;
255
+
256
+ it ( 'should return true because of width is within bounds' , function ( ) {
257
+ assert . equal ( doesMQMatch ( 'screen and (min-width: 767px) and (max-width: 979px)' , { type : 'screen' , width : 800 } ) , true ) ;
258
+ } ) ;
259
+
260
+ it ( 'should return false because width is out of bounds' , function ( ) {
261
+ assert . equal ( doesMQMatch ( 'screen and (min-width: 767px) and (max-width: 979px)' , { type : 'screen' , width : 980 } ) , false ) ;
262
+ } ) ;
263
+
264
+ it ( 'should return false since monochrome is not specified' , function ( ) {
265
+ assert . equal ( doesMQMatch ( 'screen and (monochrome)' , { width : 980 } ) , false ) ;
266
+ } ) ;
267
+
268
+ it ( 'should return true since color > 0' , function ( ) {
269
+ assert . equal ( doesMQMatch ( 'screen and (color)' , { type : 'all' , color : 1 } ) , true ) ;
270
+ } ) ;
271
+
272
+ it ( 'should return false since color = 0' , function ( ) {
273
+ assert . equal ( doesMQMatch ( 'screen and (color)' , { type : 'all' , color : 0 } ) , false ) ;
274
+ } ) ;
275
+
276
+ } ) ;
277
+
278
+ describe ( 'Grouped Media Queries' , function ( ) {
279
+ it ( 'should return true because of color' , function ( ) {
280
+ assert . equal ( doesMQMatch ( 'screen and (min-width: 767px), screen and (color)' , { type : 'screen' , color : 1 } ) , true ) ;
281
+ } ) ;
282
+
283
+ it ( 'should return true because of width and type' , function ( ) {
284
+ assert . equal ( doesMQMatch ( 'screen and (max-width: 1200px), handheld and (monochrome)' , { type : 'screen' , width : 1100 } ) , true ) ;
285
+ } ) ;
286
+
287
+ it ( 'should return false because of monochrome mis-match' , function ( ) {
288
+ assert . equal ( doesMQMatch ( 'screen and (max-width: 1200px), handheld and (monochrome)' , { type : 'screen' , monochrome : 0 } ) , false ) ;
289
+ } ) ;
290
+
291
+ } ) ;
292
+ } ) ;
293
+
0 commit comments