Skip to content

Commit

Permalink
[SecuritySolution][Endpoint] Update scan tests w/wo feature flag en…
Browse files Browse the repository at this point in the history
…abled (elastic#187758)

## Summary

These tests should pass regardless of the state of
`responseActionScanEnabled` feature flag.
This needs to be merged to `8.15` before a new PR is created to enable
the FF on it.

### todo
- [x] see if tests pass
- [x] revert 796d537 and
64010a3 before merge

---------

Co-authored-by: Gergő Ábrahám <gergo.abraham@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 10, 2024
1 parent c9b6bc9 commit 9fc0192
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { getEndpointAuthzInitialStateMock } from '../../../../../common/endpoint
import { useGetEndpointActionList as _useGetEndpointActionList } from '../../../hooks/response_actions/use_get_endpoint_action_list';
import { OUTPUT_MESSAGES } from '../translations';
import { EndpointActionGenerator } from '../../../../../common/endpoint/data_generators/endpoint_action_generator';
import type { ExperimentalFeatures } from '../../../../../common';

const useGetEndpointActionListMock = _useGetEndpointActionList as jest.Mock;

Expand Down Expand Up @@ -1490,6 +1491,17 @@ describe('Response actions history', () => {
});

describe('Actions filter', () => {
let featureFlags: Partial<ExperimentalFeatures>;

beforeEach(() => {
featureFlags = {
responseActionUploadEnabled: true,
responseActionScanEnabled: false,
};

mockedContext.setExperimentalFlag(featureFlags);
});

const filterPrefix = 'actions-filter';

it('should have a search bar', () => {
Expand All @@ -1505,7 +1517,10 @@ describe('Response actions history', () => {
});

it('should show a list of actions (without `scan`) when opened', () => {
mockedContext.setExperimentalFlag({ responseActionUploadEnabled: true });
mockedContext.setExperimentalFlag({
...featureFlags,
responseActionScanEnabled: false,
});
render();
const { getByTestId, getAllByTestId } = renderResult;

Expand All @@ -1529,7 +1544,7 @@ describe('Response actions history', () => {

it('should show a list of actions (with `scan`) when opened', () => {
mockedContext.setExperimentalFlag({
responseActionUploadEnabled: true,
...featureFlags,
responseActionScanEnabled: true,
});
render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { MANAGEMENT_PATH } from '../../../../../common/constants';
import { getActionListMock } from '../../../components/endpoint_response_actions_list/mocks';
import { useGetEndpointsList } from '../../../hooks/endpoint/use_get_endpoints_list';

jest.mock('../../../../common/experimental_features_service');

let mockUseGetEndpointActionList: {
isFetched?: boolean;
isFetching?: boolean;
Expand Down Expand Up @@ -463,7 +461,12 @@ describe('Response actions history page', () => {
expect(history.location.search).toEqual('?page=1&pageSize=20');
});

it('should set selected command filter options to URL params ', () => {
// TODO: remove this test when responseActionScanEnabled is removed
it('should set selected command filter options to URL params (without `responseActionScanEnabled`)', () => {
mockedContext.setExperimentalFlag({
responseActionScanEnabled: false,
});

const filterPrefix = 'actions-filter';
render();
const { getAllByTestId, getByTestId } = renderResult;
Expand All @@ -480,6 +483,27 @@ describe('Response actions history page', () => {
);
});

it('should set selected command filter options to URL params (with `responseActionScanEnabled`)', () => {
mockedContext.setExperimentalFlag({
responseActionScanEnabled: true,
});

const filterPrefix = 'actions-filter';
render();
const { getAllByTestId, getByTestId } = renderResult;
userEvent.click(getByTestId(`${testPrefix}-${filterPrefix}-popoverButton`));
const allFilterOptions = getAllByTestId(`${filterPrefix}-option`);

allFilterOptions.forEach((option) => {
option.style.pointerEvents = 'all';
userEvent.click(option);
});

expect(history.location.search).toEqual(
'?commands=isolate%2Crelease%2Ckill-process%2Csuspend-process%2Cprocesses%2Cget-file%2Cexecute%2Cupload%2Cscan'
);
});

it('should set selected hosts filter options to URL params ', () => {
const filterPrefix = 'hosts-filter';
render();
Expand Down Expand Up @@ -607,7 +631,12 @@ describe('Response actions history page', () => {
});

describe('Clear all selected options on a filter', () => {
it('should clear all selected options on `actions` filter', () => {
// TODO: remove this test when responseActionScanEnabled is removed
it('should clear all selected options on `actions` filter (without `responseActionScanEnabled`)', () => {
mockedContext.setExperimentalFlag({
responseActionScanEnabled: false,
});

const filterPrefix = 'actions-filter';
render();
const { getAllByTestId, getByTestId } = renderResult;
Expand All @@ -629,6 +658,32 @@ describe('Response actions history page', () => {
expect(history.location.search).toEqual('');
});

it('should clear all selected options on `actions` filter (with `responseActionScanEnabled`)', () => {
mockedContext.setExperimentalFlag({
responseActionScanEnabled: true,
});

const filterPrefix = 'actions-filter';
render();
const { getAllByTestId, getByTestId } = renderResult;
userEvent.click(getByTestId(`${testPrefix}-${filterPrefix}-popoverButton`));
const allFilterOptions = getAllByTestId(`${filterPrefix}-option`);

allFilterOptions.forEach((option) => {
option.style.pointerEvents = 'all';
userEvent.click(option);
});

expect(history.location.search).toEqual(
'?commands=isolate%2Crelease%2Ckill-process%2Csuspend-process%2Cprocesses%2Cget-file%2Cexecute%2Cupload%2Cscan'
);

const clearAllButton = getByTestId(`${testPrefix}-${filterPrefix}-clearAllButton`);
clearAllButton.style.pointerEvents = 'all';
userEvent.click(clearAllButton);
expect(history.location.search).toEqual('');
});

it('should clear all selected options on `hosts` filter', () => {
const filterPrefix = 'hosts-filter';
render();
Expand Down

0 comments on commit 9fc0192

Please sign in to comment.