transformProps.test.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 { ChartProps, SqlaFormData, supersetTheme } from '@superset-ui/core';
  20. import { EchartsBoxPlotChartProps } from '../../src/BoxPlot/types';
  21. import transformProps from '../../src/BoxPlot/transformProps';
  22. describe('BoxPlot transformProps', () => {
  23. const formData: SqlaFormData = {
  24. datasource: '5__table',
  25. granularity_sqla: 'ds',
  26. time_grain_sqla: 'P1Y',
  27. columns: [],
  28. metrics: ['AVG(averageprice)'],
  29. groupby: ['type', 'region'],
  30. whiskerOptions: 'Tukey',
  31. yAxisFormat: 'SMART_NUMBER',
  32. viz_type: 'my_chart',
  33. zoomable: true,
  34. };
  35. const chartProps = new ChartProps({
  36. formData,
  37. width: 800,
  38. height: 600,
  39. queriesData: [
  40. {
  41. data: [
  42. {
  43. type: 'organic',
  44. region: 'Charlotte',
  45. 'AVG(averageprice)__mean': 1.9405512820512825,
  46. 'AVG(averageprice)__median': 1.9025,
  47. 'AVG(averageprice)__max': 2.505,
  48. 'AVG(averageprice)__min': 1.4775,
  49. 'AVG(averageprice)__q1': 1.73875,
  50. 'AVG(averageprice)__q3': 2.105,
  51. 'AVG(averageprice)__count': 39,
  52. 'AVG(averageprice)__outliers': [2.735],
  53. },
  54. {
  55. type: 'organic',
  56. region: 'Hartford Springfield',
  57. 'AVG(averageprice)__mean': 2.231141025641026,
  58. 'AVG(averageprice)__median': 2.265,
  59. 'AVG(averageprice)__max': 2.595,
  60. 'AVG(averageprice)__min': 1.862,
  61. 'AVG(averageprice)__q1': 2.1285,
  62. 'AVG(averageprice)__q3': 2.32625,
  63. 'AVG(averageprice)__count': 39,
  64. 'AVG(averageprice)__outliers': [],
  65. },
  66. ],
  67. },
  68. ],
  69. theme: supersetTheme,
  70. });
  71. it('should transform chart props for viz', () => {
  72. expect(transformProps(chartProps as EchartsBoxPlotChartProps)).toEqual(
  73. expect.objectContaining({
  74. width: 800,
  75. height: 600,
  76. echartOptions: expect.objectContaining({
  77. dataZoom: expect.arrayContaining([
  78. {
  79. moveOnMouseWheel: true,
  80. type: 'inside',
  81. zoomOnMouseWheel: false,
  82. },
  83. ]),
  84. series: expect.arrayContaining([
  85. expect.objectContaining({
  86. name: 'boxplot',
  87. data: expect.arrayContaining([
  88. expect.objectContaining({
  89. name: 'organic, Charlotte',
  90. value: [
  91. 1.4775,
  92. 1.73875,
  93. 1.9025,
  94. 2.105,
  95. 2.505,
  96. 1.9405512820512825,
  97. 39,
  98. [2.735],
  99. ],
  100. }),
  101. expect.objectContaining({
  102. name: 'organic, Hartford Springfield',
  103. value: [
  104. 1.862,
  105. 2.1285,
  106. 2.265,
  107. 2.32625,
  108. 2.595,
  109. 2.231141025641026,
  110. 39,
  111. [],
  112. ],
  113. }),
  114. ]),
  115. }),
  116. expect.objectContaining({
  117. name: 'outlier',
  118. data: [['organic, Charlotte', 2.735]],
  119. }),
  120. ]),
  121. }),
  122. }),
  123. );
  124. });
  125. });