-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Endpoint] Add an additional hint message for Cons…
…ole commands pending more than 15s (#135500) * Add `enteredAt` to CommandHistoryItem and some refactoring in `handleExecuteCommand` * New components: ConsoleText + LongRunningCommandHint * Adds logic to display the Long running command hint to the execution output * use ConsoleText in command execution result * Fix type issue * tests for logic around showing long running command hint * Apply suggestions from code review From Ash Co-authored-by: Ashokaditya <1849116+ashokaditya@users.noreply.github.com> Co-authored-by: Ashokaditya <1849116+ashokaditya@users.noreply.github.com> Co-authored-by: Kevin Logan <kevin.logan@elastic.co>
- Loading branch information
1 parent
741f8b2
commit 092c8e1
Showing
7 changed files
with
370 additions
and
168 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...olution/public/management/components/console/components/command_execution_output.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { ConsoleProps } from '..'; | ||
import { AppContextTestRender } from '../../../../common/mock/endpoint'; | ||
import { getConsoleTestSetup } from '../mocks'; | ||
import { act } from '@testing-library/react'; | ||
import { CommandExecutionComponentProps } from '../types'; | ||
|
||
describe('When using CommandExecutionOutput component', () => { | ||
let render: (props?: Partial<ConsoleProps>) => ReturnType<AppContextTestRender['render']>; | ||
let renderResult: ReturnType<typeof render>; | ||
let setCmd1ToComplete: () => void; | ||
|
||
beforeEach(() => { | ||
const { renderConsole, commands, enterCommand } = getConsoleTestSetup(); | ||
|
||
const cmd1 = commands.find((command) => command.name === 'cmd1'); | ||
|
||
if (!cmd1) { | ||
throw new Error('cmd1 command not found in test mocks'); | ||
} | ||
|
||
(cmd1.RenderComponent as jest.Mock).mockImplementation( | ||
(props: CommandExecutionComponentProps) => { | ||
setCmd1ToComplete = () => props.setStatus('success'); | ||
|
||
return <div>{'output'}</div>; | ||
} | ||
); | ||
|
||
render = (props = {}) => { | ||
renderResult = renderConsole(props); | ||
enterCommand('cmd1'); | ||
return renderResult; | ||
}; | ||
}); | ||
|
||
it('should show long running hint message if pending and >15s have passed', () => { | ||
jest.useFakeTimers(); | ||
render(); | ||
|
||
expect(renderResult.queryByTestId('test-longRunningCommandHint')).toBeNull(); | ||
|
||
act(() => { | ||
jest.advanceTimersByTime(16 * 1000); | ||
}); | ||
|
||
expect(renderResult.getByTestId('test-longRunningCommandHint')).not.toBeNull(); | ||
}); | ||
|
||
it('should remove long running hint message if command completes', async () => { | ||
jest.useFakeTimers(); | ||
render(); | ||
|
||
act(() => { | ||
jest.advanceTimersByTime(16 * 1000); | ||
}); | ||
|
||
expect(renderResult.getByTestId('test-longRunningCommandHint')).not.toBeNull(); | ||
|
||
act(() => { | ||
setCmd1ToComplete(); | ||
}); | ||
|
||
expect(renderResult.queryByTestId('test-longRunningCommandHint')).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.