66
77import { shallow , mount } from 'enzyme' ;
88import React from 'react' ;
9- import { render , waitForElement , waitFor } from '@testing-library/react' ;
9+ import { render , waitFor } from '@testing-library/react' ;
1010import { JobsTableComponent } from './jobs_table' ;
1111import { mockSecurityJobs } from '../api.mock' ;
1212import { cloneDeep } from 'lodash/fp' ;
1313import { SecurityJob } from '../types' ;
14- import { createKibanaContextProviderMock } from '../../../lib/kibana/kibana_react.mock' ;
1514
1615jest . mock ( '../../../lib/kibana' ) ;
1716
18- const MockKibanaContextProvider = createKibanaContextProviderMock ( ) ;
19-
2017export async function getRenderedHref ( Component : React . FC , selector : string ) {
21- const el = render (
22- < MockKibanaContextProvider >
23- < Component />
24- </ MockKibanaContextProvider >
25- ) ;
18+ const el = render ( < Component /> ) ;
2619
27- await waitForElement ( ( ) => el . container . querySelector ( selector ) ) ;
20+ await waitFor ( ( ) => el . container . querySelector ( selector ) ) ;
2821
2922 const a = el . container . querySelector ( selector ) ;
30- return a ? a . getAttribute ( 'href' ) : '' ;
23+ return a ? .getAttribute ( 'href' ) ?? '' ;
3124}
3225
3326describe ( 'JobsTableComponent' , ( ) => {
@@ -61,7 +54,9 @@ describe('JobsTableComponent', () => {
6154 ) ,
6255 '[data-test-subj="jobs-table-link"]'
6356 ) ;
64- expect ( href ) . toEqual ( '/app/ml/jobs?mlManagement=(jobId:linux_anomalous_network_activity_ecs)' ) ;
57+ await waitFor ( ( ) =>
58+ expect ( href ) . toEqual ( '/app/ml/jobs?mlManagement=(jobId:linux_anomalous_network_activity_ecs)' )
59+ ) ;
6560 } ) ;
6661
6762 test ( 'should render the hyperlink with URI encodings which points specifically to the job id' , async ( ) => {
@@ -76,7 +71,9 @@ describe('JobsTableComponent', () => {
7671 ) ,
7772 '[data-test-subj="jobs-table-link"]'
7873 ) ;
79- expect ( href ) . toEqual ( "/app/ml/jobs?mlManagement=(jobId:'job%20id%20with%20spaces')" ) ;
74+ await waitFor ( ( ) =>
75+ expect ( href ) . toEqual ( "/app/ml/jobs?mlManagement=(jobId:'job%20id%20with%20spaces')" )
76+ ) ;
8077 } ) ;
8178
8279 test ( 'should call onJobStateChange when the switch is clicked to be true/open' , async ( ) => {
@@ -99,25 +96,29 @@ describe('JobsTableComponent', () => {
9996 } ) ;
10097 } ) ;
10198
102- test ( 'should have a switch when it is not in the loading state' , ( ) => {
99+ test ( 'should have a switch when it is not in the loading state' , async ( ) => {
103100 const wrapper = mount (
104101 < JobsTableComponent
105102 isLoading = { false }
106103 jobs = { securityJobs }
107104 onJobStateChange = { onJobStateChangeMock }
108105 />
109106 ) ;
110- expect ( wrapper . find ( '[data-test-subj="job-switch"]' ) . exists ( ) ) . toBe ( true ) ;
107+ await waitFor ( ( ) => {
108+ expect ( wrapper . find ( '[data-test-subj="job-switch"]' ) . exists ( ) ) . toBe ( true ) ;
109+ } ) ;
111110 } ) ;
112111
113- test ( 'should not have a switch when it is in the loading state' , ( ) => {
112+ test ( 'should not have a switch when it is in the loading state' , async ( ) => {
114113 const wrapper = mount (
115114 < JobsTableComponent
116115 isLoading = { true }
117116 jobs = { securityJobs }
118117 onJobStateChange = { onJobStateChangeMock }
119118 />
120119 ) ;
121- expect ( wrapper . find ( '[data-test-subj="job-switch"]' ) . exists ( ) ) . toBe ( false ) ;
120+ await waitFor ( ( ) => {
121+ expect ( wrapper . find ( '[data-test-subj="job-switch"]' ) . exists ( ) ) . toBe ( false ) ;
122+ } ) ;
122123 } ) ;
123124} ) ;
0 commit comments