transformProps.test.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, QueryFormData, supersetTheme } from '@superset-ui/core';
  20. import transformProps from '../../src/plugin/transformProps';
  21. import { MetricsLayoutEnum } from '../../src/types';
  22. describe('PivotTableChart transformProps', () => {
  23. const setDataMask = jest.fn();
  24. const formData = {
  25. groupbyRows: ['row1', 'row2'],
  26. groupbyColumns: ['col1', 'col2'],
  27. metrics: ['metric1', 'metric2'],
  28. tableRenderer: 'Table With Subtotal',
  29. colOrder: 'key_a_to_z',
  30. rowOrder: 'key_a_to_z',
  31. aggregateFunction: 'Sum',
  32. transposePivot: true,
  33. combineMetric: true,
  34. rowSubtotalPosition: true,
  35. colSubtotalPosition: true,
  36. colTotals: true,
  37. rowTotals: true,
  38. valueFormat: 'SMART_NUMBER',
  39. metricsLayout: MetricsLayoutEnum.COLUMNS,
  40. viz_type: '',
  41. datasource: '',
  42. conditionalFormatting: [],
  43. dateFormat: '',
  44. legacy_order_by: 'count',
  45. order_desc: true,
  46. currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
  47. };
  48. const chartProps = new ChartProps<QueryFormData>({
  49. formData,
  50. width: 800,
  51. height: 600,
  52. queriesData: [
  53. {
  54. data: [{ name: 'Hulk', sum__num: 1, __timestamp: 599616000000 }],
  55. colnames: ['name', 'sum__num', '__timestamp'],
  56. coltypes: [1, 0, 2],
  57. },
  58. ],
  59. hooks: { setDataMask },
  60. filterState: { selectedFilters: {} },
  61. datasource: { verboseMap: {}, columnFormats: {} },
  62. theme: supersetTheme,
  63. });
  64. it('should transform chart props for viz', () => {
  65. expect(transformProps(chartProps)).toEqual({
  66. width: 800,
  67. height: 600,
  68. groupbyRows: ['row1', 'row2'],
  69. groupbyColumns: ['col1', 'col2'],
  70. metrics: ['metric1', 'metric2'],
  71. tableRenderer: 'Table With Subtotal',
  72. colOrder: 'key_a_to_z',
  73. rowOrder: 'key_a_to_z',
  74. aggregateFunction: 'Sum',
  75. transposePivot: true,
  76. combineMetric: true,
  77. rowSubtotalPosition: true,
  78. colSubtotalPosition: true,
  79. colTotals: true,
  80. rowTotals: true,
  81. valueFormat: 'SMART_NUMBER',
  82. data: [{ name: 'Hulk', sum__num: 1, __timestamp: 599616000000 }],
  83. setDataMask,
  84. selectedFilters: {},
  85. verboseMap: {},
  86. metricsLayout: MetricsLayoutEnum.COLUMNS,
  87. metricColorFormatters: [],
  88. dateFormatters: {},
  89. emitCrossFilters: false,
  90. columnFormats: {},
  91. currencyFormats: {},
  92. currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
  93. });
  94. });
  95. });