time_table.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';
  20. describe('Visualization > Time TableViz', () => {
  21. beforeEach(() => {
  22. cy.intercept('POST', '**/superset/explore_json/**').as('getJson');
  23. });
  24. const VIZ_DEFAULTS = { ...FORM_DATA_DEFAULTS, viz_type: 'time_table' };
  25. it('Test time series table multiple metrics last year total', () => {
  26. const formData = {
  27. ...VIZ_DEFAULTS,
  28. metrics: [NUM_METRIC, 'count'],
  29. column_collection: [
  30. {
  31. key: '9g4K-B-YL',
  32. label: 'Last Year',
  33. colType: 'time',
  34. timeLag: '1',
  35. comparisonType: 'value',
  36. },
  37. ],
  38. url: '',
  39. };
  40. cy.visitChartByParams(formData);
  41. cy.verifySliceSuccess({
  42. waitAlias: '@getJson',
  43. querySubstring: NUM_METRIC.label,
  44. });
  45. cy.get('[data-test="time-table"]').within(() => {
  46. cy.get('span').contains('Sum(num)');
  47. cy.get('span').contains('COUNT(*)');
  48. });
  49. });
  50. it('Test time series table metric and group by last year total', () => {
  51. const formData = {
  52. ...VIZ_DEFAULTS,
  53. metrics: [NUM_METRIC],
  54. groupby: ['gender'],
  55. column_collection: [
  56. {
  57. key: '9g4K-B-YL',
  58. label: 'Last Year',
  59. colType: 'time',
  60. timeLag: '1',
  61. comparisonType: 'value',
  62. },
  63. ],
  64. url: '',
  65. };
  66. cy.visitChartByParams(formData);
  67. cy.verifySliceSuccess({
  68. waitAlias: '@getJson',
  69. querySubstring: NUM_METRIC.label,
  70. });
  71. cy.get('[data-test="time-table"]').within(() => {
  72. cy.get('td').contains('boy');
  73. cy.get('td').contains('girl');
  74. });
  75. });
  76. it('Test time series various time columns', () => {
  77. const formData = {
  78. ...VIZ_DEFAULTS,
  79. metrics: [NUM_METRIC, 'count'],
  80. column_collection: [
  81. { key: 'LHHNPhamU', label: 'Current', colType: 'time', timeLag: 0 },
  82. {
  83. key: '9g4K-B-YL',
  84. label: 'Last Year',
  85. colType: 'time',
  86. timeLag: '1',
  87. comparisonType: 'value',
  88. },
  89. {
  90. key: 'JVZXtNu7_',
  91. label: 'YoY',
  92. colType: 'time',
  93. timeLag: 1,
  94. comparisonType: 'perc',
  95. d3format: '%',
  96. },
  97. { key: 'tN5Gba36u', label: 'Trend', colType: 'spark' },
  98. ],
  99. url: '',
  100. };
  101. cy.visitChartByParams(formData);
  102. cy.verifySliceSuccess({
  103. waitAlias: '@getJson',
  104. querySubstring: NUM_METRIC.label,
  105. });
  106. cy.get('[data-test="time-table"]').within(() => {
  107. cy.get('th').contains('Current');
  108. cy.get('th').contains('Last Year');
  109. cy.get('th').contains('YoY');
  110. cy.get('th').contains('Trend');
  111. cy.get('span').contains('%');
  112. cy.get('svg')
  113. .first()
  114. .then(charts => {
  115. const firstChart = charts[0];
  116. expect(firstChart.clientWidth).greaterThan(0);
  117. expect(firstChart.clientHeight).greaterThan(0);
  118. });
  119. });
  120. });
  121. });