Skip to content

Commit

Permalink
[Security Solution][Endpoint] Trim Activity Log comments (#111163)
Browse files Browse the repository at this point in the history
* trim comments so empty comments do not show up

fixes /issues/111106

* not exclusive test

* update test to be more specific

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
ashokaditya and kibanamachine authored Sep 6, 2021
1 parent 02a6eeb commit 2e2b451
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const useLogEntryUIProps = (
if (logEntry.type === 'action') {
avatarSize = 'm';
commentType = 'regular';
commentText = logEntry.item.data.data.comment ?? '';
commentText = logEntry.item.data.data.comment?.trim() ?? '';
displayResponseEvent = false;
iconType = 'lockOpen';
username = logEntry.item.data.user_id;
Expand All @@ -55,7 +55,7 @@ const useLogEntryUIProps = (
iconType = 'lock';
isIsolateAction = true;
}
if (data.comment) {
if (commentText) {
displayComment = true;
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ export const LogEntry = memo(({ logEntry }: { logEntry: Immutable<ActivityLogEnt
data-test-subj="timelineEntry"
>
{displayComment ? (
<EuiText size="s">
<EuiText size="s" data-test-subj="activityLogCommentText">
<p>{commentText}</p>
</EuiText>
) : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,15 @@ describe('when on the endpoint list page', () => {
});
const actionData = fleetActionGenerator.generate({
agents: [agentId],
data: {
comment: 'some comment',
},
});
const isolatedActionData = fleetActionGenerator.generateIsolateAction({
agents: [agentId],
data: {
comment: ' ', // has space for comment,
},
});

getMockData = () => ({
Expand All @@ -854,6 +863,13 @@ describe('when on the endpoint list page', () => {
data: actionData,
},
},
{
type: 'action',
item: {
id: 'some_id_3',
data: isolatedActionData,
},
},
],
});

Expand Down Expand Up @@ -890,7 +906,7 @@ describe('when on the endpoint list page', () => {
dispatchEndpointDetailsActivityLogChanged('success', getMockData());
});
const logEntries = await renderResult.queryAllByTestId('timelineEntry');
expect(logEntries.length).toEqual(2);
expect(logEntries.length).toEqual(3);
expect(`${logEntries[0]} .euiCommentTimeline__icon--update`).not.toBe(null);
expect(`${logEntries[1]} .euiCommentTimeline__icon--regular`).not.toBe(null);
});
Expand Down Expand Up @@ -947,7 +963,7 @@ describe('when on the endpoint list page', () => {
dispatchEndpointDetailsActivityLogChanged('success', getMockData());
});
const logEntries = await renderResult.queryAllByTestId('timelineEntry');
expect(logEntries.length).toEqual(2);
expect(logEntries.length).toEqual(3);
});

it('should display a callout message if no log data', async () => {
Expand Down Expand Up @@ -975,6 +991,29 @@ describe('when on the endpoint list page', () => {
const activityLogCallout = await renderResult.findByTestId('activityLogNoDataCallout');
expect(activityLogCallout).not.toBeNull();
});

it('should correctly display non-empty comments only for actions', async () => {
const userChangedUrlChecker = middlewareSpy.waitForAction('userChangedUrl');
reactTestingLibrary.act(() => {
history.push(
`${MANAGEMENT_PATH}/endpoints?page_index=0&page_size=10&selected_endpoint=1&show=activity_log`
);
});
const changedUrlAction = await userChangedUrlChecker;
expect(changedUrlAction.payload.search).toEqual(
'?page_index=0&page_size=10&selected_endpoint=1&show=activity_log'
);
await middlewareSpy.waitForAction('endpointDetailsActivityLogChanged');
reactTestingLibrary.act(() => {
dispatchEndpointDetailsActivityLogChanged('success', getMockData());
});
const commentTexts = await renderResult.queryAllByTestId('activityLogCommentText');
expect(commentTexts.length).toEqual(1);
expect(commentTexts[0].textContent).toEqual('some comment');
expect(commentTexts[0].parentElement?.parentElement?.className).toContain(
'euiCommentEvent--regular'
);
});
});

describe('when showing host Policy Response panel', () => {
Expand Down

0 comments on commit 2e2b451

Please sign in to comment.