@@ -413,6 +413,11 @@ function headerCell(utils, tableId, sortKey) {
413413 . find ( th => th . querySelector ( `[data-sort-key="${ sortKey } "]` ) ) ;
414414}
415415
416+ function headerCells ( utils , tableId ) {
417+ return [ ...utils . container . querySelectorAll (
418+ `table[data-rf-table="${ tableId } "] thead th` ) ] ;
419+ }
420+
416421async function waitForPage ( utils , tableId , statusText ) {
417422 await waitFor ( ( ) => {
418423 expect ( paginationNav ( utils , tableId ) ?. textContent ?? '' ) . toContain ( statusText ) ;
@@ -462,21 +467,54 @@ describe('enhanced report tables: pagination', () => {
462467} ) ;
463468
464469describe ( 'enhanced report tables: sorting' , ( ) => {
465- test ( 'sorts ascending on first click, descending on second, updating aria-sort ' , async ( ) => {
470+ test ( 'initializes every Priority column sorted ascending with a visible up arrow ' , async ( ) => {
466471 respondJsonFor ( sampleJson ) ;
467472 const utils = await renderReport ( ) ;
468- const { fireEvent } = await import ( '@testing-library/react' ) ;
469473
470- const prioritiesOf = ( ) => tableRows ( utils , 'class-relationships' )
474+ // Static tables: sorted by priority asc out of the box (priority 1 first),
475+ // arrow signalling both the active sort and that headers are sortable.
476+ for ( const tableId of [ 'class-relationships' , 'package-relationships' , 'class-cycles-summary' ] ) {
477+ const th = headerCell ( utils , tableId , 'priority' ) ;
478+ expect ( th . getAttribute ( 'aria-sort' ) ) . toBe ( 'ascending' ) ;
479+ expect ( th . querySelector ( '.rf-sort-indicator' ) . textContent ) . toBe ( '▲' ) ;
480+ }
481+ // Rows are actually sorted: priority 1 first.
482+ const priorities = tableRows ( utils , 'class-relationships' )
471483 . map ( row => Number ( row . children [ 1 ] . textContent . trim ( ) ) ) ;
484+ expect ( priorities [ 0 ] ) . toBe ( 1 ) ;
485+ expect ( priorities [ 19 ] ) . toBe ( 20 ) ;
486+ // Disharmony tables carry the arrow on their Priority-labelled column.
487+ const godThs = headerCells ( utils , 'disharmony-GOD' ) ;
488+ const godPriority = godThs . find ( th => th . querySelector ( 'button' ) ?. textContent . includes ( 'Priority' ) ) ;
489+ expect ( godPriority . getAttribute ( 'aria-sort' ) ) . toBe ( 'ascending' ) ;
490+ expect ( godPriority . querySelector ( '.rf-sort-indicator' ) . textContent ) . toBe ( '▲' ) ;
491+ // Tables without a Priority column keep their original order untouched.
492+ for ( const th of headerCells ( utils , 'largest-cycle-breakdown' ) ) {
493+ expect ( th . getAttribute ( 'aria-sort' ) ) . toBe ( 'none' ) ;
494+ }
495+ } , SLOW_TEST_MS ) ;
472496
497+ test ( 'clicking the default-sorted Priority column flips it to descending' , async ( ) => {
498+ respondJsonFor ( sampleJson ) ;
499+ const utils = await renderReport ( ) ;
500+ const { fireEvent } = await import ( '@testing-library/react' ) ;
501+
502+ expect ( headerCell ( utils , 'class-relationships' , 'priority' ) . getAttribute ( 'aria-sort' ) )
503+ . toBe ( 'ascending' ) ;
473504 fireEvent . click ( headerCell ( utils , 'class-relationships' , 'priority' ) . querySelector ( 'button' ) ) ;
474505 await waitFor ( ( ) => {
475- expect ( headerCell ( utils , 'class-relationships' , 'priority' ) . getAttribute ( 'aria-sort' ) ) . toBe ( 'ascending' ) ;
506+ expect ( headerCell ( utils , 'class-relationships' , 'priority' ) . getAttribute ( 'aria-sort' ) )
507+ . toBe ( 'descending' ) ;
476508 } ) ;
477- expect ( prioritiesOf ( ) ) . toEqual ( [ ...Array ( 20 ) . keys ( ) ] . map ( i => i + 1 ) ) ;
478- expect ( headerCell ( utils , 'class-relationships' , 'priority' )
479- . querySelector ( '.rf-sort-indicator' ) . textContent ) . toBe ( '▲' ) ;
509+ } , SLOW_TEST_MS ) ;
510+
511+ test ( 'clicking Priority flips the default to descending, then back to ascending' , async ( ) => {
512+ respondJsonFor ( sampleJson ) ;
513+ const utils = await renderReport ( ) ;
514+ const { fireEvent } = await import ( '@testing-library/react' ) ;
515+
516+ const prioritiesOf = ( ) => tableRows ( utils , 'class-relationships' )
517+ . map ( row => Number ( row . children [ 1 ] . textContent . trim ( ) ) ) ;
480518
481519 fireEvent . click ( headerCell ( utils , 'class-relationships' , 'priority' ) . querySelector ( 'button' ) ) ;
482520 await waitFor ( ( ) => {
@@ -485,17 +523,21 @@ describe('enhanced report tables: sorting', () => {
485523 expect ( prioritiesOf ( ) ) . toEqual ( [ ...Array ( 20 ) . keys ( ) ] . map ( i => 47 - i ) ) ;
486524 expect ( headerCell ( utils , 'class-relationships' , 'priority' )
487525 . querySelector ( '.rf-sort-indicator' ) . textContent ) . toBe ( '▼' ) ;
526+
527+ fireEvent . click ( headerCell ( utils , 'class-relationships' , 'priority' ) . querySelector ( 'button' ) ) ;
528+ await waitFor ( ( ) => {
529+ expect ( headerCell ( utils , 'class-relationships' , 'priority' ) . getAttribute ( 'aria-sort' ) ) . toBe ( 'ascending' ) ;
530+ } ) ;
531+ expect ( prioritiesOf ( ) ) . toEqual ( [ ...Array ( 20 ) . keys ( ) ] . map ( i => i + 1 ) ) ;
532+ expect ( headerCell ( utils , 'class-relationships' , 'priority' )
533+ . querySelector ( '.rf-sort-indicator' ) . textContent ) . toBe ( '▲' ) ;
488534 } , SLOW_TEST_MS ) ;
489535
490536 test ( 'applies the sort across the whole dataset and keeps it while paging' , async ( ) => {
491537 respondJsonFor ( sampleJson ) ;
492538 const utils = await renderReport ( ) ;
493539 const { fireEvent } = await import ( '@testing-library/react' ) ;
494540
495- fireEvent . click ( headerCell ( utils , 'class-relationships' , 'priority' ) . querySelector ( 'button' ) ) ;
496- await waitFor ( ( ) => {
497- expect ( headerCell ( utils , 'class-relationships' , 'priority' ) . getAttribute ( 'aria-sort' ) ) . toBe ( 'ascending' ) ;
498- } ) ;
499541 fireEvent . click ( headerCell ( utils , 'class-relationships' , 'priority' ) . querySelector ( 'button' ) ) ;
500542 await waitFor ( ( ) => {
501543 expect ( headerCell ( utils , 'class-relationships' , 'priority' ) . getAttribute ( 'aria-sort' ) ) . toBe ( 'descending' ) ;
@@ -660,10 +702,6 @@ describe('enhanced report tables: CSV export', () => {
660702
661703 // Sort by priority descending so the export order is observable.
662704 fireEvent . click ( headerCell ( utils , 'class-relationships' , 'priority' ) . querySelector ( 'button' ) ) ;
663- await waitFor ( ( ) => {
664- expect ( headerCell ( utils , 'class-relationships' , 'priority' ) . getAttribute ( 'aria-sort' ) ) . toBe ( 'ascending' ) ;
665- } ) ;
666- fireEvent . click ( headerCell ( utils , 'class-relationships' , 'priority' ) . querySelector ( 'button' ) ) ;
667705 await waitFor ( ( ) => {
668706 expect ( headerCell ( utils , 'class-relationships' , 'priority' ) . getAttribute ( 'aria-sort' ) ) . toBe ( 'descending' ) ;
669707 } ) ;
0 commit comments