Skip to content

Commit

Permalink
improving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tiansivive committed Dec 18, 2023
1 parent 1f757db commit f95165c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ export const AssetCriticalitySelector: React.FC<Props> = ({ entity }) => {
{criticality.query.isLoading || criticality.mutation.isLoading ? (
<EuiLoadingSpinner size="s" />
) : (
<EuiFlexGroup direction="row" alignItems="center" wrap={false}>
<EuiFlexGroup
direction="row"
alignItems="center"
justifyContent="spaceEvenly"
wrap={false}
>
<EuiFlexItem>
<EuiText size="s">
{criticality.status === 'update' && criticality.query.data?.criticality_level ? (
<EuiHealth
data-test-subj="asset-criticality-level"
color={CRITICALITY_LEVEL_COLOR[criticality.query.data.criticality_level]}
>
{CRITICALITY_LEVEL_TITLE[criticality.query.data.criticality_level]}
Expand Down Expand Up @@ -137,7 +143,7 @@ const AssetCriticalityModal: React.FC<ModalProps> = ({ 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"
/>
</EuiModalBody>
<EuiModalFooter>
Expand All @@ -146,7 +152,6 @@ const AssetCriticalityModal: React.FC<ModalProps> = ({ criticality, modal, entit
id="xpack.securitySolution.entityAnalytics.assetCriticality.cancelButton"
defaultMessage="Cancel"
/>
{'Cancel'}
</EuiButtonEmpty>

<EuiButton
Expand All @@ -173,7 +178,11 @@ const AssetCriticalityModal: React.FC<ModalProps> = ({ criticality, modal, entit
const option = (level: CriticalityLevel): EuiSuperSelectOption<CriticalityLevel> => ({
value: level,
dropdownDisplay: (
<EuiHealth color={CRITICALITY_LEVEL_COLOR[level]} style={{ lineHeight: 'inherit' }}>
<EuiHealth
color={CRITICALITY_LEVEL_COLOR[level]}
style={{ lineHeight: 'inherit' }}
data-test-subj="asset-criticality-modal-select-option"
>
<strong>{CRITICALITY_LEVEL_TITLE[level]}</strong>
<EuiText size="s" color="subdued">
<p>{CRITICALITY_LEVEL_DESCRIPTION[level]}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -283,6 +284,7 @@ export const HostOverview = React.memo<HostSummaryProps>(
{!isInDetailsSidePanel && (
<InspectButton queryId={id} title={i18n.INSPECT_TITLE} inspectIndex={0} />
)}
<AssetCriticalitySelector entity={{ type: 'host', name: hostName }} />
{descriptionLists.map((descriptionList, index) => (
<OverviewDescriptionList descriptionList={descriptionList} key={index} />
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -275,6 +276,7 @@ export const UserOverview = React.memo<UserSummaryProps>(
{!isInDetailsSidePanel && (
<InspectButton queryId={id} title={i18n.INSPECT_TITLE} inspectIndex={0} />
)}
<AssetCriticalitySelector entity={{ type: 'user', name: userName }} />
{descriptionLists.map((descriptionList, index) => (
<OverviewDescriptionList descriptionList={descriptionList} key={index} />
))}
Expand All @@ -290,6 +292,7 @@ export const UserOverview = React.memo<UserSummaryProps>(
)}
</OverviewWrapper>
</InspectButtonContainer>

{isAuthorized && (
<UserRiskOverviewWrapper
gutterSize={isInDetailsSidePanel ? 'm' : 'none'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { i18n } from '@kbn/i18n';
import React from 'react';
import styled from 'styled-components';
import { AssetCriticalitySelector } from '../../../../entity_analytics/components/asset_criticality/asset_criticality_selector';
import {
ExpandableHostDetails,
ExpandableHostDetailsPageLink,
Expand Down Expand Up @@ -84,7 +83,6 @@ export const HostDetailsPanel: React.FC<HostDetailsProps> = React.memo(
<EuiSpacer size="m" />
<ExpandableHostDetails contextID={contextID} scopeId={scopeId} hostName={hostName} />
<EuiSpacer size="m" />
<AssetCriticalitySelector entity={{ type: 'host', name: hostName }} />
</StyledEuiFlyoutBody>
</>
) : (
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/security_solution_cypress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] } };

Expand All @@ -41,7 +48,7 @@ describe(
expandFirstAlertHostExpandableFlyout();
});

describe('Expandable flyout', () => {
describe('Host flyout', () => {
it('should display header section', () => {
cy.log('header and content');

Expand All @@ -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', () => {
Expand All @@ -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');
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/security_solution_cypress/serverless_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
])}`,
`--xpack.securitySolution.enableExperimental=${JSON.stringify([
'alertSuppressionForThresholdRuleEnabled',
'entityAnalyticsAssetCriticalityEnabled',
])}`,
],
},
Expand Down

0 comments on commit f95165c

Please sign in to comment.