Test callout behavior with different API responses

This commit is contained in:
Ryland Herrick 2021-03-11 20:33:19 -06:00
parent 5d095d1896
commit 1db3d4e859

View file

@ -7,11 +7,19 @@
import { mount } from 'enzyme';
import React from 'react';
import { MlJobCompatibilityCallout } from './index';
import { TestProviders } from '../../../../common/mock';
import { useInstalledSecurityJobs } from '../../../../common/components/ml/hooks/use_installed_security_jobs';
import { MlJobCompatibilityCallout } from './index';
jest.mock('../../../../common/components/ml/hooks/use_installed_security_jobs');
describe('MlJobCompatibilityCallout', () => {
it('renders when v2 jobs are installed', () => {
it('renders when new affected jobs are installed', () => {
(useInstalledSecurityJobs as jest.Mock).mockReturnValue({
loading: false,
jobs: [{ id: 'v2_linux_rare_metadata_process' }],
});
const wrapper = mount(
<TestProviders>
<MlJobCompatibilityCallout />
@ -20,7 +28,24 @@ describe('MlJobCompatibilityCallout', () => {
expect(wrapper.exists('[data-test-subj="callout-ml-job-compatibility"]')).toEqual(true);
});
it('does not render if no v2 jobs are installed', () => {
it('renders when old affected jobs are installed', () => {
(useInstalledSecurityJobs as jest.Mock).mockReturnValue({
loading: false,
jobs: [{ id: 'linux_rare_metadata_process' }],
});
const wrapper = mount(
<TestProviders>
<MlJobCompatibilityCallout />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-ml-job-compatibility"]')).toEqual(true);
});
it('does not render if no affected jobs are installed', () => {
(useInstalledSecurityJobs as jest.Mock).mockReturnValue({
loading: false,
jobs: [{ id: 'windows_rare_user_type10_remote_login' }],
});
const wrapper = mount(
<TestProviders>
<MlJobCompatibilityCallout />
@ -30,6 +55,10 @@ describe('MlJobCompatibilityCallout', () => {
});
it('does not render while jobs are loading', () => {
(useInstalledSecurityJobs as jest.Mock).mockReturnValue({
loading: true,
jobs: [],
});
const wrapper = mount(
<TestProviders>
<MlJobCompatibilityCallout />