Skip to content
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ import { TestProviders } from '../../common/mock';
import { useSourcererDataView } from '../../sourcerer/containers';
import { useIsExperimentalFeatureEnabled } from '../../common/hooks/use_experimental_features';
import { useDataView } from '../../data_view_manager/hooks/use_data_view';
import { useEntityStoreStatus } from '../components/entity_store/hooks/use_entity_store';

jest.mock('../../common/components/links/link_props', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mockReact = require('react');
return {
withSecuritySolutionLink:
(WrappedComponent: React.ComponentType<Record<string, unknown>>) =>
(props: Record<string, unknown>) =>
mockReact.createElement(WrappedComponent, { ...props, href: '/mocked' }),
useGetSecuritySolutionLinkProps: jest.fn(() => () => ({ href: '/mocked', onClick: jest.fn() })),
useSecuritySolutionLinkProps: jest.fn(() => ({ href: '/mocked', onClick: jest.fn() })),
};
});

jest.mock('../../common/components/link_to', () => ({
useGetSecuritySolutionUrl:
Expand Down Expand Up @@ -97,6 +111,12 @@ jest.mock('../components/home/use_entity_store_data_view', () => ({
})),
}));

jest.mock('../components/entity_store/hooks/use_entity_store', () => ({
useEntityStoreStatus: jest.fn(() => ({
data: { status: 'running', engines: [] },
})),
}));

// useEntityURLState is already mocked inside the entities_table mock above

jest.mock('../../common/hooks/use_space_id', () => ({
Expand All @@ -112,6 +132,7 @@ jest.mock('@kbn/expandable-flyout', () => ({
const mockUseSourcererDataView = useSourcererDataView as jest.Mock;
const mockUseIsExperimentalFeatureEnabled = useIsExperimentalFeatureEnabled as jest.Mock;
const mockUseDataView = useDataView as jest.Mock;
const mockUseEntityStoreStatus = useEntityStoreStatus as jest.Mock;

describe('EntityAnalyticsHomePage', () => {
beforeEach(() => {
Expand All @@ -132,6 +153,10 @@ describe('EntityAnalyticsHomePage', () => {
dataView: { id: 'test', matchedIndices: ['index-1'] },
status: 'ready',
});

mockUseEntityStoreStatus.mockReturnValue({
data: { status: 'running', engines: [] },
});
});

it('renders the page title', () => {
Expand Down Expand Up @@ -240,4 +265,120 @@ describe('EntityAnalyticsHomePage', () => {
// EmptyPrompt should be rendered
expect(screen.queryByTestId('entityAnalyticsHomePage')).not.toBeInTheDocument();
});

it("renders entity store disabled empty prompt when status is 'not_installed'", () => {
mockUseEntityStoreStatus.mockReturnValue({
data: { status: 'not_installed', engines: [] },
});

render(
<MemoryRouter>
<EntityAnalyticsHomePage />
</MemoryRouter>,
{ wrapper: TestProviders }
);

expect(screen.getByTestId('entityStoreDisabledEmptyPrompt')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Entity analytics' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Enable Entity analytics' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: /Read the docs/ })).toBeInTheDocument();
expect(screen.queryByTestId('entityAnalyticsHomePage')).not.toBeInTheDocument();
});

it("renders entity store disabled empty prompt when status is 'stopped'", () => {
mockUseEntityStoreStatus.mockReturnValue({
data: { status: 'stopped', engines: [] },
});

render(
<MemoryRouter>
<EntityAnalyticsHomePage />
</MemoryRouter>,
{ wrapper: TestProviders }
);

expect(screen.getByTestId('entityStoreDisabledEmptyPrompt')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Entity analytics' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Enable Entity analytics' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: /Read the docs/ })).toBeInTheDocument();
expect(screen.queryByTestId('entityAnalyticsHomePage')).not.toBeInTheDocument();
});

it("does not render disabled empty prompt when status is 'running'", () => {
mockUseEntityStoreStatus.mockReturnValue({
data: { status: 'running', engines: [] },
});

render(
<MemoryRouter>
<EntityAnalyticsHomePage />
</MemoryRouter>,
{ wrapper: TestProviders }
);

expect(screen.queryByTestId('entityStoreDisabledEmptyPrompt')).not.toBeInTheDocument();
expect(screen.getByTestId('entityAnalyticsHomePage')).toBeInTheDocument();
});

it("does not render disabled empty prompt when status is 'installing'", () => {
mockUseEntityStoreStatus.mockReturnValue({
data: { status: 'installing', engines: [] },
});

render(
<MemoryRouter>
<EntityAnalyticsHomePage />
</MemoryRouter>,
{ wrapper: TestProviders }
);

expect(screen.queryByTestId('entityStoreDisabledEmptyPrompt')).not.toBeInTheDocument();
expect(screen.getByTestId('entityAnalyticsHomePage')).toBeInTheDocument();
});

it('disabled empty prompt footer renders a Read the docs link to the entity analytics docs', () => {
mockUseEntityStoreStatus.mockReturnValue({
data: { status: 'not_installed', engines: [] },
});

render(
<MemoryRouter>
<EntityAnalyticsHomePage />
</MemoryRouter>,
{ wrapper: TestProviders }
);

expect(screen.getByText('Want to learn more?', { exact: false })).toBeInTheDocument();
const docsLink = screen.getByRole('link', { name: /Read the docs/ });
expect(docsLink).toBeInTheDocument();
expect(docsLink).toHaveAttribute('href', expect.stringContaining('entity-risk-scoring'));
expect(docsLink).toHaveAttribute('target', '_blank');
});

it('indicesExist=false still wins over entity store disabled state', () => {
mockUseSourcererDataView.mockReturnValue({
indicesExist: false,
loading: false,
sourcererDataView: { id: 'test', matchedIndices: [] },
});

mockUseDataView.mockReturnValue({
dataView: { id: 'test', matchedIndices: [] },
status: 'ready',
});

mockUseEntityStoreStatus.mockReturnValue({
data: { status: 'not_installed', engines: [] },
});

render(
<MemoryRouter>
<EntityAnalyticsHomePage />
</MemoryRouter>,
{ wrapper: TestProviders }
);

expect(screen.queryByTestId('entityStoreDisabledEmptyPrompt')).not.toBeInTheDocument();
expect(screen.queryByTestId('entityAnalyticsHomePage')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import {
type URLQuery,
} from '../components/home/entities_table';
import { DynamicRiskLevelPanel } from '../components/home/dynamic_risk_level_panel';
import { useEntityStoreStatus } from '../components/entity_store/hooks/use_entity_store';
import { EntityStoreDisabledEmptyPrompt } from './entity_store_disabled_empty_prompt';
import { useGetSecuritySolutionUrl } from '../../common/components/link_to';
import { TabId } from './entity_analytics_management_page';
import { TopThreatHuntingLeads } from '../components/threat_hunting/top_threat_hunting_leads';
Expand Down Expand Up @@ -147,6 +149,11 @@ export const EntityAnalyticsHomePage = () => {
const isXlScreen = useIsWithinBreakpoints(['l', 'xl']);
const showEmptyPrompt = !indicesExist;

const { data: entityStoreStatusData } = useEntityStoreStatus();
const entityStoreDisabled =
entityStoreStatusData?.status === 'not_installed' ||
entityStoreStatusData?.status === 'stopped';

const handleOpenFlyout = useCallback(() => setIsFlyoutOpen(true), []);
const handleCloseFlyout = useCallback(() => setIsFlyoutOpen(false), []);

Expand All @@ -173,6 +180,10 @@ export const EntityAnalyticsHomePage = () => {
return <EmptyPrompt />;
}

if (entityStoreDisabled) {
return <EntityStoreDisabledEmptyPrompt />;
}

return (
<>
<FiltersGlobal>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { css } from '@emotion/react';
import { EuiEmptyPrompt, EuiFlexGroup, EuiImage, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { SecurityPageName } from '../../../common/constants';
import { SecuritySolutionLinkButton } from '../../common/components/links';
import { SecuritySolutionPageWrapper } from '../../common/components/page_wrapper';
import { HeaderPage } from '../../common/components/header_page';
import { EntityAnalyticsLearnMoreLink } from '../components/entity_analytics_learn_more_link';
import illustrationSearchAnalytics from '../../common/images/illustration_search_analytics.svg';

export const EntityStoreDisabledEmptyPrompt = React.memo(() => (
<SecuritySolutionPageWrapper
css={css`
height: calc(100vh - 240px);
`}
>
<HeaderPage
title={
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.homePage.pageTitle"
defaultMessage="Entity analytics"
/>
}
/>
<EuiFlexGroup
alignItems="center"
justifyContent="center"
css={css`
height: 100%;
`}
>
<EuiEmptyPrompt
color="plain"
css={css`
.euiEmptyPrompt__icon {
min-inline-size: 160px;
text-align: center;
}
.euiEmptyPrompt__content {
flex: 1;
}
`}
data-test-subj="entityStoreDisabledEmptyPrompt"
icon={<EuiImage size={128} alt="" url={illustrationSearchAnalytics} />}
layout="horizontal"
style={{ maxWidth: 624 }}
title={
<h2>
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.homePage.enableEntityAnalytics"
defaultMessage="Enable Entity analytics to collect entity data and access analytics capabilities"
/>
</h2>
}
actions={
<SecuritySolutionLinkButton
fill
deepLinkId={SecurityPageName.entityAnalyticsManagement}
iconType="external"
iconSide="right"
target="_blank"
>
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.homePage.enableEntityAnalytics.action"
defaultMessage="Enable Entity analytics"
/>
</SecuritySolutionLinkButton>
}
footer={
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.homePage.enableEntityAnalytics.footer"
defaultMessage="<semibold>Want to learn more?</semibold> {docsLink}"
values={{
semibold: (chunks: React.ReactNode) => (
<EuiText size="s" component="span" css={{ fontWeight: 600 }}>
{chunks}
</EuiText>
),
docsLink: (
<EntityAnalyticsLearnMoreLink
title={
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.homePage.enableEntityAnalytics.footerLink"
defaultMessage="Read the docs"
/>
}
/>
),
}}
/>
}
/>
</EuiFlexGroup>
</SecuritySolutionPageWrapper>
));
EntityStoreDisabledEmptyPrompt.displayName = 'EntityStoreDisabledEmptyPrompt';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

import { login } from '../../../tasks/login';
import { visit } from '../../../tasks/navigation';
import { setGrouping } from '../../../tasks/entity_analytics/entity_analytics_home';
import {
interceptEntityStoreStatus,
setGrouping,
} from '../../../tasks/entity_analytics/entity_analytics_home';
import { ENTITY_ANALYTICS_HOME_PAGE_URL } from '../../../urls/navigation';
import {
PAGE_TITLE,
Expand Down Expand Up @@ -45,6 +48,7 @@ describe(
`--xpack.securitySolution.enableExperimental=${JSON.stringify([
'entityAnalyticsNewHomePageEnabled',
])}`,
'--uiSettings.overrides.securitySolution:entityStoreEnableV2=true',
],
},
},
Expand All @@ -55,9 +59,11 @@ describe(
});

beforeEach(() => {
interceptEntityStoreStatus('running');
login();
setGrouping(['none']);
visit(ENTITY_ANALYTICS_HOME_PAGE_URL);
cy.wait('@entityStoreStatus', { timeout: 20000 });
waitForTableToLoad();
});

Expand Down Expand Up @@ -182,15 +188,18 @@ describe(
`--xpack.securitySolution.enableExperimental=${JSON.stringify([
'entityAnalyticsNewHomePageEnabled',
])}`,
'--uiSettings.overrides.securitySolution:entityStoreEnableV2=true',
],
},
},
},
() => {
beforeEach(() => {
interceptEntityStoreStatus('running');
login();
setGrouping(['none']);
visit(ENTITY_ANALYTICS_HOME_PAGE_URL);
cy.wait('@entityStoreStatus', { timeout: 20000 });
cy.get(PAGE_TITLE).should('exist');
});

Expand Down
Loading
Loading