list.test.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 { DASHBOARD_LIST } from 'cypress/utils/urls';
  20. import { setGridMode, toggleBulkSelect } from 'cypress/utils';
  21. import {
  22. setFilter,
  23. interceptBulkDelete,
  24. interceptUpdate,
  25. interceptDelete,
  26. interceptFav,
  27. interceptUnfav,
  28. } from '../dashboard/utils';
  29. function orderAlphabetical() {
  30. setFilter('Sort', 'Alphabetical');
  31. }
  32. function openProperties() {
  33. cy.get('[aria-label="more"]').first().click();
  34. cy.getBySel('dashboard-card-option-edit-button').click();
  35. }
  36. function openMenu() {
  37. cy.get('[aria-label="more"]').first().click();
  38. }
  39. function confirmDelete(bulk = false) {
  40. interceptDelete();
  41. interceptBulkDelete();
  42. // Wait for modal dialog to be present and visible
  43. cy.get('[role="dialog"][aria-modal="true"]').should('be.visible');
  44. cy.getBySel('delete-modal-input')
  45. .should('be.visible')
  46. .then($input => {
  47. cy.wrap($input).clear();
  48. cy.wrap($input).type('DELETE');
  49. });
  50. cy.getBySel('modal-confirm-button').should('be.visible').click();
  51. if (bulk) {
  52. cy.wait('@bulkDelete');
  53. } else {
  54. cy.wait('@delete');
  55. }
  56. }
  57. describe('Dashboards list', () => {
  58. describe('list mode', () => {
  59. before(() => {
  60. cy.visit(DASHBOARD_LIST);
  61. setGridMode('list');
  62. });
  63. it('should load rows in list mode', () => {
  64. cy.getBySel('listview-table').should('be.visible');
  65. cy.getBySel('sort-header').eq(1).contains('Name');
  66. cy.getBySel('sort-header').eq(2).contains('Status');
  67. cy.getBySel('sort-header').eq(3).contains('Owners');
  68. cy.getBySel('sort-header').eq(4).contains('Last modified');
  69. cy.getBySel('sort-header').eq(5).contains('Actions');
  70. });
  71. it('should sort correctly in list mode', () => {
  72. cy.getBySel('sort-header').eq(1).click();
  73. cy.getBySel('loading-indicator').should('not.exist');
  74. cy.getBySel('table-row').first().contains('Supported Charts Dashboard');
  75. cy.getBySel('sort-header').eq(1).click();
  76. cy.getBySel('loading-indicator').should('not.exist');
  77. cy.getBySel('table-row').first().contains("World Bank's Data");
  78. cy.getBySel('sort-header').eq(1).click();
  79. });
  80. it('should bulk select in list mode', () => {
  81. toggleBulkSelect();
  82. cy.get('[aria-label="Select all"]').click();
  83. cy.get('.ant-checkbox-input')
  84. .should('be.checked')
  85. .should('have.length', 6);
  86. cy.getBySel('bulk-select-copy').contains('5 Selected');
  87. cy.getBySel('bulk-select-action')
  88. .should('have.length', 2)
  89. .then($btns => {
  90. expect($btns).to.contain('Delete');
  91. expect($btns).to.contain('Export');
  92. });
  93. cy.getBySel('bulk-select-deselect-all').click();
  94. cy.get('input[type="checkbox"]:checked').should('have.length', 0);
  95. cy.getBySel('bulk-select-copy').contains('0 Selected');
  96. cy.getBySel('bulk-select-action').should('not.exist');
  97. });
  98. });
  99. describe('card mode', () => {
  100. before(() => {
  101. cy.visit(DASHBOARD_LIST);
  102. setGridMode('card');
  103. });
  104. it('should load rows in card mode', () => {
  105. cy.getBySel('listview-table').should('not.exist');
  106. cy.getBySel('styled-card').should('have.length', 5);
  107. });
  108. it('should bulk select in card mode', () => {
  109. toggleBulkSelect();
  110. cy.getBySel('styled-card').click({ multiple: true });
  111. cy.getBySel('bulk-select-copy').contains('5 Selected');
  112. cy.getBySel('bulk-select-action')
  113. .should('have.length', 2)
  114. .then($btns => {
  115. expect($btns).to.contain('Delete');
  116. expect($btns).to.contain('Export');
  117. });
  118. cy.getBySel('bulk-select-deselect-all').click();
  119. cy.getBySel('bulk-select-copy').contains('0 Selected');
  120. cy.getBySel('bulk-select-action').should('not.exist');
  121. });
  122. it('should sort in card mode', () => {
  123. orderAlphabetical();
  124. cy.getBySel('styled-card').first().contains('Supported Charts Dashboard');
  125. });
  126. it('should preserve other filters when sorting', () => {
  127. cy.getBySel('styled-card').should('have.length', 5);
  128. setFilter('Status', 'Published');
  129. setFilter('Sort', 'Least recently modified');
  130. cy.getBySel('styled-card').should('have.length', 3);
  131. });
  132. });
  133. describe('common actions', () => {
  134. beforeEach(() => {
  135. cy.createSampleDashboards([0, 1, 2, 3]);
  136. cy.visit(DASHBOARD_LIST);
  137. });
  138. it('should allow to favorite/unfavorite dashboard', () => {
  139. interceptFav();
  140. interceptUnfav();
  141. setGridMode('card');
  142. orderAlphabetical();
  143. cy.getBySel('styled-card').first().contains('1 - Sample dashboard');
  144. cy.getBySel('styled-card')
  145. .first()
  146. .find("[aria-label='unstarred']")
  147. .click();
  148. cy.wait('@select');
  149. cy.getBySel('styled-card').first().find("[aria-label='starred']").click();
  150. cy.wait('@unselect');
  151. cy.getBySel('styled-card')
  152. .first()
  153. .find("[aria-label='starred']")
  154. .should('not.exist');
  155. });
  156. it('should bulk delete correctly', () => {
  157. toggleBulkSelect();
  158. // bulk deletes in card-view
  159. setGridMode('card');
  160. orderAlphabetical();
  161. cy.getBySel('styled-card').eq(0).contains('1 - Sample dashboard').click();
  162. cy.getBySel('styled-card').eq(1).contains('2 - Sample dashboard').click();
  163. cy.getBySel('bulk-select-action').eq(0).contains('Delete').click();
  164. confirmDelete(true);
  165. cy.getBySel('styled-card')
  166. .eq(0)
  167. .should('not.contain', '1 - Sample dashboard');
  168. cy.getBySel('styled-card')
  169. .eq(1)
  170. .should('not.contain', '2 - Sample dashboard');
  171. // bulk deletes in list-view
  172. setGridMode('list');
  173. cy.getBySel('table-row').eq(0).contains('3 - Sample dashboard');
  174. cy.getBySel('table-row').eq(1).contains('4 - Sample dashboard');
  175. cy.get('[data-test="table-row"] input[type="checkbox"]').eq(0).click();
  176. cy.get('[data-test="table-row"] input[type="checkbox"]').eq(1).click();
  177. cy.getBySel('bulk-select-action').eq(0).contains('Delete').click();
  178. confirmDelete(true);
  179. cy.getBySel('loading-indicator').should('exist');
  180. cy.getBySel('loading-indicator').should('not.exist');
  181. cy.getBySel('table-row')
  182. .eq(0)
  183. .should('not.contain', '3 - Sample dashboard');
  184. cy.getBySel('table-row')
  185. .eq(1)
  186. .should('not.contain', '4 - Sample dashboard');
  187. });
  188. it.skip('should delete correctly in list mode', () => {
  189. // deletes in list-view
  190. setGridMode('list');
  191. cy.getBySel('table-row')
  192. .eq(0)
  193. .contains('4 - Sample dashboard')
  194. .should('exist');
  195. cy.getBySel('dashboard-list-trash-icon').eq(0).click();
  196. confirmDelete();
  197. cy.getBySel('table-row')
  198. .eq(0)
  199. .should('not.contain', '4 - Sample dashboard');
  200. });
  201. it('should delete correctly in card mode', () => {
  202. // deletes in card-view
  203. setGridMode('card');
  204. orderAlphabetical();
  205. cy.getBySel('styled-card')
  206. .eq(0)
  207. .contains('1 - Sample dashboard')
  208. .should('exist');
  209. openMenu();
  210. cy.getBySel('dashboard-card-option-delete-button').click();
  211. confirmDelete();
  212. cy.getBySel('styled-card')
  213. .eq(0)
  214. .should('not.contain', '1 - Sample dashboard');
  215. });
  216. it('should edit correctly', () => {
  217. interceptUpdate();
  218. // edits in card-view
  219. setGridMode('card');
  220. orderAlphabetical();
  221. cy.getBySel('styled-card').eq(0).contains('1 - Sample dashboard');
  222. // change title
  223. openProperties();
  224. cy.getBySel('dashboard-title-input').type(' | EDITED');
  225. cy.get('button:contains("Save")').click();
  226. cy.wait('@update');
  227. cy.getBySel('styled-card')
  228. .eq(0)
  229. .contains('1 - Sample dashboard | EDITED');
  230. // edits in list-view
  231. setGridMode('list');
  232. cy.getBySel('edit-alt').eq(0).click();
  233. cy.getBySel('dashboard-title-input').clear();
  234. cy.getBySel('dashboard-title-input').type('1 - Sample dashboard');
  235. cy.get('button:contains("Save")').click();
  236. cy.wait('@update');
  237. cy.getBySel('table-row').eq(0).contains('1 - Sample dashboard');
  238. });
  239. });
  240. });