flattenColorPalette.test.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import flattenColorPalette from '../src/util/flattenColorPalette'
  2. test('it flattens nested color objects', () => {
  3. expect(
  4. flattenColorPalette({
  5. purple: 'purple',
  6. white: {
  7. 25: 'rgba(255,255,255,.25)',
  8. 50: 'rgba(255,255,255,.5)',
  9. 75: 'rgba(255,255,255,.75)',
  10. DEFAULT: '#fff',
  11. },
  12. red: {
  13. 1: 'rgb(33,0,0)',
  14. 2: 'rgb(67,0,0)',
  15. 3: 'rgb(100,0,0)',
  16. },
  17. green: {
  18. 1: 'rgb(0,33,0)',
  19. 2: 'rgb(0,67,0)',
  20. 3: 'rgb(0,100,0)',
  21. },
  22. blue: {
  23. 1: 'rgb(0,0,33)',
  24. 2: 'rgb(0,0,67)',
  25. 3: 'rgb(0,0,100)',
  26. },
  27. })
  28. ).toEqual({
  29. purple: 'purple',
  30. 'white-25': 'rgba(255,255,255,.25)',
  31. 'white-50': 'rgba(255,255,255,.5)',
  32. 'white-75': 'rgba(255,255,255,.75)',
  33. white: '#fff',
  34. 'red-1': 'rgb(33,0,0)',
  35. 'red-2': 'rgb(67,0,0)',
  36. 'red-3': 'rgb(100,0,0)',
  37. 'green-1': 'rgb(0,33,0)',
  38. 'green-2': 'rgb(0,67,0)',
  39. 'green-3': 'rgb(0,100,0)',
  40. 'blue-1': 'rgb(0,0,33)',
  41. 'blue-2': 'rgb(0,0,67)',
  42. 'blue-3': 'rgb(0,0,100)',
  43. })
  44. })
  45. test('it flattens deeply nested color objects', () => {
  46. expect(
  47. flattenColorPalette({
  48. primary: 'purple',
  49. secondary: {
  50. DEFAULT: 'blue',
  51. hover: 'cyan',
  52. focus: 'red',
  53. },
  54. button: {
  55. primary: {
  56. DEFAULT: 'magenta',
  57. hover: 'green',
  58. focus: {
  59. DEFAULT: 'yellow',
  60. variant: 'orange',
  61. },
  62. },
  63. },
  64. })
  65. ).toEqual({
  66. primary: 'purple',
  67. secondary: 'blue',
  68. 'secondary-hover': 'cyan',
  69. 'secondary-focus': 'red',
  70. 'button-primary': 'magenta',
  71. 'button-primary-hover': 'green',
  72. 'button-primary-focus': 'yellow',
  73. 'button-primary-focus-variant': 'orange',
  74. })
  75. })
  76. test('it handles empty objects', () => {
  77. expect(flattenColorPalette({})).toEqual({})
  78. })