colorControls.test.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import { getColorControlsProps } from '../../src';
  20. describe('getColorControlsProps', () => {
  21. it('should return default values when state is empty', () => {
  22. const state = {};
  23. const result = getColorControlsProps(state);
  24. expect(result).toEqual({
  25. chartId: undefined,
  26. dashboardId: undefined,
  27. hasDashboardColorScheme: false,
  28. hasCustomLabelsColor: false,
  29. colorNamespace: undefined,
  30. mapLabelsColors: {},
  31. sharedLabelsColors: [],
  32. });
  33. });
  34. it('should return correct values when state has form_data with dashboardId and color scheme', () => {
  35. const state = {
  36. form_data: {
  37. dashboardId: 123,
  38. dashboard_color_scheme: 'blueScheme',
  39. label_colors: {},
  40. },
  41. slice: { slice_id: 456 },
  42. };
  43. const result = getColorControlsProps(state);
  44. expect(result).toEqual({
  45. chartId: 456,
  46. dashboardId: 123,
  47. hasDashboardColorScheme: true,
  48. hasCustomLabelsColor: false,
  49. colorNamespace: undefined,
  50. mapLabelsColors: {},
  51. sharedLabelsColors: [],
  52. });
  53. });
  54. it('should detect custom label colors correctly', () => {
  55. const state = {
  56. form_data: {
  57. dashboardId: 123,
  58. label_colors: { label1: '#000000' },
  59. },
  60. slice: { slice_id: 456 },
  61. };
  62. const result = getColorControlsProps(state);
  63. expect(result).toEqual({
  64. chartId: 456,
  65. dashboardId: 123,
  66. hasDashboardColorScheme: false,
  67. hasCustomLabelsColor: true,
  68. colorNamespace: undefined,
  69. mapLabelsColors: {},
  70. sharedLabelsColors: [],
  71. });
  72. });
  73. it('should return shared label colors when available', () => {
  74. const state = {
  75. form_data: {
  76. shared_label_colors: ['#FF5733', '#33FF57'],
  77. },
  78. };
  79. const result = getColorControlsProps(state);
  80. expect(result).toEqual({
  81. chartId: undefined,
  82. dashboardId: undefined,
  83. hasDashboardColorScheme: false,
  84. hasCustomLabelsColor: false,
  85. sharedLabelsColors: ['#FF5733', '#33FF57'],
  86. colorNamespace: undefined,
  87. mapLabelsColors: {},
  88. });
  89. });
  90. it('should handle missing form_data and slice properties', () => {
  91. const state = {
  92. form_data: {
  93. dashboardId: 789,
  94. },
  95. };
  96. const result = getColorControlsProps(state);
  97. expect(result).toEqual({
  98. chartId: undefined,
  99. dashboardId: 789,
  100. hasDashboardColorScheme: false,
  101. hasCustomLabelsColor: false,
  102. colorNamespace: undefined,
  103. mapLabelsColors: {},
  104. sharedLabelsColors: [],
  105. });
  106. });
  107. });