buildQuery.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 { QueryFormData } from '@superset-ui/core';
  20. import buildQuery from '../../src/Gantt/buildQuery';
  21. describe('Gantt buildQuery', () => {
  22. const formData: QueryFormData = {
  23. datasource: '1__table',
  24. viz_type: 'gantt_chart',
  25. start_time: 'start_time',
  26. end_time: 'end_time',
  27. y_axis: {
  28. label: 'Y Axis',
  29. sqlExpression: 'SELECT 1',
  30. expressionType: 'SQL',
  31. },
  32. series: 'series',
  33. tooltip_metrics: ['tooltip_metric'],
  34. tooltip_columns: ['tooltip_column'],
  35. order_by_cols: [
  36. JSON.stringify(['start_time', true]),
  37. JSON.stringify(['order_col', false]),
  38. ],
  39. };
  40. it('should build query', () => {
  41. const queryContext = buildQuery(formData);
  42. const [query] = queryContext.queries;
  43. expect(query.metrics).toStrictEqual(['tooltip_metric']);
  44. expect(query.columns).toStrictEqual([
  45. 'start_time',
  46. 'end_time',
  47. {
  48. label: 'Y Axis',
  49. sqlExpression: 'SELECT 1',
  50. expressionType: 'SQL',
  51. },
  52. 'series',
  53. 'tooltip_column',
  54. 'order_col',
  55. ]);
  56. expect(query.series_columns).toStrictEqual(['series']);
  57. expect(query.orderby).toStrictEqual([
  58. ['start_time', true],
  59. ['order_col', false],
  60. ]);
  61. });
  62. });