types.test.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 { AdhocColumn } from '@superset-ui/core';
  20. import {
  21. ColumnMeta,
  22. ControlPanelSectionConfig,
  23. CustomControlItem,
  24. isColumnMeta,
  25. isControlPanelSectionConfig,
  26. isCustomControlItem,
  27. isSavedExpression,
  28. } from '../src';
  29. const ADHOC_COLUMN: AdhocColumn = {
  30. hasCustomLabel: true,
  31. label: 'Adhoc column',
  32. sqlExpression: 'case when 1 = 1 then 1 else 2 end',
  33. expressionType: 'SQL',
  34. };
  35. const COLUMN_META: ColumnMeta = {
  36. column_name: 'my_col',
  37. };
  38. const SAVED_EXPRESSION: ColumnMeta = {
  39. column_name: 'Saved expression',
  40. expression: 'case when 1 = 1 then 1 else 2 end',
  41. };
  42. const CONTROL_PANEL_SECTION_CONFIG: ControlPanelSectionConfig = {
  43. label: 'My Section',
  44. description: 'My Description',
  45. controlSetRows: [],
  46. };
  47. const CUSTOM_CONTROL_ITEM: CustomControlItem = {
  48. name: 'Custom Control Item',
  49. config: {
  50. type: 'config',
  51. foo: 'bar',
  52. },
  53. };
  54. test('isColumnMeta returns false for AdhocColumn', () => {
  55. expect(isColumnMeta(ADHOC_COLUMN)).toEqual(false);
  56. });
  57. test('isColumnMeta returns true for ColumnMeta', () => {
  58. expect(isColumnMeta(COLUMN_META)).toEqual(true);
  59. });
  60. test('isSavedExpression returns false for AdhocColumn', () => {
  61. expect(isSavedExpression(ADHOC_COLUMN)).toEqual(false);
  62. });
  63. test('isSavedExpression returns false for ColumnMeta without expression', () => {
  64. expect(isSavedExpression(COLUMN_META)).toEqual(false);
  65. });
  66. test('isSavedExpression returns true for ColumnMeta with expression', () => {
  67. expect(isSavedExpression(SAVED_EXPRESSION)).toEqual(true);
  68. });
  69. test('isControlPanelSectionConfig returns true for section', () => {
  70. expect(isControlPanelSectionConfig(CONTROL_PANEL_SECTION_CONFIG)).toEqual(
  71. true,
  72. );
  73. });
  74. test('isControlPanelSectionConfig returns true for null value', () => {
  75. expect(isControlPanelSectionConfig(null)).toEqual(false);
  76. });
  77. test('isCustomControlItem returns true for proper CustomControlItem', () => {
  78. expect(isCustomControlItem(CUSTOM_CONTROL_ITEM)).toEqual(true);
  79. });
  80. test('isCustomControlItem returns false for generic object', () => {
  81. expect(isCustomControlItem({})).toEqual(false);
  82. });