getMetricLabel.test.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 { getMetricLabel } from '@superset-ui/core';
  20. describe('getMetricLabel', () => {
  21. it('should handle predefined metric name', () => {
  22. expect(getMetricLabel('sum__num')).toEqual('sum__num');
  23. });
  24. it('should handle simple adhoc metrics', () => {
  25. expect(
  26. getMetricLabel({
  27. expressionType: 'SIMPLE',
  28. aggregate: 'AVG',
  29. column: {
  30. id: 5,
  31. type: 'BIGINT',
  32. columnName: 'sum_girls',
  33. },
  34. }),
  35. ).toEqual('AVG(sum_girls)');
  36. });
  37. it('should handle column_name in alternative field', () => {
  38. expect(
  39. getMetricLabel({
  40. expressionType: 'SIMPLE',
  41. aggregate: 'AVG',
  42. column: {
  43. id: 5,
  44. type: 'BIGINT',
  45. column_name: 'sum_girls',
  46. },
  47. }),
  48. ).toEqual('AVG(sum_girls)');
  49. });
  50. it('should handle SQL adhoc metrics', () => {
  51. expect(
  52. getMetricLabel({
  53. expressionType: 'SQL',
  54. sqlExpression: 'COUNT(sum_girls)',
  55. }),
  56. ).toEqual('COUNT(sum_girls)');
  57. });
  58. it('should handle adhoc metrics with custom labels', () => {
  59. expect(
  60. getMetricLabel({
  61. expressionType: 'SQL',
  62. label: 'foo',
  63. sqlExpression: 'COUNT(sum_girls)',
  64. }),
  65. ).toEqual('foo');
  66. });
  67. });