transformProps.test.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, supersetTheme } from '@superset-ui/core';
  20. import { EchartsTreemapChartProps } from '../../src/Treemap/types';
  21. import transformProps from '../../src/Treemap/transformProps';
  22. describe('Treemap transformProps', () => {
  23. const formData = {
  24. colorScheme: 'bnbColors',
  25. datasource: '3__table',
  26. granularity_sqla: 'ds',
  27. metric: 'sum__num',
  28. groupby: ['foo', 'bar'],
  29. };
  30. const chartProps = new ChartProps({
  31. formData,
  32. width: 800,
  33. height: 600,
  34. queriesData: [
  35. {
  36. data: [
  37. { foo: 'Sylvester', bar: 'bar1', sum__num: 10 },
  38. { foo: 'Arnold', bar: 'bar2', sum__num: 2.5 },
  39. ],
  40. },
  41. ],
  42. theme: supersetTheme,
  43. });
  44. it('should transform chart props for viz', () => {
  45. expect(transformProps(chartProps as EchartsTreemapChartProps)).toEqual(
  46. expect.objectContaining({
  47. width: 800,
  48. height: 600,
  49. echartOptions: expect.objectContaining({
  50. series: [
  51. expect.objectContaining({
  52. data: expect.arrayContaining([
  53. expect.objectContaining({
  54. name: 'sum__num',
  55. children: expect.arrayContaining([
  56. expect.objectContaining({
  57. name: 'Sylvester',
  58. children: expect.arrayContaining([
  59. expect.objectContaining({
  60. name: 'bar1',
  61. value: 10,
  62. }),
  63. ]),
  64. }),
  65. ]),
  66. }),
  67. ]),
  68. }),
  69. ],
  70. }),
  71. }),
  72. );
  73. });
  74. });