From 1e1ee544f004f5ec573e192512d06734735d23a6 Mon Sep 17 00:00:00 2001 From: Pablo Neves Machado Date: Wed, 2 Mar 2022 10:22:48 +0100 Subject: [PATCH] Fix copy and pasted renderer user_name test --- .../body/renderers/user_name.test.tsx | 81 +++++-------------- .../timeline/body/renderers/user_name.tsx | 2 +- 2 files changed, 19 insertions(+), 64 deletions(-) diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/user_name.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/user_name.test.tsx index d82e4c7d6719af..d81104ff5be039 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/user_name.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/user_name.test.tsx @@ -8,12 +8,12 @@ import React from 'react'; import { mount } from 'enzyme'; import { waitFor } from '@testing-library/react'; -import { HostName } from './host_name'; import { TestProviders } from '../../../../../common/mock'; import { TimelineId, TimelineTabs } from '../../../../../../common/types'; import { StatefulEventContext } from '../../../../../../../timelines/public'; import { timelineActions } from '../../../../store/timeline'; import { activeTimeline } from '../../../../containers/active_timeline_context'; +import { UserName } from './user_name'; jest.mock('react-redux', () => { const origin = jest.requireActual('react-redux'); @@ -51,14 +51,13 @@ jest.mock('../../../../store/timeline', () => { }; }); -// TODO USER NAME -describe('HostName', () => { +describe('UserName', () => { const props = { - fieldName: 'host.name', + fieldName: 'user.name', contextId: 'test-context-id', eventId: 'test-event-id', isDraggable: false, - value: 'Mock Host', + value: 'Mock User', }; let toggleExpandedDetail: jest.SpyInstance; @@ -70,16 +69,14 @@ describe('HostName', () => { afterEach(() => { toggleExpandedDetail.mockClear(); }); - test('should render host name', () => { + test('should render user name', () => { const wrapper = mount( - + ); - expect(wrapper.find('[data-test-subj="host-details-button"]').last().text()).toEqual( - props.value - ); + expect(wrapper.find('[data-test-subj="users-link-anchor"]').last().text()).toEqual(props.value); }); test('should render DefaultDraggable if isDraggable is true', () => { @@ -89,56 +86,14 @@ describe('HostName', () => { }; const wrapper = mount( - + ); expect(wrapper.find('[data-test-subj="DefaultDraggable"]').exists()).toEqual(true); }); - test('if not enableHostDetailsFlyout, should go to hostdetails page', async () => { - const wrapper = mount( - - - - ); - - wrapper.find('[data-test-subj="host-details-button"]').first().simulate('click'); - await waitFor(() => { - expect(timelineActions.toggleDetailPanel).not.toHaveBeenCalled(); - expect(toggleExpandedDetail).not.toHaveBeenCalled(); - }); - }); - - test('if enableHostDetailsFlyout, should open HostDetailsSidePanel', async () => { - const context = { - enableHostDetailsFlyout: true, - enableIpDetailsFlyout: true, - timelineID: TimelineId.active, - tabType: TimelineTabs.query, - }; - const wrapper = mount( - - - - - - ); - - wrapper.find('[data-test-subj="host-details-button"]').first().simulate('click'); - await waitFor(() => { - expect(timelineActions.toggleDetailPanel).toHaveBeenCalledWith({ - panelView: 'hostDetail', - params: { - hostName: props.value, - }, - tabType: context.tabType, - timelineId: context.timelineID, - }); - }); - }); - - test('if enableHostDetailsFlyout and timelineId equals to `timeline-1`, should call toggleExpandedDetail', async () => { + test('if timelineId equals to `timeline-1`, should call toggleExpandedDetail', async () => { const context = { enableHostDetailsFlyout: true, enableIpDetailsFlyout: true, @@ -148,23 +103,23 @@ describe('HostName', () => { const wrapper = mount( - + ); - wrapper.find('[data-test-subj="host-details-button"]').first().simulate('click'); + wrapper.find('[data-test-subj="users-link-anchor"]').first().simulate('click'); await waitFor(() => { expect(toggleExpandedDetail).toHaveBeenCalledWith({ - panelView: 'hostDetail', + panelView: 'userDetail', params: { - hostName: props.value, + userName: props.value, }, }); }); }); - test('if enableHostDetailsFlyout but timelineId not equals to `TimelineId.active`, should not call toggleExpandedDetail', async () => { + test('if timelineId not equals to `TimelineId.active`, should not call toggleExpandedDetail', async () => { const context = { enableHostDetailsFlyout: true, enableIpDetailsFlyout: true, @@ -174,17 +129,17 @@ describe('HostName', () => { const wrapper = mount( - + ); - wrapper.find('[data-test-subj="host-details-button"]').first().simulate('click'); + wrapper.find('[data-test-subj="users-link-anchor"]').first().simulate('click'); await waitFor(() => { expect(timelineActions.toggleDetailPanel).toHaveBeenCalledWith({ - panelView: 'hostDetail', + panelView: 'userDetail', params: { - hostName: props.value, + userName: props.value, }, tabType: context.tabType, timelineId: context.timelineID, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/user_name.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/user_name.tsx index fae2652284a6a1..61f62ee3c0e296 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/user_name.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/user_name.tsx @@ -83,7 +83,7 @@ const UserNameComponent: React.FC = ({ ); // The below is explicitly defined this way as the onClick takes precedence when it and the href are both defined - // When this component is used outside of timeline/alerts table (i.e. in the flyout) we would still like it to link to the Host Details page + // When this component is used outside of timeline/alerts table (i.e. in the flyout) we would still like it to link to the User Details page const content = useMemo( () => (