files_sorting.cy.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /**
  2. * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. describe('Files: Sorting the file list', { testIsolation: true }, () => {
  23. let currentUser
  24. beforeEach(() => {
  25. cy.createRandomUser().then((user) => {
  26. currentUser = user
  27. cy.login(user)
  28. })
  29. })
  30. it('Files are sorted by name ascending by default', () => {
  31. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 first.txt')
  32. .uploadContent(currentUser, new Blob(), 'text/plain', '/z last.txt')
  33. .uploadContent(currentUser, new Blob(), 'text/plain', '/A.txt')
  34. .uploadContent(currentUser, new Blob(), 'text/plain', '/Ä.txt')
  35. .mkdir(currentUser, '/m')
  36. .mkdir(currentUser, '/4')
  37. cy.login(currentUser)
  38. cy.visit('/apps/files')
  39. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  40. switch (index) {
  41. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('4')
  42. break
  43. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('m')
  44. break
  45. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 first.txt')
  46. break
  47. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('A.txt')
  48. break
  49. case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('Ä.txt')
  50. break
  51. case 5: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  52. break
  53. case 6: expect($row.attr('data-cy-files-list-row-name')).to.eq('z last.txt')
  54. break
  55. }
  56. })
  57. })
  58. /**
  59. * Regression test of https://github.com/nextcloud/server/issues/45829
  60. */
  61. it('Filesnames with numbers are sorted by name ascending by default', () => {
  62. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/name.txt')
  63. .uploadContent(currentUser, new Blob(), 'text/plain', '/name_03.txt')
  64. .uploadContent(currentUser, new Blob(), 'text/plain', '/name_02.txt')
  65. .uploadContent(currentUser, new Blob(), 'text/plain', '/name_01.txt')
  66. cy.login(currentUser)
  67. cy.visit('/apps/files')
  68. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  69. switch (index) {
  70. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('name.txt')
  71. break
  72. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_01.txt')
  73. break
  74. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_02.txt')
  75. break
  76. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('name_03.txt')
  77. break
  78. }
  79. })
  80. })
  81. it('Can sort by size', () => {
  82. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1 tiny.txt')
  83. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z big.txt')
  84. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a medium.txt')
  85. .mkdir(currentUser, '/folder')
  86. cy.login(currentUser)
  87. cy.visit('/apps/files')
  88. // click sort button
  89. cy.get('th').contains('button', 'Size').click()
  90. // sorting is set
  91. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
  92. // Files are sorted
  93. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  94. switch (index) {
  95. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
  96. break
  97. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
  98. break
  99. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  100. break
  101. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
  102. break
  103. case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
  104. break
  105. }
  106. })
  107. // click sort button
  108. cy.get('th').contains('button', 'Size').click()
  109. // sorting is set
  110. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
  111. // Files are sorted
  112. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  113. switch (index) {
  114. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('folder')
  115. break
  116. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z big.txt')
  117. break
  118. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a medium.txt')
  119. break
  120. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  121. break
  122. case 4: expect($row.attr('data-cy-files-list-row-name')).to.eq('1 tiny.txt')
  123. break
  124. }
  125. })
  126. })
  127. it('Can sort by mtime', () => {
  128. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1.txt', Date.now() / 1000 - 86400 - 1000)
  129. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z.txt', Date.now() / 1000 - 86400)
  130. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a.txt', Date.now() / 1000 - 86400 - 500)
  131. cy.login(currentUser)
  132. cy.visit('/apps/files')
  133. // click sort button
  134. cy.get('th').contains('button', 'Modified').click()
  135. // sorting is set
  136. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'ascending')
  137. // Files are sorted
  138. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  139. switch (index) {
  140. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt') // uploaded right now
  141. break
  142. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt') // fake time of yesterday
  143. break
  144. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt') // fake time of yesterday and few minutes
  145. break
  146. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt') // fake time of yesterday and ~15 minutes ago
  147. break
  148. }
  149. })
  150. // reverse order
  151. cy.get('th').contains('button', 'Modified').click()
  152. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'descending')
  153. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  154. switch (index) {
  155. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt') // uploaded right now
  156. break
  157. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt') // fake time of yesterday
  158. break
  159. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt') // fake time of yesterday and few minutes
  160. break
  161. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt') // fake time of yesterday and ~15 minutes ago
  162. break
  163. }
  164. })
  165. })
  166. it('Favorites are sorted first', () => {
  167. cy.uploadContent(currentUser, new Blob(), 'text/plain', '/1.txt', Date.now() / 1000 - 86400 - 1000)
  168. .uploadContent(currentUser, new Blob(['a'.repeat(1024)]), 'text/plain', '/z.txt', Date.now() / 1000 - 86400)
  169. .uploadContent(currentUser, new Blob(['a'.repeat(512)]), 'text/plain', '/a.txt', Date.now() / 1000 - 86400 - 500)
  170. .setFileAsFavorite(currentUser, '/a.txt')
  171. cy.login(currentUser)
  172. cy.visit('/apps/files')
  173. cy.log('By name - ascending')
  174. cy.get('th').contains('button', 'Name').click()
  175. cy.contains('th', 'Name').should('have.attr', 'aria-sort', 'ascending')
  176. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  177. switch (index) {
  178. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  179. break
  180. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  181. break
  182. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  183. break
  184. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  185. break
  186. }
  187. })
  188. cy.log('By name - descending')
  189. cy.get('th').contains('button', 'Name').click()
  190. cy.contains('th', 'Name').should('have.attr', 'aria-sort', 'descending')
  191. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  192. switch (index) {
  193. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  194. break
  195. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  196. break
  197. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  198. break
  199. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  200. break
  201. }
  202. })
  203. cy.log('By size - ascending')
  204. cy.get('th').contains('button', 'Size').click()
  205. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'ascending')
  206. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  207. switch (index) {
  208. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  209. break
  210. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  211. break
  212. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  213. break
  214. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  215. break
  216. }
  217. })
  218. cy.log('By size - descending')
  219. cy.get('th').contains('button', 'Size').click()
  220. cy.contains('th', 'Size').should('have.attr', 'aria-sort', 'descending')
  221. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  222. switch (index) {
  223. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  224. break
  225. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  226. break
  227. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  228. break
  229. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  230. break
  231. }
  232. })
  233. cy.log('By mtime - ascending')
  234. cy.get('th').contains('button', 'Modified').click()
  235. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'ascending')
  236. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  237. switch (index) {
  238. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  239. break
  240. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  241. break
  242. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  243. break
  244. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  245. break
  246. }
  247. })
  248. cy.log('By mtime - descending')
  249. cy.get('th').contains('button', 'Modified').click()
  250. cy.contains('th', 'Modified').should('have.attr', 'aria-sort', 'descending')
  251. cy.get('[data-cy-files-list-row]').each(($row, index) => {
  252. switch (index) {
  253. case 0: expect($row.attr('data-cy-files-list-row-name')).to.eq('a.txt')
  254. break
  255. case 1: expect($row.attr('data-cy-files-list-row-name')).to.eq('1.txt')
  256. break
  257. case 2: expect($row.attr('data-cy-files-list-row-name')).to.eq('z.txt')
  258. break
  259. case 3: expect($row.attr('data-cy-files-list-row-name')).to.eq('welcome.txt')
  260. break
  261. }
  262. })
  263. })
  264. })