list.test.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 { setGridMode, toggleBulkSelect } from 'cypress/utils';
  21. import {
  22. setFilter,
  23. interceptBulkDelete,
  24. interceptUpdate,
  25. interceptDelete,
  26. visitSampleChartFromList,
  27. saveChartToDashboard,
  28. interceptFiltering,
  29. interceptFavoriteStatus,
  30. } from '../explore/utils';
  31. import { interceptGet as interceptDashboardGet } from '../dashboard/utils';
  32. function orderAlphabetical() {
  33. setFilter('Sort', 'Alphabetical');
  34. }
  35. function openProperties() {
  36. cy.get('[aria-label="more"]').eq(0).click();
  37. cy.getBySel('chart-list-edit-option').click();
  38. }
  39. function openMenu() {
  40. cy.get('[aria-label="more"]').eq(0).click();
  41. }
  42. function confirmDelete() {
  43. cy.getBySel('delete-modal-input').type('DELETE');
  44. cy.getBySel('modal-confirm-button').click();
  45. }
  46. function visitChartList() {
  47. interceptFiltering();
  48. interceptFavoriteStatus();
  49. cy.visit(CHART_LIST);
  50. cy.wait('@filtering');
  51. cy.wait('@favoriteStatus');
  52. }
  53. describe('Charts list', () => {
  54. describe('Cross-referenced dashboards', () => {
  55. beforeEach(() => {
  56. cy.createSampleDashboards([0, 1, 2, 3]);
  57. cy.createSampleCharts([0]);
  58. visitChartList();
  59. });
  60. it('should show the cross-referenced dashboards in the table cell', () => {
  61. interceptDashboardGet();
  62. cy.getBySel('table-row')
  63. .first()
  64. .find('[data-test="table-row-cell"]')
  65. .find('[data-test="crosslinks"]')
  66. .should('be.empty');
  67. cy.getBySel('table-row')
  68. .eq(10)
  69. .find('[data-test="table-row-cell"]')
  70. .find('[data-test="crosslinks"]')
  71. .contains('Supported Charts Dashboard')
  72. .invoke('removeAttr', 'target')
  73. .click();
  74. cy.wait('@get');
  75. });
  76. it('should show the newly added dashboards in a tooltip', () => {
  77. interceptDashboardGet();
  78. visitSampleChartFromList('1 - Sample chart');
  79. saveChartToDashboard('1 - Sample chart', '1 - Sample dashboard');
  80. saveChartToDashboard('1 - Sample chart', '2 - Sample dashboard');
  81. saveChartToDashboard('1 - Sample chart', '3 - Sample dashboard');
  82. saveChartToDashboard('1 - Sample chart', '4 - Sample dashboard');
  83. visitChartList();
  84. cy.getBySel('count-crosslinks').should('be.visible');
  85. });
  86. });
  87. describe('card mode', () => {
  88. before(() => {
  89. visitChartList();
  90. setGridMode('card');
  91. });
  92. it('should preserve other filters when sorting', () => {
  93. cy.getBySel('styled-card').should('have.length', 25);
  94. setFilter('Type', 'Big Number');
  95. setFilter('Sort', 'Least recently modified');
  96. cy.getBySel('styled-card').should('have.length', 3);
  97. });
  98. });
  99. describe('common actions', () => {
  100. beforeEach(() => {
  101. visitChartList();
  102. });
  103. it('should bulk delete correctly', () => {
  104. cy.createSampleCharts([0, 1, 2, 3]);
  105. interceptBulkDelete();
  106. toggleBulkSelect();
  107. // bulk deletes in card-view
  108. setGridMode('card');
  109. orderAlphabetical();
  110. cy.getBySel('skeleton-card').should('not.exist');
  111. cy.getBySel('styled-card').contains('1 - Sample chart').click();
  112. cy.getBySel('styled-card').contains('2 - Sample chart').click();
  113. cy.getBySel('bulk-select-action').contains('Delete').click();
  114. confirmDelete();
  115. cy.wait('@bulkDelete');
  116. cy.getBySel('styled-card')
  117. .eq(1)
  118. .should('not.contain', '1 - Sample chart');
  119. cy.getBySel('styled-card')
  120. .eq(2)
  121. .should('not.contain', '2 - Sample chart');
  122. // bulk deletes in list-view
  123. setGridMode('list');
  124. cy.get('.loading').should('not.exist');
  125. cy.getBySel('table-row').contains('3 - Sample chart').should('exist');
  126. cy.getBySel('table-row').contains('4 - Sample chart').should('exist');
  127. cy.get('[data-test="table-row"] input[type="checkbox"]').eq(0).click();
  128. cy.get('[data-test="table-row"] input[type="checkbox"]').eq(1).click();
  129. cy.getBySel('bulk-select-action').eq(0).contains('Delete').click();
  130. confirmDelete();
  131. cy.wait('@bulkDelete');
  132. cy.get('.loading').should('exist');
  133. cy.get('.loading').should('not.exist');
  134. cy.getBySel('table-row').eq(0).should('not.contain', '3 - Sample chart');
  135. cy.getBySel('table-row').eq(1).should('not.contain', '4 - Sample chart');
  136. });
  137. it('should delete correctly in card mode', () => {
  138. cy.createSampleCharts([0, 1]);
  139. interceptDelete();
  140. // deletes in card-view
  141. setGridMode('card');
  142. orderAlphabetical();
  143. cy.getBySel('styled-card').contains('1 - Sample chart');
  144. openMenu();
  145. cy.getBySel('chart-list-delete-option').click();
  146. confirmDelete();
  147. cy.wait('@delete');
  148. cy.getBySel('styled-card')
  149. .contains('1 - Sample chart')
  150. .should('not.exist');
  151. });
  152. it('should delete correctly in list mode', () => {
  153. cy.createSampleCharts([2, 3]);
  154. interceptDelete();
  155. cy.getBySel('sort-header').contains('Name').click();
  156. // Modal closes immediately without this
  157. cy.wait(2000);
  158. cy.getBySel('table-row').eq(0).contains('3 - Sample chart');
  159. cy.getBySel('delete').eq(0).click();
  160. confirmDelete();
  161. cy.wait('@delete');
  162. cy.get('.loading').should('exist');
  163. cy.get('.loading').should('not.exist');
  164. cy.getBySel('table-row').eq(0).should('not.contain', '3 - Sample chart');
  165. });
  166. it('should edit correctly', () => {
  167. cy.createSampleCharts([0]);
  168. interceptUpdate();
  169. // edits in card-view
  170. setGridMode('card');
  171. orderAlphabetical();
  172. cy.getBySel('skeleton-card').should('not.exist');
  173. cy.getBySel('styled-card').eq(0).contains('1 - Sample chart');
  174. // change title
  175. openProperties();
  176. cy.getBySel('properties-modal-name-input').type(' | EDITED');
  177. cy.get('button:contains("Save")').click();
  178. cy.wait('@update');
  179. cy.getBySel('styled-card').eq(0).contains('1 - Sample chart | EDITED');
  180. // edits in list-view
  181. setGridMode('list');
  182. cy.getBySel('edit-alt').eq(1).click();
  183. cy.getBySel('properties-modal-name-input').clear();
  184. cy.getBySel('properties-modal-name-input').type('1 - Sample chart');
  185. cy.get('button:contains("Save")').click();
  186. cy.wait('@update');
  187. cy.getBySel('table-row').eq(1).contains('1 - Sample chart');
  188. });
  189. });
  190. });