11import { Envelope } from '@cucumber/messages'
2- import { render } from '@testing-library/react'
2+ import { render , waitFor } from '@testing-library/react'
33import { userEvent } from '@testing-library/user-event'
44import { expect } from 'chai'
55import React , { VoidFunctionComponent } from 'react'
@@ -26,26 +26,28 @@ describe('FilteredResults', () => {
2626 }
2727
2828 describe ( 'with a targeted run' , ( ) => {
29- it ( 'doesnt include features where no scenarios became test cases' , ( ) => {
29+ it ( 'doesnt include features where no scenarios became test cases' , async ( ) => {
3030 const { getByRole, queryByRole } = render (
3131 < TestableFilteredResults envelopes = { targetedRun as Envelope [ ] } />
3232 )
3333
34- expect (
35- getByRole ( 'heading' , {
36- name : 'features/adding.feature' ,
37- } )
38- ) . to . be . visible
39- expect (
40- queryByRole ( 'heading' , {
41- name : 'features/editing.feature' ,
42- } )
43- ) . not . to . exist
44- expect (
45- queryByRole ( 'heading' , {
46- name : 'features/empty.feature' ,
47- } )
48- ) . not . to . exist
34+ await waitFor ( ( ) => {
35+ expect (
36+ getByRole ( 'heading' , {
37+ name : 'features/adding.feature' ,
38+ } )
39+ ) . to . be . visible
40+ expect (
41+ queryByRole ( 'heading' , {
42+ name : 'features/editing.feature' ,
43+ } )
44+ ) . not . to . exist
45+ expect (
46+ queryByRole ( 'heading' , {
47+ name : 'features/empty.feature' ,
48+ } )
49+ ) . not . to . exist
50+ } )
4951 } )
5052 } )
5153
@@ -55,10 +57,14 @@ describe('FilteredResults', () => {
5557 < TestableFilteredResults envelopes = { attachments as Envelope [ ] } />
5658 )
5759
60+ await waitFor ( ( ) => getByText ( 'samples/attachments/attachments.feature' ) )
61+
5862 await userEvent . type ( getByRole ( 'textbox' , { name : 'Search' } ) , 'nope!' )
5963 await userEvent . keyboard ( '{Enter}' )
6064
61- expect ( getByText ( 'No matches found for your query "nope!" and/or filters' ) ) . to . be . visible
65+ await waitFor ( ( ) => {
66+ expect ( getByText ( 'No matches found for your query "nope!" and/or filters' ) ) . to . be . visible
67+ } )
6268 } )
6369
6470 it ( 'narrows the results with a valid search term, and restores when we clear the search' , async ( ) => {
@@ -84,64 +90,76 @@ describe('FilteredResults', () => {
8490 } )
8591
8692 describe ( 'filtering by status' , ( ) => {
87- it ( 'should not show filters when only one status' , ( ) => {
93+ it ( 'should not show filters when only one status' , async ( ) => {
8894 const { queryByRole } = render ( < TestableFilteredResults envelopes = { minimal as Envelope [ ] } /> )
8995
90- expect ( queryByRole ( 'checkbox' ) ) . not . to . exist
96+ await waitFor ( ( ) => {
97+ expect ( queryByRole ( 'checkbox' ) ) . not . to . exist
98+ } )
9199 } )
92100
93- it ( 'should show named status filters, all checked by default' , ( ) => {
101+ it ( 'should show named status filters, all checked by default' , async ( ) => {
94102 const { getAllByRole, getByRole } = render (
95103 < TestableFilteredResults envelopes = { examplesTables as Envelope [ ] } />
96104 )
97105
98- expect ( getAllByRole ( 'checkbox' ) ) . to . have . length ( 3 )
99- expect ( getByRole ( 'checkbox' , { name : 'passed' } ) ) . to . be . visible
100- expect ( getByRole ( 'checkbox' , { name : 'failed' } ) ) . to . be . visible
101- expect ( getByRole ( 'checkbox' , { name : 'undefined' } ) ) . to . be . visible
102- getAllByRole ( 'checkbox' ) . forEach ( ( checkbox : HTMLInputElement ) => {
103- expect ( checkbox ) . to . be . checked
106+ await waitFor ( ( ) => {
107+ expect ( getAllByRole ( 'checkbox' ) ) . to . have . length ( 3 )
108+ expect ( getByRole ( 'checkbox' , { name : 'passed' } ) ) . to . be . visible
109+ expect ( getByRole ( 'checkbox' , { name : 'failed' } ) ) . to . be . visible
110+ expect ( getByRole ( 'checkbox' , { name : 'undefined' } ) ) . to . be . visible
111+ getAllByRole ( 'checkbox' ) . forEach ( ( checkbox : HTMLInputElement ) => {
112+ expect ( checkbox ) . to . be . checked
113+ } )
104114 } )
105- } )
106115
107- it ( 'should hide features with a certain status when we uncheck it' , async ( ) => {
108- const { getByRole, queryByRole } = render (
109- < TestableFilteredResults envelopes = { [ ...examplesTables , ...minimal ] as Envelope [ ] } />
110- )
116+ it ( 'should hide features with a certain status when we uncheck it' , async ( ) => {
117+ const { getByRole, queryByRole } = render (
118+ < TestableFilteredResults envelopes = { [ ...examplesTables , ...minimal ] as Envelope [ ] } />
119+ )
111120
112- expect ( getByRole ( 'heading' , { name : 'samples/examples-tables/examples-tables.feature' } ) ) . to
113- . be . visible
114- expect ( getByRole ( 'heading' , { name : 'samples/minimal/minimal.feature' } ) ) . to . be . visible
121+ await waitFor ( ( ) => {
122+ expect ( getByRole ( 'heading' , { name : 'samples/examples-tables/examples-tables.feature' } ) )
123+ . to . be . visible
124+ expect ( getByRole ( 'heading' , { name : 'samples/minimal/minimal.feature' } ) ) . to . be . visible
125+ } )
115126
116- await userEvent . click ( getByRole ( 'checkbox' , { name : 'passed' } ) )
127+ await userEvent . click ( getByRole ( 'checkbox' , { name : 'passed' } ) )
117128
118- expect ( getByRole ( 'heading' , { name : 'samples/examples-tables/examples-tables.feature' } ) ) . to
119- . be . visible
120- expect (
121- queryByRole ( 'heading' , {
122- name : 'samples/minimal/minimal.feature' ,
129+ await waitFor ( ( ) => {
130+ expect ( getByRole ( 'heading' , { name : 'samples/examples-tables/examples-tables.feature' } ) )
131+ . to . be . visible
132+ expect (
133+ queryByRole ( 'heading' , {
134+ name : 'samples/minimal/minimal.feature' ,
135+ } )
136+ ) . not . to . exist
123137 } )
124- ) . not . to . exist
125- } )
126-
127- it ( 'should show a message if we filter all statuses out' , async ( ) => {
128- const { getByRole, queryByRole, getByText } = render (
129- < TestableFilteredResults envelopes = { examplesTables as Envelope [ ] } />
130- )
138+ } )
131139
132- expect ( getByRole ( 'heading' , { name : 'samples/examples-tables/examples-tables.feature' } ) ) . to
133- . be . visible
140+ it ( 'should show a message if we filter all statuses out' , async ( ) => {
141+ const { getByRole, queryByRole, getByText } = render (
142+ < TestableFilteredResults envelopes = { examplesTables as Envelope [ ] } />
143+ )
134144
135- await userEvent . click ( getByRole ( 'checkbox' , { name : 'passed' } ) )
136- await userEvent . click ( getByRole ( 'checkbox' , { name : 'failed' } ) )
137- await userEvent . click ( getByRole ( 'checkbox' , { name : 'undefined' } ) )
145+ await waitFor ( ( ) => {
146+ expect ( getByRole ( 'heading' , { name : 'samples/examples-tables/examples-tables.feature' } ) )
147+ . to . be . visible
148+ } )
138149
139- expect (
140- queryByRole ( 'heading' , {
141- name : 'samples/examples-tables/examples-tables.feature' ,
150+ await userEvent . click ( getByRole ( 'checkbox' , { name : 'passed' } ) )
151+ await userEvent . click ( getByRole ( 'checkbox' , { name : 'failed' } ) )
152+ await userEvent . click ( getByRole ( 'checkbox' , { name : 'undefined' } ) )
153+
154+ await waitFor ( ( ) => {
155+ expect (
156+ queryByRole ( 'heading' , {
157+ name : 'samples/examples-tables/examples-tables.feature' ,
158+ } )
159+ ) . not . to . exist
160+ expect ( getByText ( 'No matches found for your filters' ) ) . to . be . visible
142161 } )
143- ) . not . to . exist
144- expect ( getByText ( 'No matches found for your filters' ) ) . to . be . visible
162+ } )
145163 } )
146164 } )
147165} )
0 commit comments