Skip to content

Commit 1c390c1

Browse files
committed
[ML] Fix warnings for jobs_table.test.tsx
1 parent 5e09d95 commit 1c390c1

File tree

1 file changed

+18
-17
lines changed
  • x-pack/plugins/security_solution/public/common/components/ml_popover/jobs_table

1 file changed

+18
-17
lines changed

x-pack/plugins/security_solution/public/common/components/ml_popover/jobs_table/jobs_table.test.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,21 @@
66

77
import { shallow, mount } from 'enzyme';
88
import React from 'react';
9-
import { render, waitForElement, waitFor } from '@testing-library/react';
9+
import { render, waitFor } from '@testing-library/react';
1010
import { JobsTableComponent } from './jobs_table';
1111
import { mockSecurityJobs } from '../api.mock';
1212
import { cloneDeep } from 'lodash/fp';
1313
import { SecurityJob } from '../types';
14-
import { createKibanaContextProviderMock } from '../../../lib/kibana/kibana_react.mock';
1514

1615
jest.mock('../../../lib/kibana');
1716

18-
const MockKibanaContextProvider = createKibanaContextProviderMock();
19-
2017
export 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

3326
describe('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

Comments
 (0)