Skip to content

Commit

Permalink
Fix process tree node exit_code condition (elastic#77)
Browse files Browse the repository at this point in the history
* Fix process tree node exit_code condition

* Fix typo
  • Loading branch information
zizhouW authored Feb 24, 2022
1 parent 659edcd commit 4f7f7f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import {
childProcessMock,
sessionViewAlertProcessMock,
} from '../../../common/mocks/constants/session_view_process.mock';
import {
EventKind,
EventAction,
ProcessFields,
ProcessEvent,
} from '../../../common/types/process_tree';
import { AppContextTestRender, createAppRootMockRenderer } from '../../test';
import { ProcessTreeNode } from './index';

Expand Down Expand Up @@ -56,7 +62,7 @@ describe('ProcessTreeNode component', () => {
expect(renderResult.queryByTestId('sessionView:processTreeNodeUserIcon')).toBeTruthy();
});

it('renders Exec icon for executed process', async () => {
it('renders Exec icon and exit code for executed process', async () => {
const executedProcessMock: typeof processMock = {
...processMock,
hasExec: () => true,
Expand All @@ -65,6 +71,24 @@ describe('ProcessTreeNode component', () => {
renderResult = mockedContext.render(<ProcessTreeNode process={executedProcessMock} />);

expect(renderResult.queryByTestId('sessionView:processTreeNodeExecIcon')).toBeTruthy();
expect(renderResult.queryByTestId('sessionView:processTreeNodeExitCode')).toBeTruthy();
});

it('does not render exit code if it does not exist', async () => {
const processWithoutExitCode: typeof processMock = {
...processMock,
hasExec: () => true,
getDetails: () => ({
...processMock.getDetails(),
process: {
...processMock.getDetails().process,
exit_code: undefined,
},
}),
};

renderResult = mockedContext.render(<ProcessTreeNode process={processWithoutExitCode} />);
expect(renderResult.queryByTestId('sessionView:processTreeNodeExitCode')).toBeFalsy();
});

it('renders Root Escalation flag properly', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ export function ProcessTreeNode({
<span css={styles.workingDir}>{workingDirectory}</span>&nbsp;
<span css={styles.darkText}>{args[0]}</span>&nbsp;
{args.slice(1).join(' ')}
{exitCode && <small> [exit_code: {exitCode}]</small>}
{exitCode !== undefined && (
<small data-test-subj="sessionView:processTreeNodeExitCode">
{' '}
[exit_code: {exitCode}]
</small>
)}
</span>
);
} else {
Expand Down

0 comments on commit 4f7f7f5

Please sign in to comment.