expandControlConfig.test.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. expandControlConfig,
  21. sharedControls,
  22. CustomControlItem,
  23. sharedControlComponents,
  24. } from '../../src';
  25. describe('expandControlConfig()', () => {
  26. it('expands shared control alias', () => {
  27. expect(expandControlConfig('metrics')).toEqual({
  28. name: 'metrics',
  29. config: sharedControls.metrics,
  30. });
  31. });
  32. it('expands control with overrides', () => {
  33. expect(
  34. expandControlConfig({
  35. name: 'metrics',
  36. override: {
  37. label: 'Custom Metric',
  38. },
  39. }),
  40. ).toEqual({
  41. name: 'metrics',
  42. config: {
  43. ...sharedControls.metrics,
  44. label: 'Custom Metric',
  45. },
  46. });
  47. });
  48. it('leave full control untouched', () => {
  49. const input = {
  50. name: 'metrics',
  51. config: {
  52. type: 'SelectControl',
  53. label: 'Custom Metric',
  54. },
  55. };
  56. expect(expandControlConfig(input)).toEqual(input);
  57. });
  58. it('load shared components in chart-controls', () => {
  59. const input = {
  60. name: 'metrics',
  61. config: {
  62. type: 'RadioButtonControl',
  63. label: 'Custom Metric',
  64. },
  65. };
  66. expect(
  67. (expandControlConfig(input) as CustomControlItem).config.type,
  68. ).toEqual(sharedControlComponents.RadioButtonControl);
  69. });
  70. it('leave NULL and ReactElement untouched', () => {
  71. expect(expandControlConfig(null)).toBeNull();
  72. const input = <h1>Test</h1>;
  73. expect(expandControlConfig(input)).toBe(input);
  74. });
  75. it('leave unknown text untouched', () => {
  76. const input = 'superset-ui';
  77. expect(expandControlConfig(input as never)).toBe(input);
  78. });
  79. it('return null for invalid configs', () => {
  80. expect(
  81. expandControlConfig({ type: 'SelectControl', label: 'Hello' } as never),
  82. ).toBeNull();
  83. });
  84. });