@@ -50,7 +50,7 @@ async function apiDeleteUpload(page, uploadId) {
5050async function goToAdminUploads ( page ) {
5151 await page . goto ( '/#/admin' )
5252 await page . waitForLoadState ( 'networkidle' )
53- await page . getByRole ( 'button' , { name : 'Uploads' , exact : true } ) . click ( )
53+ await page . locator ( 'aside' ) . getByRole ( 'button' , { name : 'Uploads' , exact : true } ) . click ( )
5454 await page . waitForLoadState ( 'networkidle' )
5555}
5656
@@ -328,6 +328,7 @@ test.describe('Sort controls', () => {
328328 // Sort and Order buttons should be visible
329329 await expect ( main . getByRole ( 'button' , { name : 'Date' } ) ) . toBeVisible ( { timeout : 5_000 } )
330330 await expect ( main . getByRole ( 'button' , { name : 'Size' } ) ) . toBeVisible ( )
331+ await expect ( main . getByRole ( 'button' , { name : 'Downloads' } ) ) . toBeVisible ( )
331332 await expect ( main . getByRole ( 'button' , { name : 'Desc' } ) ) . toBeVisible ( )
332333 await expect ( main . getByRole ( 'button' , { name : 'Asc' } ) ) . toBeVisible ( )
333334
@@ -339,14 +340,27 @@ test.describe('Sort controls', () => {
339340 await page . waitForLoadState ( 'networkidle' )
340341 await expect ( main . getByRole ( 'button' , { name : 'Size' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / )
341342 expect ( page . url ( ) ) . toContain ( 'sort=size' )
343+
344+ // Click Downloads — should become active and persist in URL
345+ await main . getByRole ( 'button' , { name : 'Downloads' } ) . click ( )
346+ await page . waitForLoadState ( 'networkidle' )
347+ await expect ( main . getByRole ( 'button' , { name : 'Downloads' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / )
348+ expect ( page . url ( ) ) . toContain ( 'sort=downloads' )
342349 } )
343350
344351 test ( 'home: sort buttons are visible and functional' , async ( { authenticatedPage : page } ) => {
345352 await goToHomeUploads ( page )
346353 const main = page . locator ( 'main' )
354+ const badTokenResponses = [ ]
355+ page . on ( 'response' , response => {
356+ if ( response . url ( ) . includes ( '/me/token' ) && response . status ( ) >= 400 ) {
357+ badTokenResponses . push ( response . status ( ) )
358+ }
359+ } )
347360
348361 await expect ( main . getByRole ( 'button' , { name : 'Date' } ) ) . toBeVisible ( { timeout : 5_000 } )
349362 await expect ( main . getByRole ( 'button' , { name : 'Size' } ) ) . toBeVisible ( )
363+ await expect ( main . getByRole ( 'button' , { name : 'Downloads' } ) ) . toBeVisible ( )
350364 await expect ( main . getByRole ( 'button' , { name : 'Desc' } ) ) . toBeVisible ( )
351365 await expect ( main . getByRole ( 'button' , { name : 'Asc' } ) ) . toBeVisible ( )
352366
@@ -356,9 +370,16 @@ test.describe('Sort controls', () => {
356370 await expect ( main . getByRole ( 'button' , { name : 'Size' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / )
357371 expect ( page . url ( ) ) . toContain ( 'sort=size' )
358372
373+ // Click Downloads
374+ await main . getByRole ( 'button' , { name : 'Downloads' } ) . click ( )
375+ await page . waitForLoadState ( 'networkidle' )
376+ await expect ( main . getByRole ( 'button' , { name : 'Downloads' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / )
377+ expect ( page . url ( ) ) . toContain ( 'sort=downloads' )
378+
359379 // Reload — sort should persist
360380 await page . reload ( { waitUntil : 'networkidle' } )
361- await expect ( main . getByRole ( 'button' , { name : 'Size' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / , { timeout : 5_000 } )
381+ await expect ( main . getByRole ( 'button' , { name : 'Downloads' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / , { timeout : 5_000 } )
382+ expect ( badTokenResponses ) . toEqual ( [ ] )
362383 } )
363384
364385} )
@@ -368,12 +389,12 @@ test.describe('Sort controls', () => {
368389test . describe ( 'Direct URL with combined filters' , ( ) => {
369390 test ( 'admin: navigating to URL with sort + badge filters applies all state' , async ( { authenticatedPage : page } ) => {
370391 // Navigate directly with multiple params — simulates paste-in-new-tab
371- await page . goto ( '/#/admin/uploads?sort=size &oneShot=true&removable=true' )
392+ await page . goto ( '/#/admin/uploads?sort=downloads &oneShot=true&removable=true' )
372393 await page . waitForLoadState ( 'networkidle' )
373394 const main = page . locator ( 'main' )
374395
375- // Sort should be "Size "
376- await expect ( main . getByRole ( 'button' , { name : 'Size ' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / , { timeout : 5_000 } )
396+ // Sort should be "Downloads "
397+ await expect ( main . getByRole ( 'button' , { name : 'Downloads ' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / , { timeout : 5_000 } )
377398 await expect ( main . getByRole ( 'button' , { name : 'Date' } ) ) . not . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / )
378399
379400 // Badge filters should be active
@@ -386,12 +407,19 @@ test.describe('Direct URL with combined filters', () => {
386407 } )
387408
388409 test ( 'home: navigating to URL with sort + badge filters applies all state' , async ( { authenticatedPage : page } ) => {
389- await page . goto ( '/#/home/uploads?sort=size&stream=true&password=true' )
410+ const badTokenResponses = [ ]
411+ page . on ( 'response' , response => {
412+ if ( response . url ( ) . includes ( '/me/token' ) && response . status ( ) >= 400 ) {
413+ badTokenResponses . push ( response . status ( ) )
414+ }
415+ } )
416+
417+ await page . goto ( '/#/home/uploads?sort=downloads&stream=true&password=true' )
390418 await page . waitForLoadState ( 'networkidle' )
391419 const main = page . locator ( 'main' )
392420
393- // Sort should be "Size "
394- await expect ( main . getByRole ( 'button' , { name : 'Size ' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / , { timeout : 5_000 } )
421+ // Sort should be "Downloads "
422+ await expect ( main . getByRole ( 'button' , { name : 'Downloads ' } ) ) . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / , { timeout : 5_000 } )
395423 await expect ( main . getByRole ( 'button' , { name : 'Date' } ) ) . not . toHaveClass ( / t e x t - a c c e n t - 4 0 0 / )
396424
397425 // Badge filters should be active
@@ -401,5 +429,6 @@ test.describe('Direct URL with combined filters', () => {
401429 // Other filters should NOT be active
402430 await expect ( main . getByRole ( 'button' , { name : 'one-shot' } ) ) . not . toHaveClass ( / r i n g - 1 / )
403431 await expect ( main . getByRole ( 'button' , { name : 'removable' } ) ) . not . toHaveClass ( / r i n g - 1 / )
432+ expect ( badTokenResponses ) . toEqual ( [ ] )
404433 } )
405434} )
0 commit comments