files_sorting.cy.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. /**
  42. * Regression test of https://github.com/nextcloud/server/issues/45829
  43. */
  44. it('Filesnames with numbers are sorted by name ascending by default', () => {
  45. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/name.txt')
  46. .uploadContent(currentUser, new Blob(), 'text/plain', '/name_03.txt')
  47. .uploadContent(currentUser, new Blob(), 'text/plain', '/name_02.txt')
  48. .uploadContent(currentUser, new Blob(), 'text/plain', '/name_01.txt')
  49. cy.login(currentUser)
  50. cy.visit('/apps/files')
  51. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  52. switch (index) {
  53. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('name.txt')
  54. break
  55. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_01.txt')
  56. break
  57. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_02.txt')
  58. break
  59. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_03.txt')
  60. break
  61. }
  62. })
  63. })
  64. it('Can sort by size', () => {
  65. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 tiny.txt')
  66. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z big.txt')
  67. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a medium.txt')
  68. .mkdir(currentUser, '/folder')
  69. cy.login(currentUser)
  70. cy.visit('/apps/files')
  71. // click sort button
  72. cy.get('th').contains('button', 'Size').click()
  73. // sorting is set
  74. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
  75. // Files are sorted
  76. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  77. switch (index) {
  78. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
  79. break
  80. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
  81. break
  82. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  83. break
  84. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
  85. break
  86. case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
  87. break
  88. }
  89. })
  90. // click sort button
  91. cy.get('th').contains('button', 'Size').click()
  92. // sorting is set
  93. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
  94. // Files are sorted
  95. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  96. switch (index) {
  97. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
  98. break
  99. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
  100. break
  101. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
  102. break
  103. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  104. break
  105. case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
  106. break
  107. }
  108. })
  109. })
  110. it('Can sort by mtime', () => {
  111. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1.txt', Date.now() / 1000 - 86400 - 1000)
  112. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z.txt', Date.now() / 1000 - 86400)
  113. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a.txt', Date.now() / 1000 - 86400 - 500)
  114. cy.login(currentUser)
  115. cy.visit('/apps/files')
  116. // click sort button
  117. cy.get('th').contains('button', 'Modified').click()
  118. // sorting is set
  119. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'ascending')
  120. // Files are sorted
  121. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  122. switch (index) {
  123. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt') // uploaded right now
  124. break
  125. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt') // fake time of yesterday
  126. break
  127. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt') // fake time of yesterday and few minutes
  128. break
  129. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt') // fake time of yesterday and ~15 minutes ago
  130. break
  131. }
  132. })
  133. // reverse order
  134. cy.get('th').contains('button', 'Modified').click()
  135. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'descending')
  136. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  137. switch (index) {
  138. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt') // uploaded right now
  139. break
  140. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt') // fake time of yesterday
  141. break
  142. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt') // fake time of yesterday and few minutes
  143. break
  144. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt') // fake time of yesterday and ~15 minutes ago
  145. break
  146. }
  147. })
  148. })
  149. it('Favorites are sorted first', () => {
  150. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1.txt', Date.now() / 1000 - 86400 - 1000)
  151. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z.txt', Date.now() / 1000 - 86400)
  152. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a.txt', Date.now() / 1000 - 86400 - 500)
  153. .setFileAsFavorite(currentUser, '/a.txt')
  154. cy.login(currentUser)
  155. cy.visit('/apps/files')
  156. cy.log('By name - ascending')
  157. cy.get('th').contains('button', 'Name').click()
  158. cy.contains('th', 'Name').should('have.attr', 'aria-sort', 'ascending')
  159. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  160. switch (index) {
  161. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  162. break
  163. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  164. break
  165. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  166. break
  167. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  168. break
  169. }
  170. })
  171. cy.log('By name - descending')
  172. cy.get('th').contains('button', 'Name').click()
  173. cy.contains('th', 'Name').should('have.attr', 'aria-sort', 'descending')
  174. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  175. switch (index) {
  176. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  177. break
  178. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  179. break
  180. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  181. break
  182. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  183. break
  184. }
  185. })
  186. cy.log('By size - ascending')
  187. cy.get('th').contains('button', 'Size').click()
  188. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
  189. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  190. switch (index) {
  191. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  192. break
  193. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  194. break
  195. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  196. break
  197. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  198. break
  199. }
  200. })
  201. cy.log('By size - descending')
  202. cy.get('th').contains('button', 'Size').click()
  203. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
  204. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  205. switch (index) {
  206. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  207. break
  208. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  209. break
  210. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  211. break
  212. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  213. break
  214. }
  215. })
  216. cy.log('By mtime - ascending')
  217. cy.get('th').contains('button', 'Modified').click()
  218. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'ascending')
  219. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  220. switch (index) {
  221. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  222. break
  223. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  224. break
  225. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  226. break
  227. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  228. break
  229. }
  230. })
  231. cy.log('By mtime - descending')
  232. cy.get('th').contains('button', 'Modified').click()
  233. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'descending')
  234. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  235. switch (index) {
  236. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  237. break
  238. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  239. break
  240. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  241. break
  242. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  243. break
  244. }
  245. })
  246. })
  247. })