File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
frontend/src/components/ConsumerGroups/__test__ Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ import { screen } from '@testing-library/react' ;
2+ import { render } from 'lib/testHelpers' ;
3+ import { useConsumerGroups } from 'lib/hooks/api/consumers' ;
4+ import List from '../List' ;
5+
6+ // Mock hooks
7+ jest . mock ( 'lib/hooks/api/consumers' , ( ) => ( {
8+ useConsumerGroups : jest . fn ( ) ,
9+ } ) ) ;
10+
11+ jest . mock ( 'react-router-dom' , ( ) => ( {
12+ ...jest . requireActual ( 'react-router-dom' ) ,
13+ useSearchParams : ( ) => [ new URLSearchParams ( ) , jest . fn ( ) ] ,
14+ useNavigate : ( ) => jest . fn ( ) ,
15+ } ) ) ;
16+
17+ const mockUseConsumerGroups = useConsumerGroups as jest . Mock ;
18+
19+ describe ( 'ConsumerGroups List' , ( ) => {
20+ beforeEach ( ( ) => {
21+ mockUseConsumerGroups . mockImplementation ( ( ) => ( {
22+ data : {
23+ consumerGroups : [
24+ {
25+ groupId : 'group1' ,
26+ consumerLag : 0 ,
27+ members : 1 ,
28+ topics : 1 ,
29+ coordinator : { id : 1 } ,
30+ state : 'STABLE' ,
31+ } ,
32+ {
33+ groupId : 'group2' ,
34+ consumerLag : null ,
35+ members : 1 ,
36+ topics : 1 ,
37+ coordinator : { id : 2 } ,
38+ state : 'STABLE' ,
39+ } ,
40+ ] ,
41+ pageCount : 1 ,
42+ } ,
43+ isSuccess : true ,
44+ isFetching : false ,
45+ } ) ) ;
46+ } ) ;
47+
48+ it ( 'renders consumer lag values correctly' , ( ) => {
49+ render ( < List /> ) ;
50+ const tableRows = screen . getAllByRole ( 'row' ) ;
51+ expect ( tableRows [ 1 ] ) . toHaveTextContent ( '0' ) ;
52+ expect ( tableRows [ 2 ] ) . toHaveTextContent ( 'N/A' ) ;
53+ } ) ;
54+ } ) ;
You can’t perform that action at this time.
0 commit comments