processExtraFormData.test.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 { overrideExtraFormData } from '../../src/query/processExtraFormData';
  20. describe('overrideExtraFormData', () => {
  21. it('should assign allowed nonexistent value', () => {
  22. expect(
  23. overrideExtraFormData(
  24. {
  25. granularity: 'something',
  26. viz_type: 'custom',
  27. datasource: 'table_1',
  28. },
  29. {
  30. time_range: '100 years ago',
  31. },
  32. ),
  33. ).toEqual({
  34. granularity: 'something',
  35. viz_type: 'custom',
  36. datasource: 'table_1',
  37. time_range: '100 years ago',
  38. });
  39. });
  40. it('should override allowed preexisting value', () => {
  41. expect(
  42. overrideExtraFormData(
  43. {
  44. granularity: 'something',
  45. viz_type: 'custom',
  46. datasource: 'table_1',
  47. time_range: '100 years ago',
  48. },
  49. {
  50. time_range: '50 years ago',
  51. },
  52. ),
  53. ).toEqual({
  54. granularity: 'something',
  55. viz_type: 'custom',
  56. datasource: 'table_1',
  57. time_range: '50 years ago',
  58. });
  59. });
  60. it('should not override non-allowed value', () => {
  61. expect(
  62. overrideExtraFormData(
  63. {
  64. granularity: 'something',
  65. viz_type: 'custom',
  66. datasource: 'table_1',
  67. time_range: '100 years ago',
  68. },
  69. {
  70. // @ts-expect-error
  71. viz_type: 'other custom viz',
  72. },
  73. ),
  74. ).toEqual({
  75. granularity: 'something',
  76. viz_type: 'custom',
  77. datasource: 'table_1',
  78. time_range: '100 years ago',
  79. });
  80. });
  81. it('should override preexisting extra value', () => {
  82. expect(
  83. overrideExtraFormData(
  84. {
  85. granularity: 'something',
  86. viz_type: 'custom',
  87. datasource: 'table_1',
  88. time_range: '100 years ago',
  89. extras: {
  90. time_grain_sqla: 'PT1H',
  91. },
  92. },
  93. { time_grain_sqla: 'P1D' },
  94. ),
  95. ).toEqual({
  96. granularity: 'something',
  97. viz_type: 'custom',
  98. datasource: 'table_1',
  99. time_range: '100 years ago',
  100. extras: {
  101. time_grain_sqla: 'P1D',
  102. },
  103. });
  104. });
  105. it('should add extra override value', () => {
  106. expect(
  107. overrideExtraFormData(
  108. {
  109. granularity: 'something',
  110. viz_type: 'custom',
  111. datasource: 'table_1',
  112. time_range: '100 years ago',
  113. },
  114. {
  115. time_grain_sqla: 'PT1H',
  116. },
  117. ),
  118. ).toEqual({
  119. granularity: 'something',
  120. viz_type: 'custom',
  121. datasource: 'table_1',
  122. time_range: '100 years ago',
  123. extras: {
  124. time_grain_sqla: 'PT1H',
  125. },
  126. });
  127. });
  128. });