buildQuery.test.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. isPostProcessingBoxplot,
  21. PostProcessingBoxplot,
  22. } from '@superset-ui/core';
  23. import { DEFAULT_TITLE_FORM_DATA } from '../../src/constants';
  24. import buildQuery from '../../src/BoxPlot/buildQuery';
  25. import { BoxPlotQueryFormData } from '../../src/BoxPlot/types';
  26. describe('BoxPlot buildQuery', () => {
  27. const formData: BoxPlotQueryFormData = {
  28. ...DEFAULT_TITLE_FORM_DATA,
  29. columns: [],
  30. datasource: '5__table',
  31. granularity_sqla: 'ds',
  32. groupby: ['bar'],
  33. metrics: ['foo'],
  34. time_grain_sqla: 'P1Y',
  35. viz_type: 'my_chart',
  36. whiskerOptions: 'Tukey',
  37. yAxisFormat: 'SMART_NUMBER',
  38. };
  39. it('should build timeseries when series columns is empty', () => {
  40. const queryContext = buildQuery(formData);
  41. const [query] = queryContext.queries;
  42. expect(query.metrics).toEqual(['foo']);
  43. expect(query.columns).toEqual(['ds', 'bar']);
  44. expect(query.series_columns).toEqual(['bar']);
  45. const [rule] = query.post_processing || [];
  46. expect(isPostProcessingBoxplot(rule)).toEqual(true);
  47. expect((rule as PostProcessingBoxplot)?.options?.groupby).toEqual(['bar']);
  48. });
  49. it('should build non-timeseries query object when columns is defined', () => {
  50. const queryContext = buildQuery({ ...formData, columns: ['qwerty'] });
  51. const [query] = queryContext.queries;
  52. expect(query.metrics).toEqual(['foo']);
  53. expect(query.columns).toEqual(['qwerty', 'bar']);
  54. expect(query.series_columns).toEqual(['bar']);
  55. const [rule] = query.post_processing || [];
  56. expect(isPostProcessingBoxplot(rule)).toEqual(true);
  57. expect((rule as PostProcessingBoxplot)?.options?.groupby).toEqual(['bar']);
  58. });
  59. });