Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security solution][Alert Details] Enable preview feature flag and cypress tests #188580

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export const allowedExperimentalValues = Object.freeze({
securitySolutionNotesEnabled: false,

/**
* Enables entity and alert previews
* Disables entity and alert previews
*/
entityAlertPreviewEnabled: false,
entityAlertPreviewDisabled: false,

/**
* Enables the Assistant Model Evaluation advanced setting and API endpoint, introduced in `8.11.0`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('RiskInputsTab', () => {
});

it('it renders alert preview button when feature flag is enable', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseRiskScore.mockReturnValue({
loading: false,
error: false,
Expand All @@ -152,7 +152,7 @@ describe('RiskInputsTab', () => {
});

it('it does not render alert preview button when feature flag is disable', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseRiskScore.mockReturnValue({
loading: false,
error: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const RiskInputsTab = ({ entityType, entityName, scopeId }: RiskInputsTab
}),
[]
);
const isPreviewEnabled = useIsExperimentalFeatureEnabled('entityAlertPreviewEnabled');
const isPreviewEnabled = !useIsExperimentalFeatureEnabled('entityAlertPreviewDisabled');

const inputColumns: Array<EuiBasicTableColumn<InputAlert>> = useMemo(
() => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const renderCorrelationsTable = (panelContext: DocumentDetailsContext) =>
describe('CorrelationsDetailsAlertsTable', () => {
beforeEach(() => {
jest.mocked(useExpandableFlyoutApi).mockReturnValue(mockFlyoutApi);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
jest.mocked(usePaginatedAlerts).mockReturnValue({
setPagination: jest.fn(),
setSorting: jest.fn(),
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('CorrelationsDetailsAlertsTable', () => {
});

it('renders open preview button when feature flag is on', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
const { getByTestId, getAllByTestId } = renderCorrelationsTable({
...mockContextValue,
isPreviewMode: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const CorrelationsDetailsAlertsTable: FC<CorrelationsDetailsAlertsTablePr
sorting,
error,
} = usePaginatedAlerts(alertIds || []);
const isPreviewEnabled = useIsExperimentalFeatureEnabled('entityAlertPreviewEnabled');
const isPreviewEnabled = !useIsExperimentalFeatureEnabled('entityAlertPreviewDisabled');

const onTableChange = useCallback(
({ page, sort }: Criteria<Record<string, unknown>>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('<HostDetails />', () => {
mockUseHostDetails.mockReturnValue(mockHostDetailsResponse);
mockUseRiskScore.mockReturnValue(mockRiskScoreResponse);
mockUseHostsRelatedUsers.mockReturnValue(mockRelatedUsersResponse);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
});

it('should render host details correctly', () => {
Expand All @@ -168,7 +168,7 @@ describe('<HostDetails />', () => {
});

it('should render host name as clicable link when feature flag is true', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
const { getByTestId } = renderHostDetails(mockContextValue);
expect(getByTestId(HOST_DETAILS_LINK_TEST_ID)).toBeInTheDocument();

Expand Down Expand Up @@ -272,7 +272,7 @@ describe('<HostDetails />', () => {
});

it('should render user name as clicable link when feature flag is true', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
const { getAllByTestId } = renderHostDetails(mockContextValue);
expect(getAllByTestId(HOST_DETAILS_RELATED_USERS_LINK_TEST_ID).length).toBe(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const HostDetails: React.FC<HostDetailsProps> = ({ hostName, timestamp, s
const isEntityAnalyticsAuthorized = isPlatinumOrTrialLicense && hasEntityAnalyticsCapability;

const { openPreviewPanel } = useExpandableFlyoutApi();
const isPreviewEnabled = useIsExperimentalFeatureEnabled('entityAlertPreviewEnabled');
const isPreviewEnabled = !useIsExperimentalFeatureEnabled('entityAlertPreviewDisabled');

const narrowDateRange = useCallback(
(score, interval) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('PrevalenceDetails', () => {
jest.clearAllMocks();
licenseServiceMock.isPlatinumPlus.mockReturnValue(true);
jest.mocked(useExpandableFlyoutApi).mockReturnValue(mockFlyoutApi);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
});

it('should render the table with all data if license is platinum', () => {
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('PrevalenceDetails', () => {
});

it('should render host and user name as clickable link if feature flag is true', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
(usePrevalence as jest.Mock).mockReturnValue(mockPrevelanceReturnValue);

const { getByTestId } = renderPrevalenceDetails();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export const PrevalenceDetails: React.FC = () => {
const { telemetry } = useKibana().services;

const isPlatinumPlus = useLicense().isPlatinumPlus();
const isPreviewEnabled = useIsExperimentalFeatureEnabled('entityAlertPreviewEnabled');
const isPreviewEnabled = !useIsExperimentalFeatureEnabled('entityAlertPreviewDisabled');

// these two are used by the usePrevalence hook to fetch the data
const [start, setStart] = useState(DEFAULT_FROM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('<UserDetails />', () => {
mockUseObservedUserDetails.mockReturnValue(mockUserDetailsResponse);
mockUseRiskScore.mockReturnValue(mockRiskScoreResponse);
mockUseUsersRelatedHosts.mockReturnValue(mockRelatedHostsResponse);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
});

it('should render user details correctly', () => {
Expand All @@ -165,7 +165,7 @@ describe('<UserDetails />', () => {
});

it('should render user name as clicable link when feature flag is true', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
const { getByTestId } = renderUserDetails(mockContextValue);
expect(getByTestId(USER_DETAILS_LINK_TEST_ID)).toBeInTheDocument();

Expand Down Expand Up @@ -254,7 +254,7 @@ describe('<UserDetails />', () => {
});

it('should render host name as clicable link when feature flag is true', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
const { getAllByTestId } = renderUserDetails(mockContextValue);
expect(getAllByTestId(USER_DETAILS_RELATED_HOSTS_LINK_TEST_ID).length).toBe(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const UserDetails: React.FC<UserDetailsProps> = ({ userName, timestamp, s
const isEntityAnalyticsAuthorized = isPlatinumOrTrialLicense && hasEntityAnalyticsCapability;

const { openPreviewPanel } = useExpandableFlyoutApi();
const isPreviewEnabled = useIsExperimentalFeatureEnabled('entityAlertPreviewEnabled');
const isPreviewEnabled = !useIsExperimentalFeatureEnabled('entityAlertPreviewDisabled');

const narrowDateRange = useCallback(
(score, interval) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const renderHighlightedFieldsCell = (values: string[], field: string) =>
describe('<HighlightedFieldsCell />', () => {
beforeAll(() => {
jest.mocked(useExpandableFlyoutApi).mockReturnValue(mockFlyoutApi);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
});

it('should render a basic cell', () => {
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('<HighlightedFieldsCell />', () => {
});

it('should open host preview when click on host when feature flag is on', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
const { getByTestId } = renderHighlightedFieldsCell(['test host'], 'host.name');

getByTestId(HIGHLIGHTED_FIELDS_LINKED_CELL_TEST_ID).click();
Expand All @@ -114,7 +114,7 @@ describe('<HighlightedFieldsCell />', () => {
});

it('should open user preview when click on user when feature flag is on', () => {
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
const { getByTestId } = renderHighlightedFieldsCell(['test user'], 'user.name');

getByTestId(HIGHLIGHTED_FIELDS_LINKED_CELL_TEST_ID).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface LinkFieldCellProps {
const LinkFieldCell: VFC<LinkFieldCellProps> = ({ field, value }) => {
const { scopeId, eventId, indexName } = useDocumentDetailsContext();
const { openLeftPanel, openPreviewPanel } = useExpandableFlyoutApi();
const isPreviewEnabled = useIsExperimentalFeatureEnabled('entityAlertPreviewEnabled');
const isPreviewEnabled = !useIsExperimentalFeatureEnabled('entityAlertPreviewDisabled');
const { telemetry } = useKibana().services;

const goToInsightsEntities = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const renderHostEntityContent = () =>
describe('<HostEntityContent />', () => {
beforeAll(() => {
jest.mocked(useExpandableFlyoutApi).mockReturnValue(mockFlyoutApi);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
});

describe('license is valid', () => {
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('<HostEntityContent />', () => {
it('should open host preview when clicking on title when feature flag is on', () => {
mockUseHostDetails.mockReturnValue([false, { hostDetails: hostData }]);
mockUseRiskScore.mockReturnValue({ data: riskLevel, isAuthorized: true });
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);

const { getByTestId } = renderHostEntityContent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const HostEntityOverview: React.FC<HostEntityOverviewProps> = ({ hostName
const { openLeftPanel, openPreviewPanel } = useExpandableFlyoutApi();
const { telemetry } = useKibana().services;

const isPreviewEnabled = useIsExperimentalFeatureEnabled('entityAlertPreviewEnabled');
const isPreviewEnabled = !useIsExperimentalFeatureEnabled('entityAlertPreviewDisabled');

const goToEntitiesTab = useCallback(() => {
openLeftPanel({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const renderUserEntityOverview = () =>
describe('<UserEntityOverview />', () => {
beforeAll(() => {
jest.mocked(useExpandableFlyoutApi).mockReturnValue(mockFlyoutApi);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
});

describe('license is valid', () => {
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('<UserEntityOverview />', () => {
it('should open user preview if feature flag is true', () => {
mockUseUserDetails.mockReturnValue([false, { userDetails: userData }]);
mockUseRiskScore.mockReturnValue({ data: riskLevel, isAuthorized: true });
mockUseIsExperimentalFeatureEnabled.mockReturnValue(true);
mockUseIsExperimentalFeatureEnabled.mockReturnValue(false);

const { getByTestId } = render(
<TestProviders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const UserEntityOverview: React.FC<UserEntityOverviewProps> = ({ userName
const { openLeftPanel, openPreviewPanel } = useExpandableFlyoutApi();
const { telemetry } = useKibana().services;

const isPreviewEnabled = useIsExperimentalFeatureEnabled('entityAlertPreviewEnabled');
const isPreviewEnabled = !useIsExperimentalFeatureEnabled('entityAlertPreviewDisabled');

const goToEntitiesTab = useCallback(() => {
openLeftPanel({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import {
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_ENTITIES_BUTTON,
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_HOST_DETAILS,
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_HOST_DETAILS_RIGHT_SECTION,
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_HOST_DETAILS_TITLE,
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_HOST_DETAILS_LINK,
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS,
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS_RIGHT_SECTION,
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS_TITLE,
DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS_LINK,
} from '../../../../screens/expandable_flyout/alert_details_left_panel_entities_tab';
import {
Expand Down Expand Up @@ -68,34 +66,20 @@ describe(
.should('have.text', 'Entities')
.and('have.class', 'euiButtonGroupButton-isSelected');

// github.com/elastic/security-team/issues/9933
// Comment out when feature flag 'entityAlertPreviewEnabled' is enabled
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS_TITLE).should(
'contain.text',
'test'
);
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS_RIGHT_SECTION).should(
'contain.text',
'Related hosts: 0'
);
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS).should('exist');

// github.com/elastic/security-team/issues/9933
// Comment out when feature flag 'entityAlertPreviewEnabled' is enabled
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_HOST_DETAILS_TITLE).should(
'contain.text',
'siem-kibana'
);
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_HOST_DETAILS_RIGHT_SECTION).should(
'contain.text',
'Related users: 0'
);
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_HOST_DETAILS).should('exist');
});

// github.com/elastic/security-team/issues/9933
// Enable when feature flag 'entityAlertPreviewEnabled' is enabled
it.skip('should open host preview when click on host details title', () => {
it('should open host preview when click on host details title', () => {
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_HOST_DETAILS_LINK).should(
'contain.text',
'siem-kibana'
Expand All @@ -115,9 +99,7 @@ describe(
cy.get(HOST_PREVIEW_PANEL_FOOTER).should('not.exist');
});

// github.com/elastic/security-team/issues/9933
// Enable when feature flag 'entityAlertPreviewEnabled' is enabled
it.skip('should open user preview when click on user details title', () => {
it('should open user preview when click on user details title', () => {
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS_LINK).should('contain.text', 'test');
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_USER_DETAILS_LINK).click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ describe(
);
});

// github.com/elastic/security-team/issues/9933
// Enable when feature flag 'entityAlertPreviewEnabled' is enabled
it.skip('should open host preview when click on host details title', () => {
it('should open host preview when click on host details title', () => {
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_PREVALENCE_TABLE_HOST_CELL).click();

cy.get(PREVIEW_SECTION).should('exist');
Expand All @@ -118,9 +116,7 @@ describe(
cy.get(HOST_PREVIEW_PANEL_FOOTER).should('not.exist');
});

// github.com/elastic/security-team/issues/9933
// Enable when feature flag 'entityAlertPreviewEnabled' is enabled
it.skip('should open user preview when click on user details title', () => {
it('should open user preview when click on user details title', () => {
cy.get(DOCUMENT_DETAILS_FLYOUT_INSIGHTS_TAB_PREVALENCE_TABLE_USER_CELL).click();

cy.get(PREVIEW_SECTION).should('exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ import {
openTableTab,
} from '../../../../tasks/expandable_flyout/alert_details_right_panel';

// github.com/elastic/security-team/issues/9933
// Enable when feature flag 'entityAlertPreviewEnabled' is enabled
describe.skip(
describe(
'Opening alert previews from alert details flyout',
{ tags: ['@ess', '@serverless'] },
() => {
Expand Down
Loading