[Security Solution][Endpoint] Trim Activity Log comments (#111163)

* trim comments so empty comments do not show up

fixes elastic/kibana/issues/111106

* not exclusive test

* update test to be more specific

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Ashokaditya 2021-09-06 14:15:53 +02:00 committed by GitHub
parent 02a6eeb69f
commit 2e2b451162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 5 deletions

View file

@ -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;
@ -55,7 +55,7 @@ const useLogEntryUIProps = (
iconType = 'lock';
isIsolateAction = true;
}
if (data.comment) {
if (commentText) {
displayComment = true;
}
}
@ -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}

View file

@ -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 = () => ({
@ -854,6 +863,13 @@ describe('when on the endpoint list page', () => {
data: actionData,
},
},
{
type: 'action',
item: {
id: 'some_id_3',
data: isolatedActionData,
},
},
],
});
@ -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);
});
@ -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 () => {
@ -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', () => {