@@ -124,6 +124,63 @@ describe('<FilterButton />', () => {
124124 expect ( checkboxes [ 2 ] . getAttribute ( 'aria-checked' ) ) . toBe ( 'false' ) ;
125125 } ) ;
126126
127+ it ( 'should remove the checked state of the menu item when removing its matching filter even when 2 filters were set' , async ( ) => {
128+ render ( < Basic /> ) ;
129+
130+ fireEvent . click ( await screen . findByLabelText ( 'Add filter' ) ) ;
131+ fireEvent . click ( screen . getAllByRole ( 'menuitemcheckbox' ) [ 0 ] ) ;
132+ await screen . findByRole ( 'textbox' , {
133+ name : 'Title' ,
134+ } ) ;
135+
136+ await screen . findByText ( '1-1 of 1' ) ;
137+
138+ fireEvent . click ( await screen . findByLabelText ( 'Add filter' ) ) ;
139+ fireEvent . click ( screen . getAllByRole ( 'menuitemcheckbox' ) [ 2 ] ) ;
140+ fireEvent . change (
141+ await screen . findByRole ( 'textbox' , {
142+ name : 'Body' ,
143+ } ) ,
144+ {
145+ target : { value : 'foo' } ,
146+ }
147+ ) ;
148+ await screen . findByText (
149+ 'No Posts found using the current filters.'
150+ ) ;
151+
152+ fireEvent . click ( screen . getAllByTitle ( 'Remove this filter' ) [ 1 ] ) ;
153+ await screen . findByText ( '1-1 of 1' ) ;
154+
155+ await waitFor (
156+ ( ) => {
157+ expect (
158+ screen . queryByRole ( 'textbox' , {
159+ name : 'Body' ,
160+ } )
161+ ) . toBeNull ( ) ;
162+ } ,
163+ { timeout : 2000 }
164+ ) ;
165+
166+ // Wait for a bit
167+ await new Promise ( resolve => setTimeout ( resolve , 510 ) ) ;
168+
169+ fireEvent . click ( screen . getByTitle ( 'Remove this filter' ) ) ;
170+ await screen . findByText ( '1-10 of 13' ) ;
171+
172+ await waitFor (
173+ ( ) => {
174+ expect (
175+ screen . queryByRole ( 'textbox' , {
176+ name : 'Title' ,
177+ } )
178+ ) . toBeNull ( ) ;
179+ } ,
180+ { timeout : 2000 }
181+ ) ;
182+ } , 10000 ) ;
183+
127184 it ( 'should display the filter button if all filters are shown and there is a filter value' , ( ) => {
128185 render (
129186 < AdminContext theme = { theme } >
0 commit comments