@@ -267,4 +267,65 @@ describe('Files: Sorting the file list', { testIsolation: true }, () => {
267267 }
268268 } )
269269 } )
270+
271+ it ( 'Sorting works after switching view twice' , ( ) => {
272+ cy . uploadContent ( currentUser , new Blob ( ) , 'text/plain' , '/1 tiny.txt' )
273+ . uploadContent ( currentUser , new Blob ( [ 'a' . repeat ( 1024 ) ] ) , 'text/plain' , '/z big.txt' )
274+ . uploadContent ( currentUser , new Blob ( [ 'a' . repeat ( 512 ) ] ) , 'text/plain' , '/a medium.txt' )
275+ . mkdir ( currentUser , '/folder' )
276+ cy . login ( currentUser )
277+ cy . visit ( '/apps/files' )
278+
279+ // click sort button twice
280+ cy . get ( 'th' ) . contains ( 'button' , 'Size' ) . click ( )
281+ cy . get ( 'th' ) . contains ( 'button' , 'Size' ) . click ( )
282+
283+ // switch to personal and click sort button twice again
284+ cy . get ( '[data-cy-files-navigation-item="personal"]' ) . click ( )
285+ cy . get ( 'th' ) . contains ( 'button' , 'Size' ) . click ( )
286+ cy . get ( 'th' ) . contains ( 'button' , 'Size' ) . click ( )
287+
288+ // switch back to files view and do actual assertions
289+ cy . get ( '[data-cy-files-navigation-item="files"]' ) . click ( )
290+
291+ // click sort button
292+ cy . get ( 'th' ) . contains ( 'button' , 'Size' ) . click ( )
293+ // sorting is set
294+ cy . contains ( 'th' , 'Size' ) . should ( 'have.attr' , 'aria-sort' , 'ascending' )
295+ // Files are sorted
296+ cy . get ( '[data-cy-files-list-row]' ) . each ( ( $row , index ) => {
297+ switch ( index ) {
298+ case 0 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( 'folder' )
299+ break
300+ case 1 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( '1 tiny.txt' )
301+ break
302+ case 2 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( 'welcome.txt' )
303+ break
304+ case 3 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( 'a medium.txt' )
305+ break
306+ case 4 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( 'z big.txt' )
307+ break
308+ }
309+ } )
310+
311+ // click sort button
312+ cy . get ( 'th' ) . contains ( 'button' , 'Size' ) . click ( )
313+ // sorting is set
314+ cy . contains ( 'th' , 'Size' ) . should ( 'have.attr' , 'aria-sort' , 'descending' )
315+ // Files are sorted
316+ cy . get ( '[data-cy-files-list-row]' ) . each ( ( $row , index ) => {
317+ switch ( index ) {
318+ case 0 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( 'folder' )
319+ break
320+ case 1 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( 'z big.txt' )
321+ break
322+ case 2 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( 'a medium.txt' )
323+ break
324+ case 3 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( 'welcome.txt' )
325+ break
326+ case 4 : expect ( $row . attr ( 'data-cy-files-list-row-name' ) ) . to . eq ( '1 tiny.txt' )
327+ break
328+ }
329+ } )
330+ } )
270331} )
0 commit comments