@@ -61,6 +61,7 @@ const mockTagsResponse = {
6161 descendant_count : 14 ,
6262 _id : 1001 ,
6363 sub_tags_url : '/request/to/load/subtags/1' ,
64+ usage_count : 1 ,
6465 } ,
6566 {
6667 ...tagDefaults ,
@@ -69,6 +70,7 @@ const mockTagsResponse = {
6970 descendant_count : 10 ,
7071 _id : 1002 ,
7172 sub_tags_url : '/request/to/load/subtags/2' ,
73+ usage_count : 0 ,
7274 } ,
7375 {
7476 ...tagDefaults ,
@@ -77,6 +79,7 @@ const mockTagsResponse = {
7779 descendant_count : 5 ,
7880 _id : 1003 ,
7981 sub_tags_url : '/request/to/load/subtags/3' ,
82+ usage_count : 3 ,
8083 } ,
8184 {
8285 ...tagDefaults ,
@@ -86,6 +89,7 @@ const mockTagsResponse = {
8689 _id : 1111 ,
8790 sub_tags_url : null ,
8891 parent_value : 'root tag 1' ,
92+ usage_count : 1 ,
8993 } ,
9094 {
9195 ...tagDefaults ,
@@ -95,6 +99,7 @@ const mockTagsResponse = {
9599 _id : 1111 ,
96100 sub_tags_url : null ,
97101 parent_value : 'the child tag' ,
102+ usage_count : null ,
98103 } ,
99104 ] ,
100105} ;
@@ -107,7 +112,7 @@ const mockTagsPaginationResponse = {
107112 start : 0 ,
108113 results : [ ] ,
109114} ;
110- const rootTagsListUrl = 'http://localhost:18010/api/content_tagging/v1/taxonomies/1/tags/?full_depth_threshold=10000' ;
115+ const rootTagsListUrl = 'http://localhost:18010/api/content_tagging/v1/taxonomies/1/tags/?full_depth_threshold=10000&include_counts=true ' ;
111116const subTagsResponse = {
112117 next : null ,
113118 previous : null ,
@@ -217,6 +222,13 @@ describe('<TagListTable />', () => {
217222 expect ( rows . length ) . toBe ( 3 + 1 ) ; // 3 items plus header
218223 expect ( within ( rows [ 0 ] ) . getAllByRole ( 'columnheader' ) [ 0 ] . textContent ) . toEqual ( 'Tag name' ) ;
219224 expect ( within ( rows [ 1 ] ) . getAllByRole ( 'cell' ) [ 0 ] . textContent ) . toEqual ( 'root tag 1' ) ;
225+ expect ( within ( rows [ 0 ] ) . getAllByRole ( 'columnheader' ) [ 1 ] . textContent ) . toEqual ( 'Usage Count' ) ;
226+ } ) ;
227+
228+ it ( 'should render usage count correctly for root tag' , async ( ) => {
229+ const rows = screen . getAllByRole ( 'row' ) ;
230+ expect ( rows . length ) . toBe ( 3 + 1 ) ; // 3 items plus header
231+ expect ( within ( rows [ 1 ] ) . getAllByRole ( 'cell' ) [ 1 ] . textContent ) . toEqual ( '1' ) ;
220232 } ) ;
221233
222234 it ( 'should render page correctly with subtags' , async ( ) => {
@@ -226,6 +238,36 @@ describe('<TagListTable />', () => {
226238 expect ( childTag ) . toBeInTheDocument ( ) ;
227239 } ) ;
228240
241+ it ( 'should render usage count correctly for sub tag' , async ( ) => {
242+ // Expand all tags and await for child tag to render
243+ const expandButton = screen . getAllByText ( 'Expand All' ) [ 0 ] ;
244+ fireEvent . click ( expandButton ) ;
245+ const childTag = await screen . findByText ( 'the child tag' ) ;
246+ expect ( childTag ) . toBeInTheDocument ( ) ;
247+
248+ const rows = screen . getAllByRole ( 'row' ) ;
249+ expect ( rows . length ) . toBe ( 5 + 1 ) ; // 5 items plus header
250+ expect ( within ( rows [ 2 ] ) . getAllByRole ( 'cell' ) [ 1 ] . textContent ) . toEqual ( '1' ) ;
251+ } ) ;
252+
253+ it ( 'should render usage count as empty/no content when usage count is "0"' , async ( ) => {
254+ const rows = screen . getAllByRole ( 'row' ) ;
255+ expect ( rows . length ) . toBe ( 3 + 1 ) ; // 3 items plus header
256+ expect ( within ( rows [ 2 ] ) . getAllByRole ( 'cell' ) [ 1 ] . textContent ) . toEqual ( '' ) ;
257+ } ) ;
258+
259+ it ( 'should render usage count as empty/no when usage count is "null"' , async ( ) => {
260+ // Expand all tags and await for child tag to render
261+ const expandButton = screen . getAllByText ( 'Expand All' ) [ 0 ] ;
262+ fireEvent . click ( expandButton ) ;
263+ const childTag = await screen . findByText ( 'the child tag' ) ;
264+ expect ( childTag ) . toBeInTheDocument ( ) ;
265+
266+ const rows = screen . getAllByRole ( 'row' ) ;
267+ expect ( rows . length ) . toBe ( 5 + 1 ) ; // 5 items plus header
268+ expect ( within ( rows [ 4 ] ) . getAllByRole ( 'cell' ) [ 1 ] . textContent ) . toEqual ( '' ) ;
269+ } ) ;
270+
229271 it ( 'should not render pagination footer if too few results' , async ( ) => {
230272 axiosMock . onGet ( rootTagsListUrl ) . reply ( 200 , mockTagsResponse ) ;
231273 renderTagListTable ( ) ;
0 commit comments