1
1
import { ReactNode } from 'react' ;
2
2
3
- import { ApiError } from '@equinor/subsurface-app-management' ;
4
- import { ApiRequestOptions } from '@equinor/subsurface-app-management/dist/api/core/ApiRequestOptions' ;
5
- import { ApiResult } from '@equinor/subsurface-app-management/dist/api/core/ApiResult' ;
6
3
import { faker } from '@faker-js/faker' ;
7
- import {
8
- QueryClient ,
9
- QueryClientProvider ,
10
- useQuery ,
11
- } from '@tanstack/react-query' ;
4
+ import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
12
5
13
6
import {
14
7
ShowSnackbar ,
@@ -17,26 +10,17 @@ import {
17
10
} from 'src/providers/SnackbarProvider/SnackbarProvider' ;
18
11
import { snackbarIcon } from 'src/providers/SnackbarProvider/SnackbarProvider.utils' ;
19
12
import {
20
- render ,
21
13
renderHook ,
22
14
screen ,
23
15
userEvent ,
24
16
waitFor ,
25
17
} from 'src/tests/browsertest-utils' ;
26
18
27
- function TestProviders ( {
28
- showAPIErrors = true ,
29
- children,
30
- } : {
31
- showAPIErrors ?: boolean ;
32
- children : ReactNode ;
33
- } ) {
19
+ function TestProviders ( { children } : { children : ReactNode } ) {
34
20
const queryClient = new QueryClient ( ) ;
35
21
return (
36
22
< QueryClientProvider client = { queryClient } >
37
- < SnackbarProvider showAPIErrors = { showAPIErrors } >
38
- { children }
39
- </ SnackbarProvider >
23
+ < SnackbarProvider > { children } </ SnackbarProvider >
40
24
</ QueryClientProvider >
41
25
) ;
42
26
}
@@ -205,63 +189,3 @@ test("'useSnackbar' hideSnackbar works as expected", async () => {
205
189
expect ( screen . queryByText ( snackbarText ) ) . not . toBeInTheDocument ( )
206
190
) ;
207
191
} ) ;
208
-
209
- function TestComponent ( {
210
- errorBody = false ,
211
- textBody = false ,
212
- } : {
213
- errorBody ?: boolean ;
214
- textBody ?: boolean ;
215
- } ) {
216
- useQuery ( {
217
- queryKey : [ 'somekey' ] ,
218
- queryFn : async ( ) => {
219
- return new Promise ( ( _ , reject ) => {
220
- const options : ApiRequestOptions = {
221
- method : 'GET' ,
222
- url : '/some-random-url' ,
223
- } ;
224
- const result : ApiResult = {
225
- body : errorBody
226
- ? textBody
227
- ? 'text error'
228
- : { userMessage : 'Body error' }
229
- : { } ,
230
- ok : false ,
231
- status : 500 ,
232
- statusText : '' ,
233
- url : '' ,
234
- } ;
235
- reject ( new ApiError ( options , result , 'API error' ) ) ;
236
- } ) ;
237
- } ,
238
- retry : false ,
239
- } ) ;
240
-
241
- return < p > this is the page</ p > ;
242
- }
243
-
244
- test ( 'Shows error snackbar when API error happens without error body' , async ( ) => {
245
- render ( < TestComponent /> , { wrapper : TestProviders } ) ;
246
- await waitFor ( ( ) => screen . getByText ( '500: API error' ) , { timeout : 2000 } ) ;
247
- } ) ;
248
-
249
- test ( 'Shows error snackbar when API error happens with error body as object' , async ( ) => {
250
- render ( < TestComponent errorBody /> , { wrapper : TestProviders } ) ;
251
- await waitFor ( ( ) => screen . getByText ( '500: Body error' ) , { timeout : 2000 } ) ;
252
- } ) ;
253
-
254
- test ( 'Shows error snackbar when API error happens with error body as text' , async ( ) => {
255
- render ( < TestComponent errorBody textBody /> , { wrapper : TestProviders } ) ;
256
- await waitFor ( ( ) => screen . getByText ( '500: text error' ) , { timeout : 2000 } ) ;
257
- } ) ;
258
-
259
- test ( "Doesn't show api error snackbar if its disabled" , async ( ) => {
260
- render ( < TestComponent /> , {
261
- wrapper : ( { children } ) => (
262
- < TestProviders showAPIErrors = { false } > { children } </ TestProviders >
263
- ) ,
264
- } ) ;
265
-
266
- expect ( screen . queryByText ( '500: API error' ) ) . not . toBeInTheDocument ( ) ;
267
- } ) ;
0 commit comments