chart.test.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 { CHART_LIST } from 'cypress/utils/urls';
  20. import { interceptGet as interceptDashboardGet } from 'cypress/e2e/dashboard/utils';
  21. import { FORM_DATA_DEFAULTS, NUM_METRIC } from './visualizations/shared.helper';
  22. import {
  23. interceptFiltering,
  24. interceptV1ChartData,
  25. saveChartToDashboard,
  26. visitSampleChartFromList,
  27. } from './utils';
  28. // SEARCH_THRESHOLD is 10. We need to add at least 11 dashboards to show search
  29. const SAMPLE_DASHBOARDS_INDEXES = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  30. function openDashboardsAddedTo() {
  31. cy.getBySel('actions-trigger').should('be.visible').click();
  32. cy.get('.ant-dropdown-menu-submenu-title')
  33. .contains('On dashboards')
  34. .trigger('mouseover', { force: true });
  35. }
  36. function closeDashboardsAddedTo() {
  37. cy.get('.ant-dropdown-menu-submenu-title')
  38. .contains('On dashboards')
  39. .trigger('mouseout', { force: true });
  40. cy.getBySel('actions-trigger').click();
  41. }
  42. function verifyDashboardsSubmenuItem(dashboardName) {
  43. cy.get('.ant-dropdown-menu-submenu-popup').contains(dashboardName);
  44. closeDashboardsAddedTo();
  45. }
  46. function verifyDashboardSearch() {
  47. openDashboardsAddedTo();
  48. cy.get('.ant-dropdown-menu-submenu-popup').trigger('mouseover');
  49. cy.get('.ant-dropdown-menu-submenu-popup')
  50. .find('input[placeholder="Search"]')
  51. .type('1');
  52. cy.get('.ant-dropdown-menu-submenu-popup').contains('1 - Sample dashboard');
  53. cy.get('.ant-dropdown-menu-submenu-popup')
  54. .find('input[placeholder="Search"]')
  55. .type('Blahblah');
  56. cy.get('.ant-dropdown-menu-submenu-popup').contains('No results found');
  57. cy.get('.ant-dropdown-menu-submenu-popup')
  58. .find('[aria-label="close-circle"]')
  59. .click();
  60. closeDashboardsAddedTo();
  61. }
  62. function verifyDashboardLink() {
  63. interceptDashboardGet();
  64. openDashboardsAddedTo();
  65. cy.get('.ant-dropdown-menu-submenu-popup').trigger('mouseover', {
  66. force: true,
  67. });
  68. cy.get('.ant-dropdown-menu-submenu-popup a')
  69. .first()
  70. .invoke('removeAttr', 'target')
  71. .click({ force: true });
  72. cy.wait('@get');
  73. }
  74. function verifyMetabar(text) {
  75. cy.getBySel('metadata-bar').contains(text);
  76. }
  77. function saveAndVerifyDashboard(chartName, number) {
  78. saveChartToDashboard(chartName, `${number} - Sample dashboard`);
  79. verifyMetabar(
  80. number > 1 ? `Added to ${number} dashboards` : 'Added to 1 dashboard',
  81. );
  82. openDashboardsAddedTo();
  83. verifyDashboardsSubmenuItem(`${number} - Sample dashboard`);
  84. }
  85. describe('Cross-referenced dashboards', () => {
  86. beforeEach(() => {
  87. interceptFiltering();
  88. cy.createSampleDashboards(SAMPLE_DASHBOARDS_INDEXES);
  89. cy.createSampleCharts([0]);
  90. cy.visit(CHART_LIST);
  91. cy.wait('@filtering');
  92. });
  93. it('should show the cross-referenced dashboards', () => {
  94. visitSampleChartFromList('1 - Sample chart');
  95. cy.getBySel('metadata-bar').contains('Not added to any dashboard');
  96. openDashboardsAddedTo();
  97. verifyDashboardsSubmenuItem('None');
  98. saveAndVerifyDashboard('1 - Sample chart', '1');
  99. saveAndVerifyDashboard('1 - Sample chart', '2');
  100. saveAndVerifyDashboard('1 - Sample chart', '3');
  101. saveAndVerifyDashboard('1 - Sample chart', '4');
  102. saveAndVerifyDashboard('1 - Sample chart', '5');
  103. saveAndVerifyDashboard('1 - Sample chart', '6');
  104. saveAndVerifyDashboard('1 - Sample chart', '7');
  105. saveAndVerifyDashboard('1 - Sample chart', '8');
  106. saveAndVerifyDashboard('1 - Sample chart', '9');
  107. saveAndVerifyDashboard('1 - Sample chart', '10');
  108. saveAndVerifyDashboard('1 - Sample chart', '11');
  109. verifyDashboardSearch();
  110. verifyDashboardLink();
  111. });
  112. });
  113. describe('No Results', () => {
  114. beforeEach(() => {
  115. interceptV1ChartData();
  116. });
  117. it('No results message shows up', () => {
  118. const formData = {
  119. ...FORM_DATA_DEFAULTS,
  120. metrics: [NUM_METRIC],
  121. viz_type: 'echarts_timeseries_line',
  122. adhoc_filters: [
  123. {
  124. expressionType: 'SIMPLE',
  125. subject: 'state',
  126. operator: 'IN',
  127. comparator: ['Fake State'],
  128. clause: 'WHERE',
  129. sqlExpression: null,
  130. },
  131. ],
  132. };
  133. cy.visitChartByParams(formData);
  134. cy.wait('@v1Data').its('response.statusCode').should('eq', 200);
  135. cy.get('div.chart-container').contains(
  136. 'No results were returned for this query',
  137. );
  138. });
  139. });