prophetOperator.test.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. DTTM_ALIAS,
  21. QueryObject,
  22. SqlaFormData,
  23. VizType,
  24. } from '@superset-ui/core';
  25. import { prophetOperator } from '@superset-ui/chart-controls';
  26. const formData: SqlaFormData = {
  27. metrics: [
  28. 'count(*)',
  29. { label: 'sum(val)', expressionType: 'SQL', sqlExpression: 'sum(val)' },
  30. ],
  31. time_range: '2015 : 2016',
  32. time_grain_sqla: 'P1Y',
  33. datasource: 'foo',
  34. viz_type: VizType.Table,
  35. };
  36. const queryObject: QueryObject = {
  37. metrics: [
  38. 'count(*)',
  39. { label: 'sum(val)', expressionType: 'SQL', sqlExpression: 'sum(val)' },
  40. ],
  41. time_range: '2015 : 2016',
  42. granularity: 'P1Y',
  43. };
  44. test('should skip prophetOperator', () => {
  45. expect(prophetOperator(formData, queryObject)).toEqual(undefined);
  46. });
  47. test('should do prophetOperator with default index', () => {
  48. expect(
  49. prophetOperator(
  50. {
  51. ...formData,
  52. granularity_sqla: 'time_column',
  53. forecastEnabled: true,
  54. forecastPeriods: '3',
  55. forecastInterval: '5',
  56. forecastSeasonalityYearly: true,
  57. forecastSeasonalityWeekly: false,
  58. forecastSeasonalityDaily: false,
  59. },
  60. queryObject,
  61. ),
  62. ).toEqual({
  63. operation: 'prophet',
  64. options: {
  65. time_grain: 'P1Y',
  66. periods: 3.0,
  67. confidence_interval: 5.0,
  68. yearly_seasonality: true,
  69. weekly_seasonality: false,
  70. daily_seasonality: false,
  71. index: DTTM_ALIAS,
  72. },
  73. });
  74. });
  75. test('should do prophetOperator over named column', () => {
  76. expect(
  77. prophetOperator(
  78. {
  79. ...formData,
  80. x_axis: 'ds',
  81. forecastEnabled: true,
  82. forecastPeriods: '3',
  83. forecastInterval: '5',
  84. forecastSeasonalityYearly: true,
  85. forecastSeasonalityWeekly: false,
  86. forecastSeasonalityDaily: false,
  87. },
  88. queryObject,
  89. ),
  90. ).toEqual({
  91. operation: 'prophet',
  92. options: {
  93. time_grain: 'P1Y',
  94. periods: 3.0,
  95. confidence_interval: 5.0,
  96. yearly_seasonality: true,
  97. weekly_seasonality: false,
  98. daily_seasonality: false,
  99. index: 'ds',
  100. },
  101. });
  102. });
  103. test('should do prophetOperator over adhoc column', () => {
  104. expect(
  105. prophetOperator(
  106. {
  107. ...formData,
  108. x_axis: {
  109. label: 'my_case_expr',
  110. expressionType: 'SQL',
  111. sqlExpression: 'case when a = 1 then 1 else 0 end',
  112. },
  113. forecastEnabled: true,
  114. forecastPeriods: '3',
  115. forecastInterval: '5',
  116. forecastSeasonalityYearly: true,
  117. forecastSeasonalityWeekly: false,
  118. forecastSeasonalityDaily: false,
  119. },
  120. queryObject,
  121. ),
  122. ).toEqual({
  123. operation: 'prophet',
  124. options: {
  125. time_grain: 'P1Y',
  126. periods: 3.0,
  127. confidence_interval: 5.0,
  128. yearly_seasonality: true,
  129. weekly_seasonality: false,
  130. daily_seasonality: false,
  131. index: 'my_case_expr',
  132. },
  133. });
  134. });