1
1
import { Envelope } from '@cucumber/messages'
2
- import { render } from '@testing-library/react'
2
+ import { render , waitFor } from '@testing-library/react'
3
3
import { userEvent } from '@testing-library/user-event'
4
4
import { expect } from 'chai'
5
5
import React , { VoidFunctionComponent } from 'react'
@@ -26,26 +26,28 @@ describe('FilteredResults', () => {
26
26
}
27
27
28
28
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 ( ) => {
30
30
const { getByRole, queryByRole } = render (
31
31
< TestableFilteredResults envelopes = { targetedRun as Envelope [ ] } />
32
32
)
33
33
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
+ } )
49
51
} )
50
52
} )
51
53
@@ -55,10 +57,14 @@ describe('FilteredResults', () => {
55
57
< TestableFilteredResults envelopes = { attachments as Envelope [ ] } />
56
58
)
57
59
60
+ await waitFor ( ( ) => getByText ( 'samples/attachments/attachments.feature' ) )
61
+
58
62
await userEvent . type ( getByRole ( 'textbox' , { name : 'Search' } ) , 'nope!' )
59
63
await userEvent . keyboard ( '{Enter}' )
60
64
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
+ } )
62
68
} )
63
69
64
70
it ( 'narrows the results with a valid search term, and restores when we clear the search' , async ( ) => {
@@ -84,64 +90,76 @@ describe('FilteredResults', () => {
84
90
} )
85
91
86
92
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 ( ) => {
88
94
const { queryByRole } = render ( < TestableFilteredResults envelopes = { minimal as Envelope [ ] } /> )
89
95
90
- expect ( queryByRole ( 'checkbox' ) ) . not . to . exist
96
+ await waitFor ( ( ) => {
97
+ expect ( queryByRole ( 'checkbox' ) ) . not . to . exist
98
+ } )
91
99
} )
92
100
93
- it ( 'should show named status filters, all checked by default' , ( ) => {
101
+ it ( 'should show named status filters, all checked by default' , async ( ) => {
94
102
const { getAllByRole, getByRole } = render (
95
103
< TestableFilteredResults envelopes = { examplesTables as Envelope [ ] } />
96
104
)
97
105
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
+ } )
104
114
} )
105
- } )
106
115
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
+ )
111
120
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
+ } )
115
126
116
- await userEvent . click ( getByRole ( 'checkbox' , { name : 'passed' } ) )
127
+ await userEvent . click ( getByRole ( 'checkbox' , { name : 'passed' } ) )
117
128
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
123
137
} )
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
+ } )
131
139
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
+ )
134
144
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
+ } )
138
149
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
142
161
} )
143
- ) . not . to . exist
144
- expect ( getByText ( 'No matches found for your filters' ) ) . to . be . visible
162
+ } )
145
163
} )
146
164
} )
147
165
} )
0 commit comments