files_sorting.cy.ts 9.8 KB

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