buildQuery.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 buildQuery from '../../src/Bubble/buildQuery';
  20. describe('Bubble buildQuery', () => {
  21. const formData = {
  22. datasource: '1__table',
  23. viz_type: 'echarts_bubble',
  24. entity: 'customer_name',
  25. x: 'count',
  26. y: {
  27. aggregate: 'sum',
  28. column: {
  29. column_name: 'price_each',
  30. },
  31. expressionType: 'simple',
  32. label: 'SUM(price_each)',
  33. },
  34. size: {
  35. aggregate: 'sum',
  36. column: {
  37. column_name: 'sales',
  38. },
  39. expressionType: 'simple',
  40. label: 'SUM(sales)',
  41. },
  42. };
  43. it('Should build query without dimension', () => {
  44. const queryContext = buildQuery(formData);
  45. const [query] = queryContext.queries;
  46. expect(query.columns).toEqual(['customer_name']);
  47. expect(query.metrics).toEqual([
  48. 'count',
  49. {
  50. aggregate: 'sum',
  51. column: {
  52. column_name: 'price_each',
  53. },
  54. expressionType: 'simple',
  55. label: 'SUM(price_each)',
  56. },
  57. {
  58. aggregate: 'sum',
  59. column: {
  60. column_name: 'sales',
  61. },
  62. expressionType: 'simple',
  63. label: 'SUM(sales)',
  64. },
  65. ]);
  66. });
  67. it('Should build query with dimension', () => {
  68. const queryContext = buildQuery({ ...formData, series: 'state' });
  69. const [query] = queryContext.queries;
  70. expect(query.columns).toEqual(['customer_name', 'state']);
  71. expect(query.metrics).toEqual([
  72. 'count',
  73. {
  74. aggregate: 'sum',
  75. column: {
  76. column_name: 'price_each',
  77. },
  78. expressionType: 'simple',
  79. label: 'SUM(price_each)',
  80. },
  81. {
  82. aggregate: 'sum',
  83. column: {
  84. column_name: 'sales',
  85. },
  86. expressionType: 'simple',
  87. label: 'SUM(sales)',
  88. },
  89. ]);
  90. });
  91. });