Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copied and pasted renderer user_name test #126663

Merged
merged 5 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand All @@ -70,16 +69,14 @@ describe('HostName', () => {
afterEach(() => {
toggleExpandedDetail.mockClear();
});
test('should render host name', () => {
test('should render user name', () => {
const wrapper = mount(
<TestProviders>
<HostName {...props} />
<UserName {...props} />
</TestProviders>
);

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', () => {
Expand All @@ -89,56 +86,14 @@ describe('HostName', () => {
};
const wrapper = mount(
<TestProviders>
<HostName {...testProps} />
<UserName {...testProps} />
</TestProviders>
);

expect(wrapper.find('[data-test-subj="DefaultDraggable"]').exists()).toEqual(true);
});

test('if not enableHostDetailsFlyout, should go to hostdetails page', async () => {
const wrapper = mount(
<TestProviders>
<HostName {...props} />
</TestProviders>
);

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(
<TestProviders>
<StatefulEventContext.Provider value={context}>
<HostName {...props} />
</StatefulEventContext.Provider>
</TestProviders>
);

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,
Expand All @@ -148,23 +103,23 @@ describe('HostName', () => {
const wrapper = mount(
<TestProviders>
<StatefulEventContext.Provider value={context}>
<HostName {...props} />
<UserName {...props} />
</StatefulEventContext.Provider>
</TestProviders>
);

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,
Expand All @@ -174,17 +129,17 @@ describe('HostName', () => {
const wrapper = mount(
<TestProviders>
<StatefulEventContext.Provider value={context}>
<HostName {...props} />
<UserName {...props} />
</StatefulEventContext.Provider>
</TestProviders>
);

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const UserNameComponent: React.FC<Props> = ({
);

// 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(
() => (
<UserDetailsLink
Expand Down