File tree Expand file tree Collapse file tree
components/ScorecardPage/EntitiesTable/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @red-hat-developer-hub/backstage-plugin-scorecard ' : patch
3+ ---
4+
5+ Enable sorting for all other columns in entities table
Original file line number Diff line number Diff line change @@ -90,4 +90,45 @@ describe('EntitiesTableHeader', () => {
9090 } ) ;
9191 expect ( sortLabel ) . toBeInTheDocument ( ) ;
9292 } ) ;
93+
94+ it ( 'should call onSortRequest with the correct column id when a different sortable header is clicked' , async ( ) => {
95+ const onSortRequest = jest . fn ( ) ;
96+ render (
97+ < table >
98+ < EntitiesTableHeader { ...defaultProps } onSortRequest = { onSortRequest } />
99+ </ table > ,
100+ ) ;
101+
102+ await userEvent . click (
103+ screen . getByText ( 'entitiesPage.entitiesTable.header.entity' ) ,
104+ ) ;
105+ expect ( onSortRequest ) . toHaveBeenCalledWith ( 'entityName' ) ;
106+
107+ await userEvent . click (
108+ screen . getByText ( 'entitiesPage.entitiesTable.header.lastUpdated' ) ,
109+ ) ;
110+ expect ( onSortRequest ) . toHaveBeenCalledWith ( 'timestamp' ) ;
111+ } ) ;
112+
113+ it ( 'should call onSortRequest again when clicking the already-active sorted column' , async ( ) => {
114+ const onSortRequest = jest . fn ( ) ;
115+ render (
116+ < table >
117+ < EntitiesTableHeader
118+ orderBy = "status"
119+ order = "asc"
120+ onSortRequest = { onSortRequest }
121+ />
122+ </ table > ,
123+ ) ;
124+
125+ const metricHeader = screen . getByText (
126+ 'entitiesPage.entitiesTable.header.metric' ,
127+ ) ;
128+ await userEvent . click ( metricHeader ) ;
129+ await userEvent . click ( metricHeader ) ;
130+
131+ expect ( onSortRequest ) . toHaveBeenCalledTimes ( 2 ) ;
132+ expect ( onSortRequest ) . toHaveBeenCalledWith ( 'status' ) ;
133+ } ) ;
93134} ) ;
Original file line number Diff line number Diff line change @@ -37,30 +37,30 @@ export const SCORECARD_ENTITIES_TABLE_HEADERS: readonly HeadCell[] = [
3737 id : 'metricValue' ,
3838 label : 'entitiesPage.entitiesTable.header.value' ,
3939 width : '8%' ,
40- sortable : false ,
40+ sortable : true ,
4141 } ,
4242 {
4343 id : 'entityName' ,
4444 label : 'entitiesPage.entitiesTable.header.entity' ,
4545 width : '28%' ,
46- sortable : false ,
46+ sortable : true ,
4747 } ,
4848 {
4949 id : 'owner' ,
5050 label : 'entitiesPage.entitiesTable.header.owner' ,
5151 width : '20%' ,
52- sortable : false ,
52+ sortable : true ,
5353 } ,
5454 {
5555 id : 'entityKind' ,
5656 label : 'entitiesPage.entitiesTable.header.kind' ,
5757 width : '12%' ,
58- sortable : false ,
58+ sortable : true ,
5959 } ,
6060 {
6161 id : 'timestamp' ,
6262 label : 'entitiesPage.entitiesTable.header.lastUpdated' ,
6363 width : '20%' ,
64- sortable : false ,
64+ sortable : true ,
6565 } ,
6666] ;
You can’t perform that action at this time.
0 commit comments