From 9fc01928b8842df3e0eaa3e3c38c5b360be9c1cf Mon Sep 17 00:00:00 2001 From: Ash <1849116+ashokaditya@users.noreply.github.com> Date: Wed, 10 Jul 2024 19:09:40 +0200 Subject: [PATCH] [SecuritySolution][Endpoint] Update `scan` tests w/wo feature flag enabled (#187758) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 796d537afd2b197abed244c2325c178386e14536 and 64010a3bc96ab92f534d8c69b87cb5cf7e47fe46 before merge --------- Co-authored-by: Gergő Ábrahám Co-authored-by: Elastic Machine --- .../response_actions_log.test.tsx | 19 +++++- .../view/response_actions_list_page.test.tsx | 63 +++++++++++++++++-- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/components/endpoint_response_actions_list/integration_tests/response_actions_log.test.tsx b/x-pack/plugins/security_solution/public/management/components/endpoint_response_actions_list/integration_tests/response_actions_log.test.tsx index bf13fec9086b1e..48cc21f4f5a553 100644 --- a/x-pack/plugins/security_solution/public/management/components/endpoint_response_actions_list/integration_tests/response_actions_log.test.tsx +++ b/x-pack/plugins/security_solution/public/management/components/endpoint_response_actions_list/integration_tests/response_actions_log.test.tsx @@ -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; @@ -1490,6 +1491,17 @@ describe('Response actions history', () => { }); describe('Actions filter', () => { + let featureFlags: Partial; + + beforeEach(() => { + featureFlags = { + responseActionUploadEnabled: true, + responseActionScanEnabled: false, + }; + + mockedContext.setExperimentalFlag(featureFlags); + }); + const filterPrefix = 'actions-filter'; it('should have a search bar', () => { @@ -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; @@ -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(); diff --git a/x-pack/plugins/security_solution/public/management/pages/response_actions/view/response_actions_list_page.test.tsx b/x-pack/plugins/security_solution/public/management/pages/response_actions/view/response_actions_list_page.test.tsx index 43afb4bd9054fd..e49385ccc7eca1 100644 --- a/x-pack/plugins/security_solution/public/management/pages/response_actions/view/response_actions_list_page.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/response_actions/view/response_actions_list_page.test.tsx @@ -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; @@ -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; @@ -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(); @@ -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; @@ -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();