diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/job_switch.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/job_switch.test.tsx index 69a029956e8e2..844d346405e0e 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/job_switch.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/job_switch.test.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { shallow } from 'enzyme'; +import { shallow, mount } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; @@ -12,6 +12,11 @@ import { isChecked, isFailure, isJobLoading, JobSwitch } from './job_switch'; import { mockOpenedJob } from '../__mocks__/api'; describe('JobSwitch', () => { + let onJobStateChangeMock = jest.fn(); + beforeEach(() => { + onJobStateChangeMock = jest.fn(); + }); + test('renders correctly against snapshot', () => { const wrapper = shallow( @@ -19,6 +24,51 @@ describe('JobSwitch', () => { expect(toJson(wrapper)).toMatchSnapshot(); }); + test('should call onJobStateChange when the switch is clicked to be true/open', () => { + const wrapper = mount( + + ); + + wrapper + .find('[data-test-subj="job-switch"] input') + .first() + .simulate('change', { + target: { checked: true }, + }); + + expect(onJobStateChangeMock.mock.calls[0]).toEqual([ + 'siem-api-rare_process_linux_ecs', + 1562870521264, + true, + ]); + }); + + test('should have a switch when it is not in the loading state', () => { + const wrapper = mount( + + ); + expect(wrapper.find('[data-test-subj="job-switch"]').exists()).toBe(true); + }); + + test('should not have a switch when it is in the loading state', () => { + const wrapper = mount( + + ); + expect(wrapper.find('[data-test-subj="job-switch"]').exists()).toBe(false); + }); + describe('isChecked', () => { test('returns false if only jobState is enabled', () => { expect(isChecked('started', 'closing')).toBe(false); diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/jobs_table.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/jobs_table.test.tsx index 23763896ea90e..932dad267e3fa 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/jobs_table.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/jobs_table.test.tsx @@ -4,14 +4,18 @@ * you may not use this file except in compliance with the Elastic License. */ -import { shallow } from 'enzyme'; +import { shallow, mount } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; import { JobsTable } from './jobs_table'; import { mockJobsSummaryResponse } from '../__mocks__/api'; +import { cloneDeep } from 'lodash/fp'; describe('JobsTable', () => { - const onJobStateChangeMock = jest.fn(); + let onJobStateChangeMock = jest.fn(); + beforeEach(() => { + onJobStateChangeMock = jest.fn(); + }); test('renders correctly against snapshot', () => { const wrapper = shallow( @@ -23,4 +27,81 @@ describe('JobsTable', () => { ); expect(toJson(wrapper)).toMatchSnapshot(); }); + + test('should render the hyperlink which points specifically to the job id', () => { + const wrapper = mount( + + ); + expect( + wrapper + .find('[data-test-subj="jobs-table-link"]') + .first() + .props().href + ).toEqual('/test/base/path/app/ml#/jobs?mlManagement=(jobId:rc-rare-process-windows-5)'); + }); + + test('should render the hyperlink with URI encodings which points specifically to the job id', () => { + const cloneJobsSummaryResponse = cloneDeep(mockJobsSummaryResponse); + cloneJobsSummaryResponse[0].id = 'job id with spaces'; + const wrapper = mount( + + ); + expect( + wrapper + .find('[data-test-subj="jobs-table-link"]') + .first() + .props().href + ).toEqual('/test/base/path/app/ml#/jobs?mlManagement=(jobId:job%20id%20with%20spaces)'); + }); + + test('should call onJobStateChange when the switch is clicked to be true/open', () => { + const wrapper = mount( + + ); + wrapper + .find('[data-test-subj="job-switch"] input') + .first() + .simulate('change', { + target: { checked: true }, + }); + expect(onJobStateChangeMock.mock.calls[0]).toEqual([ + 'rc-rare-process-windows-5', + 1561402325194, + true, + ]); + }); + + test('should have a switch when it is not in the loading state', () => { + const wrapper = mount( + + ); + expect(wrapper.find('[data-test-subj="job-switch"]').exists()).toBe(true); + }); + + test('should not have a switch when it is in the loading state', () => { + const wrapper = mount( + + ); + expect(wrapper.find('[data-test-subj="job-switch"]').exists()).toBe(false); + }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/jobs_table.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/jobs_table.tsx index 9ce5e9fbdf362..1cd429f92b6a9 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/jobs_table.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/jobs_table/jobs_table.tsx @@ -38,7 +38,11 @@ const getJobsTableColumns = ( name: i18n.COLUMN_JOB_NAME, render: ({ id, description }: Job) => ( - + {id}