@@ -3,7 +3,9 @@ import { IntlProvider } from '@edx/frontend-platform/i18n';
33import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
44import { initializeMockApp } from '@edx/frontend-platform' ;
55import { AppProvider } from '@edx/frontend-platform/react' ;
6- import { render , waitFor , within } from '@testing-library/react' ;
6+ import {
7+ render , waitFor , screen , within ,
8+ } from '@testing-library/react' ;
79import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
810import MockAdapter from 'axios-mock-adapter' ;
911
@@ -59,7 +61,16 @@ const mockTagsResponse = {
5961 } ,
6062 ] ,
6163} ;
62- const rootTagsListUrl = 'http://localhost:18010/api/content_tagging/v1/taxonomies/1/tags/?page=1' ;
64+ const mockTagsPaginationResponse = {
65+ next : null ,
66+ previous : null ,
67+ count : 103 ,
68+ num_pages : 2 ,
69+ current_page : 1 ,
70+ start : 0 ,
71+ results : [ ] ,
72+ } ;
73+ const rootTagsListUrl = 'http://localhost:18010/api/content_tagging/v1/taxonomies/1/tags/?page=1&page_size=100' ;
6374const subTagsResponse = {
6475 next : null ,
6576 previous : null ,
@@ -102,22 +113,21 @@ describe('<TagListTable />', () => {
102113 let resolveResponse ;
103114 const promise = new Promise ( resolve => { resolveResponse = resolve ; } ) ;
104115 axiosMock . onGet ( rootTagsListUrl ) . reply ( ( ) => promise ) ;
105- const result = render ( < RootWrapper /> ) ;
106- const spinner = result . getByRole ( 'status' ) ;
116+ render ( < RootWrapper /> ) ;
117+ const spinner = screen . getByRole ( 'status' ) ;
107118 expect ( spinner . textContent ) . toEqual ( 'loading' ) ;
108119 resolveResponse ( [ 200 , { } ] ) ;
109- await waitFor ( ( ) => {
110- expect ( result . getByText ( 'No results found' ) ) . toBeInTheDocument ( ) ;
111- } ) ;
120+ const noFoundComponent = await screen . findByText ( 'No results found' ) ;
121+ expect ( noFoundComponent ) . toBeInTheDocument ( ) ;
112122 } ) ;
113123
114124 it ( 'should render page correctly' , async ( ) => {
115125 axiosMock . onGet ( rootTagsListUrl ) . reply ( 200 , mockTagsResponse ) ;
116- const result = render ( < RootWrapper /> ) ;
117- await waitFor ( ( ) => {
118- expect ( result . getByText ( 'root tag 1' ) ) . toBeInTheDocument ( ) ;
119- } ) ;
120- const rows = result . getAllByRole ( 'row' ) ;
126+ render ( < RootWrapper /> ) ;
127+ const tag = await screen . findByText ( 'root tag 1' ) ;
128+ expect ( tag ) . toBeInTheDocument ( ) ;
129+
130+ const rows = screen . getAllByRole ( 'row' ) ;
121131 expect ( rows . length ) . toBe ( 3 + 1 ) ; // 3 items plus header
122132 expect ( within ( rows [ 0 ] ) . getAllByRole ( 'columnheader' ) [ 0 ] . textContent ) . toEqual ( 'Tag name' ) ;
123133 expect ( within ( rows [ 1 ] ) . getAllByRole ( 'cell' ) [ 0 ] . textContent ) . toEqual ( 'root tag 1 (14)' ) ;
@@ -126,11 +136,29 @@ describe('<TagListTable />', () => {
126136 it ( 'should render page correctly with subtags' , async ( ) => {
127137 axiosMock . onGet ( rootTagsListUrl ) . reply ( 200 , mockTagsResponse ) ;
128138 axiosMock . onGet ( subTagsUrl ) . reply ( 200 , subTagsResponse ) ;
129- const result = render ( < RootWrapper /> ) ;
130- const expandButton = result . getAllByLabelText ( 'Expand row' ) [ 0 ] ;
139+ render ( < RootWrapper /> ) ;
140+ const expandButton = screen . getAllByLabelText ( 'Expand row' ) [ 0 ] ;
131141 expandButton . click ( ) ;
142+ const childTag = await screen . findByText ( 'the child tag' ) ;
143+ expect ( childTag ) . toBeInTheDocument ( ) ;
144+ } ) ;
145+
146+ it ( 'should not render pagination footer' , async ( ) => {
147+ axiosMock . onGet ( rootTagsListUrl ) . reply ( 200 , mockTagsResponse ) ;
148+ render ( < RootWrapper /> ) ;
132149 await waitFor ( ( ) => {
133- expect ( result . getByText ( 'the child tag' ) ) . toBeInTheDocument ( ) ;
150+ expect ( screen . queryByRole ( 'navigation' , {
151+ name : / t a b l e p a g i n a t i o n / i,
152+ } ) ) . not . toBeInTheDocument ( ) ;
153+ } ) ;
154+ } ) ;
155+
156+ it ( 'should render pagination footer' , async ( ) => {
157+ axiosMock . onGet ( rootTagsListUrl ) . reply ( 200 , mockTagsPaginationResponse ) ;
158+ render ( < RootWrapper /> ) ;
159+ const tableFooter = await screen . findByRole ( 'navigation' , {
160+ name : / t a b l e p a g i n a t i o n / i,
134161 } ) ;
162+ expect ( tableFooter ) . toBeInTheDocument ( ) ;
135163 } ) ;
136164} ) ;
0 commit comments