transformProps.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 {
  20. ChartProps,
  21. QueryFormData,
  22. supersetTheme,
  23. VizType,
  24. } from '@superset-ui/core';
  25. import { HandlebarsQueryFormData } from '../../src/types';
  26. import transformProps from '../../src/plugin/transformProps';
  27. describe('Handlebars transformProps', () => {
  28. const formData: HandlebarsQueryFormData = {
  29. colorScheme: 'bnbColors',
  30. datasource: '3__table',
  31. granularitySqla: 'ds',
  32. metric: 'sum__num',
  33. groupby: ['name'],
  34. width: 500,
  35. height: 500,
  36. viz_type: VizType.Handlebars,
  37. };
  38. const data = [{ name: 'Hulk', sum__num: 1, __timestamp: 599616000000 }];
  39. const chartProps = new ChartProps<QueryFormData>({
  40. formData,
  41. width: 800,
  42. height: 600,
  43. queriesData: [{ data }],
  44. theme: supersetTheme,
  45. });
  46. it('should transform chart props for viz', () => {
  47. expect(transformProps(chartProps)).toEqual(
  48. expect.objectContaining({
  49. width: 800,
  50. height: 600,
  51. data,
  52. }),
  53. );
  54. });
  55. });