11import React from 'react' ;
22import { IntlProvider } from '@edx/frontend-platform/i18n' ;
33import {
4- act ,
54 render ,
65 waitFor ,
76 fireEvent ,
@@ -74,11 +73,9 @@ describe('<ContentTagsDropDownSelector />', () => {
7473 }
7574
7675 it ( 'should render taxonomy tags drop down selector loading with spinner' , async ( ) => {
77- await act ( async ( ) => {
78- const { getByRole } = await getComponent ( ) ;
79- const spinner = getByRole ( 'status' ) ;
80- expect ( spinner . textContent ) . toEqual ( 'Loading tags' ) ; // Uses <Spinner />
81- } ) ;
76+ const { getByRole } = await getComponent ( ) ;
77+ const spinner = getByRole ( 'status' ) ;
78+ expect ( spinner . textContent ) . toEqual ( 'Loading tags' ) ; // Uses <Spinner />
8279 } ) ;
8380
8481 it ( 'should render taxonomy tags drop down selector with no sub tags' , async ( ) => {
@@ -99,13 +96,11 @@ describe('<ContentTagsDropDownSelector />', () => {
9996 } ,
10097 } ) ;
10198
102- await act ( async ( ) => {
103- const { container, getByText } = await getComponent ( ) ;
99+ const { container, getByText } = await getComponent ( ) ;
104100
105- await waitFor ( ( ) => {
106- expect ( getByText ( 'Tag 1' ) ) . toBeInTheDocument ( ) ;
107- expect ( container . getElementsByClassName ( 'taxonomy-tags-arrow-drop-down' ) . length ) . toBe ( 0 ) ;
108- } ) ;
101+ await waitFor ( ( ) => {
102+ expect ( getByText ( 'Tag 1' ) ) . toBeInTheDocument ( ) ;
103+ expect ( container . getElementsByClassName ( 'taxonomy-tags-arrow-drop-down' ) . length ) . toBe ( 0 ) ;
109104 } ) ;
110105 } ) ;
111106
@@ -127,13 +122,11 @@ describe('<ContentTagsDropDownSelector />', () => {
127122 } ,
128123 } ) ;
129124
130- await act ( async ( ) => {
131- const { container, getByText } = await getComponent ( ) ;
125+ const { container, getByText } = await getComponent ( ) ;
132126
133- await waitFor ( ( ) => {
134- expect ( getByText ( 'Tag 2' ) ) . toBeInTheDocument ( ) ;
135- expect ( container . getElementsByClassName ( 'taxonomy-tags-arrow-drop-down' ) . length ) . toBe ( 1 ) ;
136- } ) ;
127+ await waitFor ( ( ) => {
128+ expect ( getByText ( 'Tag 2' ) ) . toBeInTheDocument ( ) ;
129+ expect ( container . getElementsByClassName ( 'taxonomy-tags-arrow-drop-down' ) . length ) . toBe ( 1 ) ;
137130 } ) ;
138131 } ) ;
139132
@@ -155,47 +148,45 @@ describe('<ContentTagsDropDownSelector />', () => {
155148 } ,
156149 } ) ;
157150
158- await act ( async ( ) => {
159- const dataWithTagsTree = {
160- ...data ,
161- tagsTree : {
162- 'Tag 3' : {
163- explicit : false ,
164- children : { } ,
165- } ,
166- } ,
167- } ;
168- const { container, getByText } = await getComponent ( dataWithTagsTree ) ;
169- await waitFor ( ( ) => {
170- expect ( getByText ( 'Tag 2' ) ) . toBeInTheDocument ( ) ;
171- expect ( container . getElementsByClassName ( 'taxonomy-tags-arrow-drop-down' ) . length ) . toBe ( 1 ) ;
172- } ) ;
173-
174- // Mock useTaxonomyTagsData again since it gets called in the recursive call
175- useTaxonomyTagsData . mockReturnValueOnce ( {
176- hasMorePages : false ,
177- tagPages : {
178- isLoading : false ,
179- isError : false ,
180- data : [ {
181- value : 'Tag 3' ,
182- externalId : null ,
183- childCount : 0 ,
184- depth : 1 ,
185- parentValue : 'Tag 2' ,
186- id : 12346 ,
187- subTagsUrl : null ,
188- } ] ,
151+ const dataWithTagsTree = {
152+ ...data ,
153+ tagsTree : {
154+ 'Tag 3' : {
155+ explicit : false ,
156+ children : { } ,
189157 } ,
190- } ) ;
158+ } ,
159+ } ;
160+ const { container, getByText } = await getComponent ( dataWithTagsTree ) ;
161+ await waitFor ( ( ) => {
162+ expect ( getByText ( 'Tag 2' ) ) . toBeInTheDocument ( ) ;
163+ expect ( container . getElementsByClassName ( 'taxonomy-tags-arrow-drop-down' ) . length ) . toBe ( 1 ) ;
164+ } ) ;
165+
166+ // Mock useTaxonomyTagsData again since it gets called in the recursive call
167+ useTaxonomyTagsData . mockReturnValueOnce ( {
168+ hasMorePages : false ,
169+ tagPages : {
170+ isLoading : false ,
171+ isError : false ,
172+ data : [ {
173+ value : 'Tag 3' ,
174+ externalId : null ,
175+ childCount : 0 ,
176+ depth : 1 ,
177+ parentValue : 'Tag 2' ,
178+ id : 12346 ,
179+ subTagsUrl : null ,
180+ } ] ,
181+ } ,
182+ } ) ;
191183
192- // Expand the dropdown to see the subtags selectors
193- const expandToggle = container . querySelector ( '.taxonomy-tags-arrow-drop-down span' ) ;
194- fireEvent . click ( expandToggle ) ;
184+ // Expand the dropdown to see the subtags selectors
185+ const expandToggle = container . querySelector ( '.taxonomy-tags-arrow-drop-down span' ) ;
186+ fireEvent . click ( expandToggle ) ;
195187
196- await waitFor ( ( ) => {
197- expect ( getByText ( 'Tag 3' ) ) . toBeInTheDocument ( ) ;
198- } ) ;
188+ await waitFor ( ( ) => {
189+ expect ( getByText ( 'Tag 3' ) ) . toBeInTheDocument ( ) ;
199190 } ) ;
200191 } ) ;
201192
@@ -219,48 +210,46 @@ describe('<ContentTagsDropDownSelector />', () => {
219210 } ) ;
220211
221212 const initalSearchTerm = 'test 1' ;
222- await act ( async ( ) => {
223- const { rerender } = await getComponent ( { ...data , searchTerm : initalSearchTerm } ) ;
224-
225- await waitFor ( ( ) => {
226- expect ( useTaxonomyTagsData ) . toBeCalledWith ( data . taxonomyId , null , 1 , initalSearchTerm ) ;
227- } ) ;
228-
229- const updatedSearchTerm = 'test 2' ;
230- rerender ( < ContentTagsDropDownSelectorComponent
231- key = { `selector-${ data . taxonomyId } ` }
232- taxonomyId = { data . taxonomyId }
233- level = { data . level }
234- tagsTree = { data . tagsTree }
235- searchTerm = { updatedSearchTerm }
236- appliedContentTagsTree = { { } }
237- stagedContentTagsTree = { { } }
238- /> ) ;
239-
240- await waitFor ( ( ) => {
241- expect ( useTaxonomyTagsData ) . toBeCalledWith ( data . taxonomyId , null , 1 , updatedSearchTerm ) ;
242- } ) ;
243-
244- // Clean search term
245- const cleanSearchTerm = '' ;
246- rerender ( < ContentTagsDropDownSelectorComponent
247- key = { `selector-${ data . taxonomyId } ` }
248- taxonomyId = { data . taxonomyId }
249- level = { data . level }
250- tagsTree = { data . tagsTree }
251- searchTerm = { cleanSearchTerm }
252- appliedContentTagsTree = { { } }
253- stagedContentTagsTree = { { } }
254- /> ) ;
255-
256- await waitFor ( ( ) => {
257- expect ( useTaxonomyTagsData ) . toBeCalledWith ( data . taxonomyId , null , 1 , cleanSearchTerm ) ;
258- } ) ;
213+ const { rerender } = await getComponent ( { ...data , searchTerm : initalSearchTerm } ) ;
214+
215+ await waitFor ( ( ) => {
216+ expect ( useTaxonomyTagsData ) . toHaveBeenCalledWith ( data . taxonomyId , null , 1 , initalSearchTerm ) ;
217+ } ) ;
218+
219+ const updatedSearchTerm = 'test 2' ;
220+ rerender ( < ContentTagsDropDownSelectorComponent
221+ key = { `selector-${ data . taxonomyId } ` }
222+ taxonomyId = { data . taxonomyId }
223+ level = { data . level }
224+ tagsTree = { data . tagsTree }
225+ searchTerm = { updatedSearchTerm }
226+ appliedContentTagsTree = { { } }
227+ stagedContentTagsTree = { { } }
228+ /> ) ;
229+
230+ await waitFor ( ( ) => {
231+ expect ( useTaxonomyTagsData ) . toHaveBeenCalledWith ( data . taxonomyId , null , 1 , updatedSearchTerm ) ;
232+ } ) ;
233+
234+ // Clean search term
235+ const cleanSearchTerm = '' ;
236+ rerender ( < ContentTagsDropDownSelectorComponent
237+ key = { `selector-${ data . taxonomyId } ` }
238+ taxonomyId = { data . taxonomyId }
239+ level = { data . level }
240+ tagsTree = { data . tagsTree }
241+ searchTerm = { cleanSearchTerm }
242+ appliedContentTagsTree = { { } }
243+ stagedContentTagsTree = { { } }
244+ /> ) ;
245+
246+ await waitFor ( ( ) => {
247+ expect ( useTaxonomyTagsData ) . toHaveBeenCalledWith ( data . taxonomyId , null , 1 , cleanSearchTerm ) ;
259248 } ) ;
260249 } ) ;
261250
262251 it ( 'should render "noTag" message if search doesnt return taxonomies' , async ( ) => {
263- useTaxonomyTagsData . mockReturnValueOnce ( {
252+ useTaxonomyTagsData . mockReturnValue ( {
264253 hasMorePages : false ,
265254 tagPages : {
266255 isLoading : false ,
@@ -271,20 +260,18 @@ describe('<ContentTagsDropDownSelector />', () => {
271260 } ) ;
272261
273262 const searchTerm = 'uncommon search term' ;
274- await act ( async ( ) => {
275- const { getByText } = await getComponent ( { ...data , searchTerm } ) ;
276-
277- await waitFor ( ( ) => {
278- expect ( useTaxonomyTagsData ) . toBeCalledWith ( data . taxonomyId , null , 1 , searchTerm ) ;
279- } ) ;
263+ const { getByText } = await getComponent ( { ...data , searchTerm } ) ;
280264
281- const message = `No tags found with the search term " ${ searchTerm } "` ;
282- expect ( getByText ( message ) ) . toBeInTheDocument ( ) ;
265+ await waitFor ( ( ) => {
266+ expect ( useTaxonomyTagsData ) . toHaveBeenCalledWith ( data . taxonomyId , null , 1 , searchTerm ) ;
283267 } ) ;
268+
269+ const message = `No tags found with the search term "${ searchTerm } "` ;
270+ expect ( getByText ( message ) ) . toBeInTheDocument ( ) ;
284271 } ) ;
285272
286273 it ( 'should render "noTagsInTaxonomy" message if taxonomy is empty' , async ( ) => {
287- useTaxonomyTagsData . mockReturnValueOnce ( {
274+ useTaxonomyTagsData . mockReturnValue ( {
288275 hasMorePages : false ,
289276 tagPages : {
290277 isLoading : false ,
@@ -295,15 +282,13 @@ describe('<ContentTagsDropDownSelector />', () => {
295282 } ) ;
296283
297284 const searchTerm = '' ;
298- await act ( async ( ) => {
299- const { getByText } = await getComponent ( { ...data , searchTerm } ) ;
300-
301- await waitFor ( ( ) => {
302- expect ( useTaxonomyTagsData ) . toBeCalledWith ( data . taxonomyId , null , 1 , searchTerm ) ;
303- } ) ;
285+ const { getByText } = await getComponent ( { ...data , searchTerm } ) ;
304286
305- const message = 'No tags in this taxonomy yet' ;
306- expect ( getByText ( message ) ) . toBeInTheDocument ( ) ;
287+ await waitFor ( ( ) => {
288+ expect ( useTaxonomyTagsData ) . toHaveBeenCalledWith ( data . taxonomyId , null , 1 , searchTerm ) ;
307289 } ) ;
290+
291+ const message = 'No tags in this taxonomy yet' ;
292+ expect ( getByText ( message ) ) . toBeInTheDocument ( ) ;
308293 } ) ;
309294} ) ;
0 commit comments