normalize-screens.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { normalizeScreens } from '../src/util/normalizeScreens'
  2. it('should normalize an array of string values', () => {
  3. let screens = ['768px', '1200px']
  4. expect(normalizeScreens(screens)).toEqual([
  5. { name: '768px', not: false, values: [{ min: '768px', max: undefined }] },
  6. { name: '1200px', not: false, values: [{ min: '1200px', max: undefined }] },
  7. ])
  8. })
  9. it('should normalize an object with string values', () => {
  10. let screens = {
  11. a: '768px',
  12. b: '1200px',
  13. }
  14. expect(normalizeScreens(screens)).toEqual([
  15. { name: 'a', not: false, values: [{ min: '768px', max: undefined }] },
  16. { name: 'b', not: false, values: [{ min: '1200px', max: undefined }] },
  17. ])
  18. })
  19. it('should normalize an object with object values', () => {
  20. let screens = {
  21. a: { min: '768px' },
  22. b: { max: '1200px' },
  23. }
  24. expect(normalizeScreens(screens)).toEqual([
  25. { name: 'a', not: false, values: [{ min: '768px', max: undefined }] },
  26. { name: 'b', not: false, values: [{ min: undefined, max: '1200px' }] },
  27. ])
  28. })
  29. it('should normalize an object with multiple object values', () => {
  30. let screens = {
  31. a: [{ min: '768px' }, { max: '1200px' }],
  32. }
  33. expect(normalizeScreens(screens)).toEqual([
  34. {
  35. name: 'a',
  36. not: false,
  37. values: [
  38. { max: undefined, min: '768px', raw: undefined },
  39. { max: '1200px', min: undefined, raw: undefined },
  40. ],
  41. },
  42. ])
  43. })
  44. it('should normalize an object with object values (min-width normalized to width)', () => {
  45. let screens = {
  46. a: { 'min-width': '768px' },
  47. b: { max: '1200px' },
  48. }
  49. expect(normalizeScreens(screens)).toEqual([
  50. { name: 'a', not: false, values: [{ min: '768px', max: undefined }] },
  51. { name: 'b', not: false, values: [{ min: undefined, max: '1200px' }] },
  52. ])
  53. })