getTemporalColumns.test.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 { testQueryResponse, testQueryResults } from '@superset-ui/core';
  20. import { GenericDataType } from '@apache-superset/core/api/core';
  21. import {
  22. Dataset,
  23. getTemporalColumns,
  24. isTemporalColumn,
  25. TestDataset,
  26. } from '../../src';
  27. test('get temporal columns from a Dataset', () => {
  28. expect(getTemporalColumns(TestDataset)).toEqual({
  29. temporalColumns: [
  30. {
  31. advanced_data_type: undefined,
  32. certification_details: null,
  33. certified_by: null,
  34. column_name: 'ds',
  35. description: null,
  36. expression: '',
  37. filterable: true,
  38. groupby: true,
  39. id: 329,
  40. is_certified: false,
  41. is_dttm: true,
  42. python_date_format: null,
  43. type: 'TIMESTAMP WITHOUT TIME ZONE',
  44. type_generic: 2,
  45. verbose_name: null,
  46. warning_markdown: null,
  47. },
  48. ],
  49. defaultTemporalColumn: 'ds',
  50. });
  51. });
  52. test('get temporal columns from a QueryResponse', () => {
  53. expect(getTemporalColumns(testQueryResponse)).toEqual({
  54. temporalColumns: [
  55. {
  56. column_name: 'Column 2',
  57. is_dttm: true,
  58. type: 'TIMESTAMP',
  59. type_generic: GenericDataType.Temporal,
  60. },
  61. ],
  62. defaultTemporalColumn: 'Column 2',
  63. });
  64. });
  65. test('get temporal columns from null', () => {
  66. expect(getTemporalColumns(null)).toEqual({
  67. temporalColumns: [],
  68. defaultTemporalColumn: undefined,
  69. });
  70. });
  71. test('should accept empty Dataset or queryResponse', () => {
  72. expect(
  73. getTemporalColumns({
  74. ...TestDataset,
  75. columns: [],
  76. main_dttm_col: undefined,
  77. } as any as Dataset),
  78. ).toEqual({
  79. temporalColumns: [],
  80. defaultTemporalColumn: undefined,
  81. });
  82. expect(
  83. getTemporalColumns({
  84. ...testQueryResponse,
  85. columns: [],
  86. results: { ...testQueryResults.results, columns: [] },
  87. }),
  88. ).toEqual({
  89. temporalColumns: [],
  90. defaultTemporalColumn: undefined,
  91. });
  92. });
  93. test('should determine temporal columns in a Dataset', () => {
  94. expect(isTemporalColumn('ds', TestDataset)).toBeTruthy();
  95. expect(isTemporalColumn('num', TestDataset)).toBeFalsy();
  96. });