normalize-screens.test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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', values: [{ min: '768px', max: undefined }] },
  6. { name: '1200px', 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', values: [{ min: '768px', max: undefined }] },
  16. { name: 'b', 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', values: [{ min: '768px', max: undefined }] },
  26. { name: 'b', 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. values: [
  37. { max: undefined, min: '768px', raw: undefined },
  38. { max: '1200px', min: undefined, raw: undefined },
  39. ],
  40. },
  41. ])
  42. })
  43. it('should normalize an object with object values (min-width normalized to width)', () => {
  44. let screens = {
  45. a: { 'min-width': '768px' },
  46. b: { max: '1200px' },
  47. }
  48. expect(normalizeScreens(screens)).toEqual([
  49. { name: 'a', values: [{ min: '768px', max: undefined }] },
  50. { name: 'b', values: [{ min: undefined, max: '1200px' }] },
  51. ])
  52. })