tabs.test.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. parsePostForm,
  21. waitForChartLoad,
  22. getChartAliasBySpec,
  23. } from 'cypress/utils';
  24. import { TABBED_DASHBOARD } from 'cypress/utils/urls';
  25. import { expandFilterOnLeftPanel } from './utils';
  26. const TREEMAP = { name: 'Treemap', viz: 'treemap_v2' };
  27. const LINE_CHART = { name: 'Growth Rate', viz: 'echarts_timeseries_line' };
  28. const BOX_PLOT = { name: 'Box plot', viz: 'box_plot' };
  29. const BIG_NUMBER = { name: 'Number of Girls', viz: 'big_number_total' };
  30. const TABLE = { name: 'Names Sorted by Num in California', viz: 'table' };
  31. function topLevelTabs() {
  32. cy.getBySel('dashboard-component-tabs')
  33. .first()
  34. .find('[data-test="nav-list"] .ant-tabs-nav-list > .ant-tabs-tab')
  35. .as('top-level-tabs');
  36. }
  37. function resetTabs() {
  38. topLevelTabs();
  39. cy.get('@top-level-tabs').first().click();
  40. waitForChartLoad(TREEMAP);
  41. waitForChartLoad(BIG_NUMBER);
  42. waitForChartLoad(TABLE);
  43. }
  44. describe('Dashboard tabs', () => {
  45. before(() => {
  46. cy.visit(TABBED_DASHBOARD);
  47. });
  48. beforeEach(() => {
  49. resetTabs();
  50. });
  51. it('should switch tabs', () => {
  52. topLevelTabs();
  53. cy.get('@top-level-tabs').first().click();
  54. cy.get('@top-level-tabs')
  55. .first()
  56. .should('have.class', 'ant-tabs-tab-active');
  57. cy.get('@top-level-tabs')
  58. .last()
  59. .should('not.have.class', 'ant-tabs-tab-active');
  60. cy.get('[data-test-chart-name="Box plot"]').should('not.exist');
  61. cy.get('[data-test-chart-name="Trends"]').should('not.exist');
  62. cy.get('@top-level-tabs').last().click();
  63. cy.get('@top-level-tabs')
  64. .last()
  65. .should('have.class', 'ant-tabs-tab-active');
  66. cy.get('@top-level-tabs')
  67. .first()
  68. .should('not.have.class', 'ant-tabs-tab-active');
  69. waitForChartLoad(BOX_PLOT);
  70. cy.get('[data-test-chart-name="Box plot"]').should('exist');
  71. resetTabs();
  72. // click row level tab, see 1 more chart
  73. cy.getBySel('dashboard-component-tabs')
  74. .eq(2)
  75. .find('[data-test="nav-list"] .ant-tabs-nav-list > .ant-tabs-tab')
  76. .as('row-level-tabs');
  77. cy.get('@row-level-tabs').last().click();
  78. waitForChartLoad(LINE_CHART);
  79. cy.get('[data-test-chart-name="Trends"]').should('exist');
  80. cy.get('@row-level-tabs').first().click();
  81. });
  82. it.skip('should send new queries when tab becomes visible', () => {
  83. // landing in first tab
  84. waitForChartLoad(TREEMAP);
  85. getChartAliasBySpec(TREEMAP).then(treemapAlias => {
  86. // apply filter
  87. cy.get('.Select__control').first().should('be.visible').click();
  88. cy.get('.Select__control input[type=text]').first().focus();
  89. cy.focused().type('South');
  90. cy.get('.Select__option').contains('South Asia').click();
  91. cy.get('.filter button:not(:disabled)').contains('Apply').click();
  92. // send new query from same tab
  93. cy.wait(treemapAlias).then(({ request }) => {
  94. const requestBody = parsePostForm(request.body);
  95. const requestParams = JSON.parse(requestBody.form_data as string);
  96. expect(requestParams.extra_filters[0]).deep.eq({
  97. col: 'region',
  98. op: 'IN',
  99. val: ['South Asia'],
  100. });
  101. });
  102. });
  103. cy.intercept('**/superset/explore_json/?*').as('legacyChartData');
  104. // click row level tab, send 1 more query
  105. cy.get('.ant-tabs-tab').contains('row tab 2').click();
  106. cy.wait('@legacyChartData').then(({ request }) => {
  107. const requestBody = parsePostForm(request.body);
  108. const requestParams = JSON.parse(requestBody.form_data as string);
  109. expect(requestParams.extra_filters[0]).deep.eq({
  110. col: 'region',
  111. op: 'IN',
  112. val: ['South Asia'],
  113. });
  114. expect(requestParams.viz_type).eq(LINE_CHART.viz);
  115. });
  116. cy.intercept('POST', '**/api/v1/chart/data?*').as('v1ChartData');
  117. // click top level tab, send 1 more query
  118. cy.get('.ant-tabs-tab').contains('Tab B').click();
  119. cy.wait('@v1ChartData').then(({ request }) => {
  120. expect(request.body.queries[0].filters[0]).deep.eq({
  121. col: 'region',
  122. op: 'IN',
  123. val: ['South Asia'],
  124. });
  125. });
  126. getChartAliasBySpec(BOX_PLOT).then(boxPlotAlias => {
  127. // navigate to filter and clear filter
  128. cy.get('.ant-tabs-tab').contains('Tab A').click();
  129. cy.get('.ant-tabs-tab').contains('row tab 1').click();
  130. cy.get('.Select__clear-indicator').click();
  131. cy.get('.filter button:not(:disabled)').contains('Apply').click();
  132. // trigger 1 new query
  133. waitForChartLoad(TREEMAP);
  134. // make sure query API not requested multiple times
  135. cy.on('fail', err => {
  136. expect(err.message).to.include('timed out waiting');
  137. return false;
  138. });
  139. cy.wait(boxPlotAlias, { timeout: 1000 }).then(() => {
  140. throw new Error('Unexpected API call.');
  141. });
  142. });
  143. });
  144. it('should update size when switch tab', () => {
  145. cy.get('@top-level-tabs').last().click();
  146. cy.get('@top-level-tabs')
  147. .last()
  148. .should('have.class', 'ant-tabs-tab-active');
  149. expandFilterOnLeftPanel();
  150. cy.wait(1000);
  151. cy.get('@top-level-tabs').first().click();
  152. cy.get('@top-level-tabs')
  153. .first()
  154. .should('have.class', 'ant-tabs-tab-active');
  155. cy.wait(1000);
  156. cy.get("[data-test-viz-type='treemap_v2'] .chart-container").then(
  157. $chartContainer => {
  158. expect($chartContainer.get(0).scrollWidth).eq(
  159. $chartContainer.get(0).offsetWidth,
  160. );
  161. },
  162. );
  163. });
  164. });