getStandardizedControls.test.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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, VizType } from '@superset-ui/core';
  20. import { getStandardizedControls } from '../../src';
  21. const formData: QueryFormData = {
  22. datasource: '30__table',
  23. viz_type: VizType.Table,
  24. standardizedFormData: {
  25. controls: {
  26. metrics: ['count(*)', 'sum(sales)'],
  27. columns: ['gender', 'gender'],
  28. },
  29. memorizedFormData: [],
  30. },
  31. };
  32. test('without standardizedFormData', () => {
  33. getStandardizedControls().setStandardizedControls({
  34. datasource: '30__table',
  35. viz_type: VizType.Table,
  36. });
  37. expect(getStandardizedControls().controls).toEqual({
  38. metrics: [],
  39. columns: [],
  40. });
  41. });
  42. test('getStandardizedControls', () => {
  43. expect(getStandardizedControls().controls).toEqual({
  44. metrics: [],
  45. columns: [],
  46. });
  47. getStandardizedControls().setStandardizedControls(formData);
  48. expect(getStandardizedControls().controls).toEqual({
  49. metrics: ['count(*)', 'sum(sales)'],
  50. columns: ['gender', 'gender'],
  51. });
  52. expect(getStandardizedControls().shiftMetric()).toEqual('count(*)');
  53. expect(getStandardizedControls().controls).toEqual({
  54. metrics: ['sum(sales)'],
  55. columns: ['gender', 'gender'],
  56. });
  57. expect(getStandardizedControls().popAllMetrics()).toEqual(['sum(sales)']);
  58. expect(getStandardizedControls().controls).toEqual({
  59. metrics: [],
  60. columns: ['gender', 'gender'],
  61. });
  62. expect(getStandardizedControls().shiftColumn()).toEqual('gender');
  63. expect(getStandardizedControls().controls).toEqual({
  64. metrics: [],
  65. columns: ['gender'],
  66. });
  67. expect(getStandardizedControls().popAllColumns()).toEqual(['gender']);
  68. expect(getStandardizedControls().controls).toEqual({
  69. metrics: [],
  70. columns: [],
  71. });
  72. getStandardizedControls().setStandardizedControls(formData);
  73. getStandardizedControls().clear();
  74. expect(getStandardizedControls().controls).toEqual({
  75. metrics: [],
  76. columns: [],
  77. });
  78. });