From f95165c4a4ceff555ec99b6ebf02d15b58b24b58 Mon Sep 17 00:00:00 2001 From: Tiago Vila Verde Date: Sun, 17 Dec 2023 23:33:10 +0100 Subject: [PATCH] improving tests --- .../asset_criticality_selector.tsx | 17 ++++-- .../asset_criticality/translations.ts | 2 +- .../components/host_overview/index.tsx | 2 + .../components/user_overview/index.tsx | 3 + .../side_panel/host_details/index.tsx | 2 - .../test/security_solution_cypress/config.ts | 1 + .../asset_criticality/host_flyout.cy.ts} | 55 +++++++++++-------- .../host_details_right_panel.ts | 10 +++- .../serverless_config.ts | 1 + 9 files changed, 61 insertions(+), 32 deletions(-) rename x-pack/test/security_solution_cypress/cypress/e2e/{investigations/alerts/expandable_flyout/host_details_right_panel.cy.ts => entity_analytics/asset_criticality/host_flyout.cy.ts} (61%) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality/asset_criticality_selector.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality/asset_criticality_selector.tsx index f0d934bcea4ef..3f9b1fb7ee2b9 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality/asset_criticality_selector.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality/asset_criticality_selector.tsx @@ -63,11 +63,17 @@ export const AssetCriticalitySelector: React.FC = ({ entity }) => { {criticality.query.isLoading || criticality.mutation.isLoading ? ( ) : ( - + {criticality.status === 'update' && criticality.query.data?.criticality_level ? ( {CRITICALITY_LEVEL_TITLE[criticality.query.data.criticality_level]} @@ -137,7 +143,7 @@ const AssetCriticalityModal: React.FC = ({ criticality, modal, entit valueOfSelected={value} onChange={setNewValue} aria-label={PICK_ASSET_CRITICALITY} - data-test-subj="asset-criticality-modal-select-dropdown" + data-test-subj="asset-criticality-modal-select" /> @@ -146,7 +152,6 @@ const AssetCriticalityModal: React.FC = ({ criticality, modal, entit id="xpack.securitySolution.entityAnalytics.assetCriticality.cancelButton" defaultMessage="Cancel" /> - {'Cancel'} = ({ criticality, modal, entit const option = (level: CriticalityLevel): EuiSuperSelectOption => ({ value: level, dropdownDisplay: ( - + {CRITICALITY_LEVEL_TITLE[level]}

{CRITICALITY_LEVEL_DESCRIPTION[level]}

diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality/translations.ts b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality/translations.ts index 3ce9bf2d9dfa9..bb4d4f51ace09 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality/translations.ts +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality/translations.ts @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n'; import type { CriticalityLevel } from './common'; export const PICK_ASSET_CRITICALITY = i18n.translate( - 'xpack.securitySolution.timeline.sidePanel.hostDetails.assetCriticality.pick', + 'xpack.securitySolution.entityAnalytics.assetCriticality.pickerText', { defaultMessage: 'Pick asset criticality level', } diff --git a/x-pack/plugins/security_solution/public/overview/components/host_overview/index.tsx b/x-pack/plugins/security_solution/public/overview/components/host_overview/index.tsx index 686828412977a..d4a4a710741b6 100644 --- a/x-pack/plugins/security_solution/public/overview/components/host_overview/index.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/host_overview/index.tsx @@ -10,6 +10,7 @@ import { euiDarkVars as darkTheme, euiLightVars as lightTheme } from '@kbn/ui-th import { getOr } from 'lodash/fp'; import React, { useCallback, useMemo } from 'react'; import styled from 'styled-components'; +import { AssetCriticalitySelector } from '../../../entity_analytics/components/asset_criticality/asset_criticality_selector'; import type { HostItem } from '../../../../common/search_strategy'; import { buildHostNamesFilter, RiskScoreEntity } from '../../../../common/search_strategy'; import { DEFAULT_DARK_MODE } from '../../../../common/constants'; @@ -283,6 +284,7 @@ export const HostOverview = React.memo( {!isInDetailsSidePanel && ( )} + {descriptionLists.map((descriptionList, index) => ( ))} diff --git a/x-pack/plugins/security_solution/public/overview/components/user_overview/index.tsx b/x-pack/plugins/security_solution/public/overview/components/user_overview/index.tsx index 446fe215a695a..0cad73ec6e5e8 100644 --- a/x-pack/plugins/security_solution/public/overview/components/user_overview/index.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/user_overview/index.tsx @@ -10,6 +10,7 @@ import { euiDarkVars as darkTheme, euiLightVars as lightTheme } from '@kbn/ui-th import { getOr } from 'lodash/fp'; import React, { useCallback, useMemo } from 'react'; import styled from 'styled-components'; +import { AssetCriticalitySelector } from '../../../entity_analytics/components/asset_criticality/asset_criticality_selector'; import { buildUserNamesFilter, RiskScoreEntity } from '../../../../common/search_strategy'; import { DEFAULT_DARK_MODE } from '../../../../common/constants'; import type { DescriptionList } from '../../../../common/utility_types'; @@ -275,6 +276,7 @@ export const UserOverview = React.memo( {!isInDetailsSidePanel && ( )} + {descriptionLists.map((descriptionList, index) => ( ))} @@ -290,6 +292,7 @@ export const UserOverview = React.memo( )} + {isAuthorized && ( = React.memo( - ) : ( diff --git a/x-pack/test/security_solution_cypress/config.ts b/x-pack/test/security_solution_cypress/config.ts index 4fe61b660f1a4..dc17bf6644e34 100644 --- a/x-pack/test/security_solution_cypress/config.ts +++ b/x-pack/test/security_solution_cypress/config.ts @@ -47,6 +47,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { `--xpack.securitySolution.enableExperimental=${JSON.stringify([ 'chartEmbeddablesEnabled', 'alertSuppressionForThresholdRuleEnabled', + 'entityAnalyticsAssetCriticalityEnabled', ])}`, // mock cloud to enable the guided onboarding tour in e2e tests '--xpack.cloud.id=test', diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/alerts/expandable_flyout/host_details_right_panel.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/asset_criticality/host_flyout.cy.ts similarity index 61% rename from x-pack/test/security_solution_cypress/cypress/e2e/investigations/alerts/expandable_flyout/host_details_right_panel.cy.ts rename to x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/asset_criticality/host_flyout.cy.ts index 2c543b0581cd8..75f2df0ee25d2 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/alerts/expandable_flyout/host_details_right_panel.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/asset_criticality/host_flyout.cy.ts @@ -5,30 +5,37 @@ * 2.0. */ +import { getNewRule } from '../../../objects/rule'; import { - HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_TITLE, - HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_BUTTON, - HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_SELECTOR, HOST_DETAILS_FLYOUT_SECTION_HEADER, + HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_SELECTOR, toggleAssetCriticalityAccordion, + HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_BUTTON, toggleAssetCriticalityModal, + HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_TITLE, + HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SELECT, + HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SELECT_OPTION, HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SAVE_BTN, HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_LEVEL, - HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_DROPDOWN, -} from '../../../../screens/expandable_flyout/host_details_right_panel'; -import { deleteAlertsAndRules } from '../../../../tasks/api_calls/common'; -import { expandFirstAlertHostExpandableFlyout } from '../../../../tasks/expandable_flyout/common'; - -import { login } from '../../../../tasks/login'; -import { visit } from '../../../../tasks/navigation'; -import { createRule } from '../../../../tasks/api_calls/rules'; -import { getNewRule } from '../../../../objects/rule'; -import { ALERTS_URL } from '../../../../urls/navigation'; -import { waitForAlertsToPopulate } from '../../../../tasks/create_new_rule'; +} from '../../../screens/expandable_flyout/host_details_right_panel'; +import { deleteAlertsAndRules } from '../../../tasks/api_calls/common'; +import { createRule } from '../../../tasks/api_calls/rules'; +import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule'; +import { expandFirstAlertHostExpandableFlyout } from '../../../tasks/expandable_flyout/common'; +import { login } from '../../../tasks/login'; +import { visit } from '../../../tasks/navigation'; +import { ALERTS_URL } from '../../../urls/navigation'; describe( - 'Alert host details expandable flyout right panel', - { tags: ['@ess', '@serverless'] }, + 'Host details flyout', + { + tags: ['@ess', '@serverless'], + env: { + ftrConfig: { + enableExperimental: ['entityAnalyticsAssetCriticalityEnabled'], + }, + }, + }, () => { const rule = { ...getNewRule(), investigation_fields: { field_names: ['host.os.name'] } }; @@ -41,7 +48,7 @@ describe( expandFirstAlertHostExpandableFlyout(); }); - describe('Expandable flyout', () => { + describe('Host flyout', () => { it('should display header section', () => { cy.log('header and content'); @@ -57,7 +64,7 @@ describe( ); toggleAssetCriticalityAccordion(); - cy.get(HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_BUTTON).should('have.text', 'Change'); + cy.get(HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_BUTTON).should('have.text', 'Create'); }); it('should display asset criticality modal', () => { @@ -74,12 +81,16 @@ describe( cy.log('asset criticality update'); toggleAssetCriticalityModal(); - cy.get(HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_DROPDOWN) - .should('be.visible') - .select('High'); + cy.get(HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SELECT).should('be.visible').click(); + + cy.get(HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SELECT_OPTION) + .contains('Important') + .click(); cy.get(HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SAVE_BTN).should('be.visible').click(); - cy.get(HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_LEVEL).contains('High').should('be.visible'); + cy.get(HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_LEVEL) + .contains('Important') + .should('be.visible'); }); }); } diff --git a/x-pack/test/security_solution_cypress/cypress/screens/expandable_flyout/host_details_right_panel.ts b/x-pack/test/security_solution_cypress/cypress/screens/expandable_flyout/host_details_right_panel.ts index 92c9eb238836e..f2530202cb2eb 100644 --- a/x-pack/test/security_solution_cypress/cypress/screens/expandable_flyout/host_details_right_panel.ts +++ b/x-pack/test/security_solution_cypress/cypress/screens/expandable_flyout/host_details_right_panel.ts @@ -11,15 +11,19 @@ export const HOST_DETAILS_FLYOUT_SECTION_HEADER = getDataTestSubjectSelector('ho export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_SELECTOR = getDataTestSubjectSelector( 'asset-criticality-selector' ); -export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_LEVEL = getDataTestSubjectSelector('risk-score'); +export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_LEVEL = + getDataTestSubjectSelector('asset-criticality-level'); export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_BUTTON = getDataTestSubjectSelector( 'asset-criticality-change-btn' ); export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_TITLE = getDataTestSubjectSelector( 'asset-criticality-modal-title' ); -export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_DROPDOWN = getDataTestSubjectSelector( - 'asset-criticality-modal-select-dropdown' +export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SELECT = getDataTestSubjectSelector( + 'asset-criticality-modal-select' +); +export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SELECT_OPTION = getDataTestSubjectSelector( + 'asset-criticality-modal-select-option' ); export const HOST_DETAILS_FLYOUT_ASSET_CRITICALITY_MODAL_SAVE_BTN = getDataTestSubjectSelector( 'asset-criticality-modal-save-btn' diff --git a/x-pack/test/security_solution_cypress/serverless_config.ts b/x-pack/test/security_solution_cypress/serverless_config.ts index 8eb8d2efdefdc..c2d680cb228ec 100644 --- a/x-pack/test/security_solution_cypress/serverless_config.ts +++ b/x-pack/test/security_solution_cypress/serverless_config.ts @@ -36,6 +36,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { ])}`, `--xpack.securitySolution.enableExperimental=${JSON.stringify([ 'alertSuppressionForThresholdRuleEnabled', + 'entityAnalyticsAssetCriticalityEnabled', ])}`, ], },