1
1
import { QueryClient , QueryClientProvider } from '@tanstack/react-query'
2
+ import {
3
+ QueryClientProvider as QueryClientProviderV5 ,
4
+ QueryClient as QueryClientV5 ,
5
+ } from '@tanstack/react-queryV5'
2
6
import { render , screen , waitFor } from '@testing-library/react'
3
7
import userEvent from '@testing-library/user-event'
4
8
import { graphql , HttpResponse } from 'msw'
@@ -8,44 +12,60 @@ import { MemoryRouter, Route } from 'react-router-dom'
8
12
9
13
import { OktaConfigForm } from './OktaConfigForm'
10
14
15
+ const oktaConfigMock = ( isEnabled : boolean , isEnforced : boolean ) => ( {
16
+ enabled : isEnabled ,
17
+ enforced : isEnforced ,
18
+ url : 'https://okta.com' ,
19
+ clientId : 'clientId' ,
20
+ clientSecret : 'clientSecret' ,
21
+ } )
22
+
11
23
const queryClient = new QueryClient ( {
12
24
defaultOptions : { queries : { retry : false } } ,
13
25
} )
14
- const server = setupServer ( )
26
+ const queryClientV5 = new QueryClientV5 ( {
27
+ defaultOptions : { queries : { retry : false } } ,
28
+ } )
29
+
30
+ const wrapper : React . FC < React . PropsWithChildren > = ( { children } ) => (
31
+ < QueryClientProviderV5 client = { queryClientV5 } >
32
+ < QueryClientProvider client = { queryClient } >
33
+ < MemoryRouter initialEntries = { [ '/account/gh/codecov/okta-access/' ] } >
34
+ < Route path = "/account/:provider/:owner/okta-access/" >
35
+ < Suspense fallback = { null } > { children } </ Suspense >
36
+ </ Route >
37
+ </ MemoryRouter >
38
+ </ QueryClientProvider >
39
+ </ QueryClientProviderV5 >
40
+ )
15
41
42
+ const server = setupServer ( )
16
43
beforeAll ( ( ) => {
17
44
server . listen ( )
18
45
} )
19
46
20
47
afterEach ( ( ) => {
21
48
queryClient . clear ( )
49
+ queryClientV5 . clear ( )
22
50
server . resetHandlers ( )
23
51
} )
24
52
25
53
afterAll ( ( ) => {
26
54
server . close ( )
27
55
} )
28
56
29
- const oktaConfigMock = {
30
- enabled : true ,
31
- enforced : true ,
32
- url : 'https://okta.com' ,
33
- clientId : 'clientId' ,
34
- clientSecret : 'clientSecret' ,
57
+ interface SetupArgs {
58
+ isEnabled ?: boolean
59
+ isEnforced ?: boolean
35
60
}
36
61
37
- const wrapper : React . FC < React . PropsWithChildren > = ( { children } ) => (
38
- < QueryClientProvider client = { queryClient } >
39
- < MemoryRouter initialEntries = { [ '/account/gh/codecov/okta-access/' ] } >
40
- < Route path = "/account/:provider/:owner/okta-access/" >
41
- < Suspense fallback = { null } > { children } </ Suspense >
42
- </ Route >
43
- </ MemoryRouter >
44
- </ QueryClientProvider >
45
- )
46
-
47
62
describe ( 'OktaConfigForm' , ( ) => {
48
- function setup ( ) {
63
+ function setup (
64
+ { isEnabled = true , isEnforced = true } : SetupArgs = {
65
+ isEnabled : true ,
66
+ isEnforced : true ,
67
+ }
68
+ ) {
49
69
const user = userEvent . setup ( )
50
70
const mutate = vi . fn ( )
51
71
@@ -56,7 +76,7 @@ describe('OktaConfigForm', () => {
56
76
owner : {
57
77
isUserOktaAuthenticated : true ,
58
78
account : {
59
- oktaConfig : oktaConfigMock ,
79
+ oktaConfig : oktaConfigMock ( isEnabled , isEnforced ) ,
60
80
} ,
61
81
} ,
62
82
} ,
@@ -180,7 +200,7 @@ describe('OktaConfigForm', () => {
180
200
} )
181
201
182
202
it ( 'should toggle Okta Sync Enabled on' , async ( ) => {
183
- const { user } = setup ( )
203
+ const { user } = setup ( { isEnabled : false , isEnforced : false } )
184
204
render ( < OktaConfigForm /> , { wrapper } )
185
205
186
206
const oktaSyncEnabledToggle = await screen . findByRole ( 'button' , {
@@ -190,11 +210,13 @@ describe('OktaConfigForm', () => {
190
210
expect ( oktaSyncEnabledToggle ) . toHaveClass ( 'bg-toggle-inactive' )
191
211
192
212
await user . click ( oktaSyncEnabledToggle )
193
- expect ( oktaSyncEnabledToggle ) . toHaveClass ( 'bg-toggle-active' )
213
+ await waitFor ( ( ) =>
214
+ expect ( oktaSyncEnabledToggle ) . toHaveClass ( 'bg-toggle-active' )
215
+ )
194
216
} )
195
217
196
218
it ( 'should toggle Okta Login Enforce on' , async ( ) => {
197
- const { user } = setup ( )
219
+ const { user } = setup ( { isEnabled : false , isEnforced : false } )
198
220
render ( < OktaConfigForm /> , { wrapper } )
199
221
200
222
const oktaLoginEnforceToggle = await screen . findByRole ( 'button' , {
@@ -204,11 +226,13 @@ describe('OktaConfigForm', () => {
204
226
expect ( oktaLoginEnforceToggle ) . toHaveClass ( 'bg-toggle-inactive' )
205
227
206
228
await user . click ( oktaLoginEnforceToggle )
207
- expect ( oktaLoginEnforceToggle ) . toHaveClass ( 'bg-toggle-active' )
229
+ await waitFor ( ( ) =>
230
+ expect ( oktaLoginEnforceToggle ) . toHaveClass ( 'bg-toggle-active' )
231
+ )
208
232
} )
209
233
210
234
it ( 'toggles enabled on when enforced is on' , async ( ) => {
211
- const { user } = setup ( )
235
+ const { user } = setup ( { isEnabled : false , isEnforced : false } )
212
236
render ( < OktaConfigForm /> , { wrapper } )
213
237
214
238
const oktaLoginEnforceToggle = await screen . findByRole ( 'button' , {
@@ -226,7 +250,7 @@ describe('OktaConfigForm', () => {
226
250
} )
227
251
228
252
it ( 'disables enforce toggle when enabled is off' , async ( ) => {
229
- const { user } = setup ( )
253
+ const { user } = setup ( { isEnabled : false , isEnforced : false } )
230
254
render ( < OktaConfigForm /> , { wrapper } )
231
255
232
256
const oktaSyncEnabledToggle = await screen . findByRole ( 'button' , {
@@ -299,9 +323,7 @@ describe('OktaConfigForm', () => {
299
323
const oktaSyncEnabledToggle = await screen . findByRole ( 'button' , {
300
324
name : / O k t a S y n c E n a b l e d / ,
301
325
} )
302
- await waitFor ( ( ) => {
303
- expect ( oktaSyncEnabledToggle ) . toHaveClass ( 'bg-toggle-inactive' )
304
- } )
326
+ expect ( oktaSyncEnabledToggle ) . toHaveClass ( 'bg-toggle-active' )
305
327
} )
306
328
307
329
it ( 'renders default values for Okta Login Enforce toggle' , async ( ) => {
@@ -312,7 +334,7 @@ describe('OktaConfigForm', () => {
312
334
name : / O k t a L o g i n E n f o r c e d / ,
313
335
} )
314
336
await waitFor ( ( ) => {
315
- expect ( oktaLoginEnforceToggle ) . toHaveClass ( 'bg-toggle-inactive ' )
337
+ expect ( oktaLoginEnforceToggle ) . toHaveClass ( 'bg-toggle-active ' )
316
338
} )
317
339
} )
318
340
} )
0 commit comments