|
| 1 | +'use strict' |
| 2 | + |
| 3 | +/** |
| 4 | + * @module |
| 5 | + */ |
| 6 | + |
| 7 | +// ---------------------------------------- |
| 8 | +// Imports |
| 9 | +// ---------------------------------------- |
| 10 | + |
| 11 | +const sortCSSmq = require('../index') |
| 12 | +// const randomize = require('./randomize') |
| 13 | + |
| 14 | +// ---------------------------------------- |
| 15 | +// Tests |
| 16 | +// ---------------------------------------- |
| 17 | + |
| 18 | +it(`simple #1. mobile-first`, () => { |
| 19 | + const receivedOrder = [ |
| 20 | + 'screen and (max-width: 640px)', |
| 21 | + 'screen and (min-width: 980px)', |
| 22 | + 'screen and (max-width: 980px)', |
| 23 | + 'screen and (max-width: 768px)', |
| 24 | + 'screen and (min-width: 640px)', |
| 25 | + 'screen and (min-width: 1280px)', |
| 26 | + 'screen and (min-width: 768px)', |
| 27 | + 'screen and (max-width: 1280px)' |
| 28 | + ] |
| 29 | + |
| 30 | + const expectedOrder = [ |
| 31 | + 'screen and (min-width: 640px)', |
| 32 | + 'screen and (min-width: 768px)', |
| 33 | + 'screen and (min-width: 980px)', |
| 34 | + 'screen and (min-width: 1280px)', |
| 35 | + 'screen and (max-width: 1280px)', |
| 36 | + 'screen and (max-width: 980px)', |
| 37 | + 'screen and (max-width: 768px)', |
| 38 | + 'screen and (max-width: 640px)' |
| 39 | + ] |
| 40 | + |
| 41 | + const expected = expectedOrder.join('\n') |
| 42 | + const received = receivedOrder.sort(sortCSSmq).join('\n') |
| 43 | + |
| 44 | + expect(received).toBe(expected) |
| 45 | +}) |
| 46 | + |
| 47 | +it(`simple #1. desktop-first`, () => { |
| 48 | + const receivedOrder = [ |
| 49 | + 'screen and (max-width: 640px)', |
| 50 | + 'screen and (min-width: 980px)', |
| 51 | + 'screen and (max-width: 980px)', |
| 52 | + 'screen and (max-width: 768px)', |
| 53 | + 'screen and (min-width: 640px)', |
| 54 | + 'screen and (min-width: 1280px)', |
| 55 | + 'screen and (min-width: 768px)', |
| 56 | + 'screen and (max-width: 1280px)' |
| 57 | + ] |
| 58 | + |
| 59 | + const expectedOrder = [ |
| 60 | + 'screen and (max-width: 1280px)', |
| 61 | + 'screen and (max-width: 980px)', |
| 62 | + 'screen and (max-width: 768px)', |
| 63 | + 'screen and (max-width: 640px)', |
| 64 | + 'screen and (min-width: 640px)', |
| 65 | + 'screen and (min-width: 768px)', |
| 66 | + 'screen and (min-width: 980px)', |
| 67 | + 'screen and (min-width: 1280px)' |
| 68 | + ] |
| 69 | + |
| 70 | + const expected = expectedOrder.join('\n') |
| 71 | + const received = receivedOrder.sort(sortCSSmq.desktopFirst).join('\n') |
| 72 | + |
| 73 | + expect(received).toBe(expected) |
| 74 | +}) |
| 75 | + |
| 76 | +it(`simple #2. mobile-first`, () => { |
| 77 | + const receivedOrder = [ |
| 78 | + 'screen and (max-width: 640px)', |
| 79 | + 'screen and (max-width: 640px)', |
| 80 | + 'screen and (min-width: 1280px)', |
| 81 | + 'screen and (max-width: 640px)' |
| 82 | + ] |
| 83 | + |
| 84 | + const expectedOrder = [ |
| 85 | + 'screen and (min-width: 1280px)', |
| 86 | + 'screen and (max-width: 640px)', |
| 87 | + 'screen and (max-width: 640px)', |
| 88 | + 'screen and (max-width: 640px)' |
| 89 | + ] |
| 90 | + |
| 91 | + const expected = expectedOrder.join('\n') |
| 92 | + const received = receivedOrder.sort(sortCSSmq).join('\n') |
| 93 | + |
| 94 | + expect(received).toBe(expected) |
| 95 | +}) |
| 96 | + |
| 97 | +it(`simple #2. desktop-first`, () => { |
| 98 | + const receivedOrder = [ |
| 99 | + 'screen and (max-width: 640px)', |
| 100 | + 'screen and (max-width: 640px)', |
| 101 | + 'screen and (min-width: 1280px)', |
| 102 | + 'screen and (max-width: 640px)' |
| 103 | + ] |
| 104 | + |
| 105 | + const expectedOrder = [ |
| 106 | + 'screen and (max-width: 640px)', |
| 107 | + 'screen and (max-width: 640px)', |
| 108 | + 'screen and (max-width: 640px)', |
| 109 | + 'screen and (min-width: 1280px)' |
| 110 | + ] |
| 111 | + |
| 112 | + const expected = expectedOrder.join('\n') |
| 113 | + const received = receivedOrder.sort(sortCSSmq.desktopFirst).join('\n') |
| 114 | + |
| 115 | + expect(received).toBe(expected) |
| 116 | +}) |
| 117 | + |
| 118 | +it(`without dimension #1. mobile-first`, () => { |
| 119 | + const receivedOrder = [ |
| 120 | + 'tv', |
| 121 | + 'print and (orientation: landscape)', |
| 122 | + 'print and (orientation: portrait)', |
| 123 | + 'print and (orientation: portrait)', |
| 124 | + 'screen and (orientation: landscape)', |
| 125 | + 'print', |
| 126 | + 'screen and (orientation: portrait)', |
| 127 | + 'print and (orientation: landscape)', |
| 128 | + 'print and (orientation: portrait)' |
| 129 | + ] |
| 130 | + |
| 131 | + const expectedOrder = [ |
| 132 | + 'screen and (orientation: landscape)', |
| 133 | + 'screen and (orientation: portrait)', |
| 134 | + 'tv', |
| 135 | + 'print', |
| 136 | + 'print and (orientation: landscape)', |
| 137 | + 'print and (orientation: landscape)', |
| 138 | + 'print and (orientation: portrait)', |
| 139 | + 'print and (orientation: portrait)', |
| 140 | + 'print and (orientation: portrait)' |
| 141 | + ] |
| 142 | + |
| 143 | + const expected = expectedOrder.join('\n') |
| 144 | + const received = receivedOrder.sort(sortCSSmq).join('\n') |
| 145 | + |
| 146 | + expect(received).toBe(expected) |
| 147 | +}) |
| 148 | + |
| 149 | +it(`without dimension #1. desktop-first`, () => { |
| 150 | + const receivedOrder = [ |
| 151 | + 'tv', |
| 152 | + 'print and (orientation: landscape)', |
| 153 | + 'print and (orientation: portrait)', |
| 154 | + 'print and (orientation: portrait)', |
| 155 | + 'screen and (orientation: landscape)', |
| 156 | + 'print', |
| 157 | + 'screen and (orientation: portrait)', |
| 158 | + 'print and (orientation: landscape)', |
| 159 | + 'print and (orientation: portrait)' |
| 160 | + ] |
| 161 | + |
| 162 | + const expectedOrder = [ |
| 163 | + 'screen and (orientation: landscape)', |
| 164 | + 'screen and (orientation: portrait)', |
| 165 | + 'tv', |
| 166 | + 'print', |
| 167 | + 'print and (orientation: landscape)', |
| 168 | + 'print and (orientation: landscape)', |
| 169 | + 'print and (orientation: portrait)', |
| 170 | + 'print and (orientation: portrait)', |
| 171 | + 'print and (orientation: portrait)' |
| 172 | + ] |
| 173 | + |
| 174 | + const expected = expectedOrder.join('\n') |
| 175 | + const received = receivedOrder.sort(sortCSSmq.desktopFirst).join('\n') |
| 176 | + |
| 177 | + expect(received).toBe(expected) |
| 178 | +}) |
| 179 | + |
| 180 | +it(`mixed #1. mobile-first`, () => { |
| 181 | + const receivedOrder = [ |
| 182 | + 'tv', |
| 183 | + 'print and (orientation: landscape)', |
| 184 | + 'screen and (min-width: 1280px)', |
| 185 | + 'screen and (max-width: 640px)', |
| 186 | + 'screen and (orientation: landscape)', |
| 187 | + 'print', |
| 188 | + 'screen and (orientation: portrait)', |
| 189 | + 'screen and (min-width: 768px)', |
| 190 | + 'screen and (max-width: 1280px)', |
| 191 | + 'print and (orientation: portrait)' |
| 192 | + ] |
| 193 | + |
| 194 | + const expectedOrder = [ |
| 195 | + 'screen and (min-width: 768px)', |
| 196 | + 'screen and (min-width: 1280px)', |
| 197 | + 'screen and (max-width: 1280px)', |
| 198 | + 'screen and (max-width: 640px)', |
| 199 | + 'screen and (orientation: landscape)', |
| 200 | + 'screen and (orientation: portrait)', |
| 201 | + 'tv', |
| 202 | + 'print', |
| 203 | + 'print and (orientation: landscape)', |
| 204 | + 'print and (orientation: portrait)' |
| 205 | + ] |
| 206 | + |
| 207 | + const expected = expectedOrder.join('\n') |
| 208 | + const received = receivedOrder.sort(sortCSSmq).join('\n') |
| 209 | + |
| 210 | + expect(received).toBe(expected) |
| 211 | +}) |
| 212 | + |
| 213 | +it(`mixed #1. desktop-first`, () => { |
| 214 | + const receivedOrder = [ |
| 215 | + 'tv', |
| 216 | + 'print and (orientation: landscape)', |
| 217 | + 'screen and (min-width: 1280px)', |
| 218 | + 'screen and (max-width: 640px)', |
| 219 | + 'screen and (orientation: landscape)', |
| 220 | + 'print', |
| 221 | + 'screen and (orientation: portrait)', |
| 222 | + 'screen and (min-width: 768px)', |
| 223 | + 'screen and (max-width: 1280px)', |
| 224 | + 'print and (orientation: portrait)' |
| 225 | + ] |
| 226 | + |
| 227 | + const expectedOrder = [ |
| 228 | + 'screen and (max-width: 1280px)', |
| 229 | + 'screen and (max-width: 640px)', |
| 230 | + 'screen and (min-width: 768px)', |
| 231 | + 'screen and (min-width: 1280px)', |
| 232 | + 'screen and (orientation: landscape)', |
| 233 | + 'screen and (orientation: portrait)', |
| 234 | + 'tv', |
| 235 | + 'print', |
| 236 | + 'print and (orientation: landscape)', |
| 237 | + 'print and (orientation: portrait)' |
| 238 | + ] |
| 239 | + |
| 240 | + const expected = expectedOrder.join('\n') |
| 241 | + const received = receivedOrder.sort(sortCSSmq.desktopFirst).join('\n') |
| 242 | + |
| 243 | + expect(received).toBe(expected) |
| 244 | +}) |
0 commit comments