files_sorting.cy.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /**
  2. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. describe('Files: Sorting the file list', { testIsolation: true }, () => {
  6. let currentUser
  7. beforeEach(() => {
  8. cy.createRandomUser().then((user) => {
  9. currentUser = user
  10. cy.login(user)
  11. })
  12. })
  13. it('Files are sorted by name ascending by default', () => {
  14. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 first.txt')
  15. .uploadContent(currentUser, new Blob(), 'text/plain', '/z last.txt')
  16. .uploadContent(currentUser, new Blob(), 'text/plain', '/A.txt')
  17. .uploadContent(currentUser, new Blob(), 'text/plain', '/Ä.txt')
  18. .mkdir(currentUser, '/m')
  19. .mkdir(currentUser, '/4')
  20. cy.login(currentUser)
  21. cy.visit('/apps/files')
  22. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  23. switch (index) {
  24. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('4')
  25. break
  26. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('m')
  27. break
  28. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 first.txt')
  29. break
  30. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('A.txt')
  31. break
  32. case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('Ä.txt')
  33. break
  34. case 5: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  35. break
  36. case 6: expect($row.attr('data-cy-files-list-row-name')).to.eq('z last.txt')
  37. break
  38. }
  39. })
  40. })
  41. it('Can sort by size', () => {
  42. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 tiny.txt')
  43. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z big.txt')
  44. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a medium.txt')
  45. .mkdir(currentUser, '/folder')
  46. cy.login(currentUser)
  47. cy.visit('/apps/files')
  48. // click sort button
  49. cy.get('th').contains('button', 'Size').click()
  50. // sorting is set
  51. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
  52. // Files are sorted
  53. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  54. switch (index) {
  55. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
  56. break
  57. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
  58. break
  59. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  60. break
  61. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
  62. break
  63. case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
  64. break
  65. }
  66. })
  67. // click sort button
  68. cy.get('th').contains('button', 'Size').click()
  69. // sorting is set
  70. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
  71. // Files are sorted
  72. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  73. switch (index) {
  74. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
  75. break
  76. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
  77. break
  78. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
  79. break
  80. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  81. break
  82. case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
  83. break
  84. }
  85. })
  86. })
  87. it('Can sort by mtime', () => {
  88. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1.txt', Date.now() / 1000 - 86400 - 1000)
  89. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z.txt', Date.now() / 1000 - 86400)
  90. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a.txt', Date.now() / 1000 - 86400 - 500)
  91. cy.login(currentUser)
  92. cy.visit('/apps/files')
  93. // click sort button
  94. cy.get('th').contains('button', 'Modified').click()
  95. // sorting is set
  96. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'ascending')
  97. // Files are sorted
  98. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  99. switch (index) {
  100. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt') // uploaded right now
  101. break
  102. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt') // fake time of yesterday
  103. break
  104. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt') // fake time of yesterday and few minutes
  105. break
  106. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt') // fake time of yesterday and ~15 minutes ago
  107. break
  108. }
  109. })
  110. // reverse order
  111. cy.get('th').contains('button', 'Modified').click()
  112. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'descending')
  113. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  114. switch (index) {
  115. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt') // uploaded right now
  116. break
  117. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt') // fake time of yesterday
  118. break
  119. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt') // fake time of yesterday and few minutes
  120. break
  121. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt') // fake time of yesterday and ~15 minutes ago
  122. break
  123. }
  124. })
  125. })
  126. it('Favorites are sorted first', () => {
  127. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1.txt', Date.now() / 1000 - 86400 - 1000)
  128. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z.txt', Date.now() / 1000 - 86400)
  129. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a.txt', Date.now() / 1000 - 86400 - 500)
  130. .setFileAsFavorite(currentUser, '/a.txt')
  131. cy.login(currentUser)
  132. cy.visit('/apps/files')
  133. cy.log('By name - ascending')
  134. cy.get('th').contains('button', 'Name').click()
  135. cy.contains('th', 'Name').should('have.attr', 'aria-sort', 'ascending')
  136. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  137. switch (index) {
  138. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  139. break
  140. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  141. break
  142. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  143. break
  144. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  145. break
  146. }
  147. })
  148. cy.log('By name - descending')
  149. cy.get('th').contains('button', 'Name').click()
  150. cy.contains('th', 'Name').should('have.attr', 'aria-sort', 'descending')
  151. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  152. switch (index) {
  153. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  154. break
  155. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  156. break
  157. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  158. break
  159. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  160. break
  161. }
  162. })
  163. cy.log('By size - ascending')
  164. cy.get('th').contains('button', 'Size').click()
  165. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
  166. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  167. switch (index) {
  168. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  169. break
  170. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  171. break
  172. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  173. break
  174. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  175. break
  176. }
  177. })
  178. cy.log('By size - descending')
  179. cy.get('th').contains('button', 'Size').click()
  180. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
  181. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  182. switch (index) {
  183. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  184. break
  185. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  186. break
  187. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  188. break
  189. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  190. break
  191. }
  192. })
  193. cy.log('By mtime - ascending')
  194. cy.get('th').contains('button', 'Modified').click()
  195. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'ascending')
  196. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  197. switch (index) {
  198. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  199. break
  200. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  201. break
  202. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  203. break
  204. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  205. break
  206. }
  207. })
  208. cy.log('By mtime - descending')
  209. cy.get('th').contains('button', 'Modified').click()
  210. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'descending')
  211. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  212. switch (index) {
  213. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  214. break
  215. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  216. break
  217. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  218. break
  219. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  220. break
  221. }
  222. })
  223. })
  224. })