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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import '../../../../__mocks__/kea.mock';
import '../../../../__mocks__/enterprise_search_url.mock';
import { setMockValues, mockTelemetryActions } from '../../../../__mocks__';

import React from 'react';
Expand All @@ -14,8 +14,6 @@ import { shallow, ShallowWrapper } from 'enzyme';

import { EuiEmptyPrompt } from '@elastic/eui';

import { SampleEngineCreationCta } from '../../sample_engine_creation_cta';

import { EmptyState } from './';

describe('EmptyState', () => {
Expand All @@ -37,10 +35,6 @@ describe('EmptyState', () => {
expect(wrapper.find('[data-test-subj="AdminEmptyEnginesPrompt"]')).toHaveLength(1);
});

it('contains a sample engine CTA', () => {
expect(prompt.find(SampleEngineCreationCta)).toHaveLength(1);
});

describe('create engine button', () => {
let button: ShallowWrapper;

Expand All @@ -54,7 +48,7 @@ describe('EmptyState', () => {
});

it('sends a user to engine creation', () => {
expect(button.prop('to')).toEqual('/engine_creation');
expect(button.prop('href')).toEqual('http://localhost:3002/as/engines/new');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import React from 'react';

import { useValues, useActions } from 'kea';

import { EuiPageContent, EuiEmptyPrompt, EuiSpacer } from '@elastic/eui';
import { EuiPageContent, EuiEmptyPrompt, EuiSpacer, EuiButton } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { EuiButtonTo } from '../../../../shared/react_router_helpers';
import { getAppSearchUrl } from '../../../../shared/enterprise_search_url';
import { TelemetryLogic } from '../../../../shared/telemetry';
import { AppLogic } from '../../../app_logic';
import { ENGINE_CREATION_PATH } from '../../../routes';

import { SampleEngineCreationCta } from '../../sample_engine_creation_cta/sample_engine_creation_cta';

import { EnginesOverviewHeader } from './header';

Expand Down Expand Up @@ -56,10 +53,13 @@ export const EmptyState: React.FC = () => {
}
actions={
<>
<EuiButtonTo
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiButton
data-test-subj="EmptyStateCreateFirstEngineCta"
fill
to={ENGINE_CREATION_PATH}
href={getAppSearchUrl('/engines/new')}
target="_blank"
iconType="popout"
onClick={() =>
sendAppSearchTelemetry({
action: 'clicked',
Expand All @@ -71,9 +71,8 @@ export const EmptyState: React.FC = () => {
'xpack.enterpriseSearch.appSearch.emptyState.createFirstEngineCta',
{ defaultMessage: 'Create an engine' }
)}
</EuiButtonTo>
</EuiButton>
<EuiSpacer size="xl" />
<SampleEngineCreationCta />
</>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

import { mockKibanaValues, mockTelemetryActions } from '../../../../../__mocks__';
import '../../../../../__mocks__/enterprise_search_url.mock';

import React from 'react';

import { shallow } from 'enzyme';

import { EuiLinkTo } from '../../../../../shared/react_router_helpers';
import { EuiLink } from '@elastic/eui';

import { navigateToEngine, renderEngineLink } from './engine_link_helpers';

Expand All @@ -21,7 +22,9 @@ describe('navigateToEngine', () => {

it('sends the user to the engine page and triggers a telemetry event', () => {
navigateToEngine('engine-a');
expect(navigateToUrl).toHaveBeenCalledWith('/engines/engine-a');
expect(navigateToUrl).toHaveBeenCalledWith('http://localhost:3002/as/engines/engine-a', {
shouldNotCreateHref: true,
});
expect(sendAppSearchTelemetry).toHaveBeenCalledWith({
action: 'clicked',
metric: 'engine_table_link',
Expand All @@ -34,9 +37,9 @@ describe('renderEngineLink', () => {

it('renders a link to the engine with telemetry', () => {
const wrapper = shallow(<div>{renderEngineLink('engine-b')}</div>);
const link = wrapper.find(EuiLinkTo);
const link = wrapper.find(EuiLink);

expect(link.prop('to')).toEqual('/engines/engine-b');
expect(link.prop('href')).toEqual('http://localhost:3002/as/engines/engine-b');

link.simulate('click');
expect(sendAppSearchTelemetry).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import React from 'react';

import { EuiLink } from '@elastic/eui';

import { getAppSearchUrl } from '../../../../../shared/enterprise_search_url';
import { KibanaLogic } from '../../../../../shared/kibana';
import { EuiLinkTo } from '../../../../../shared/react_router_helpers';
import { TelemetryLogic } from '../../../../../shared/telemetry';
import { ENGINE_PATH } from '../../../../routes';
import { generateEncodedPath } from '../../../../utils/encode_path_params';
Expand All @@ -22,15 +24,20 @@ const sendEngineTableLinkClickTelemetry = () => {

export const navigateToEngine = (engineName: string) => {
sendEngineTableLinkClickTelemetry();
KibanaLogic.values.navigateToUrl(generateEncodedPath(ENGINE_PATH, { engineName }));
KibanaLogic.values.navigateToUrl(
getAppSearchUrl(generateEncodedPath(ENGINE_PATH, { engineName })),
{ shouldNotCreateHref: true }
);
};

export const renderEngineLink = (engineName: string) => (
<EuiLinkTo
to={generateEncodedPath(ENGINE_PATH, { engineName })}
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiLink
href={getAppSearchUrl(generateEncodedPath(ENGINE_PATH, { engineName }))}
target="_blank"
onClick={sendEngineTableLinkClickTelemetry}
data-test-subj="EngineName"
>
{engineName}
</EuiLinkTo>
</EuiLink>
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import React from 'react';

import { shallow, ShallowWrapper } from 'enzyme';

import { EuiEmptyPrompt } from '@elastic/eui';

import { LoadingState, EmptyState } from './components';
import { EnginesTable } from './components/tables/engines_table';
import { MetaEnginesTable } from './components/tables/meta_engines_table';
Expand Down Expand Up @@ -42,8 +40,6 @@ describe('EnginesOverview', () => {
},
metaEnginesLoading: false,
hasPlatinumLicense: false,
// AppLogic
myRole: { canManageEngines: false },
// MetaEnginesTableLogic
expandedSourceEngines: {},
conflictingEnginesSets: {},
Expand Down Expand Up @@ -103,20 +99,6 @@ describe('EnginesOverview', () => {
expect(actions.loadEngines).toHaveBeenCalled();
});

describe('when the user can manage/create engines', () => {
it('renders a create engine button which takes users to the create engine page', () => {
setMockValues({
...valuesWithEngines,
myRole: { canManageEngines: true },
});
const wrapper = shallow(<EnginesOverview />);

expect(
wrapper.find('[data-test-subj="appSearchEnginesEngineCreationButton"]').prop('to')
).toEqual('/engine_creation');
});
});

describe('when the account has a platinum license', () => {
it('renders a 2nd meta engines table & makes a 2nd meta engines call', () => {
setMockValues({
Expand All @@ -128,41 +110,6 @@ describe('EnginesOverview', () => {
expect(wrapper.find(MetaEnginesTable)).toHaveLength(1);
expect(actions.loadMetaEngines).toHaveBeenCalled();
});

describe('when the user can manage/create engines', () => {
it('renders a create engine button which takes users to the create meta engine page', () => {
setMockValues({
...valuesWithEngines,
hasPlatinumLicense: true,
myRole: { canManageEngines: true },
});
const wrapper = shallow(<EnginesOverview />);

expect(
wrapper.find('[data-test-subj="appSearchEnginesMetaEngineCreationButton"]').prop('to')
).toEqual('/meta_engine_creation');
});

describe('when metaEngines is empty', () => {
it('contains an EuiEmptyPrompt that takes users to the create meta engine page', () => {
setMockValues({
...valuesWithEngines,
hasPlatinumLicense: true,
myRole: { canManageEngines: true },
metaEngines: [],
});
const wrapper = shallow(<EnginesOverview />);
const metaEnginesTable = wrapper.find(MetaEnginesTable).dive();
const emptyPrompt = metaEnginesTable.dive().find(EuiEmptyPrompt).dive();

expect(
emptyPrompt
.find('[data-test-subj="appSearchMetaEnginesEmptyStateCreationButton"]')
.prop('to')
).toEqual('/meta_engine_creation');
});
});
});
});

describe('pagination', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ import {

import { FlashMessages } from '../../../shared/flash_messages';
import { LicensingLogic } from '../../../shared/licensing';
import { EuiButtonTo } from '../../../shared/react_router_helpers';
import { convertMetaToPagination, handlePageChange } from '../../../shared/table_pagination';
import { SendAppSearchTelemetry as SendTelemetry } from '../../../shared/telemetry';
import { AppLogic } from '../../app_logic';
import { EngineIcon, MetaEngineIcon } from '../../icons';
import { ENGINE_CREATION_PATH, META_ENGINE_CREATION_PATH } from '../../routes';

import { EnginesOverviewHeader, LoadingState, EmptyState } from './components';
import { EnginesTable } from './components/tables/engines_table';
import { MetaEnginesTable } from './components/tables/meta_engines_table';
import {
CREATE_AN_ENGINE_BUTTON_LABEL,
CREATE_A_META_ENGINE_BUTTON_LABEL,
ENGINES_TITLE,
META_ENGINE_EMPTY_PROMPT_DESCRIPTION,
META_ENGINE_EMPTY_PROMPT_TITLE,
Expand All @@ -45,9 +40,6 @@ import './engines_overview.scss';

export const EnginesOverview: React.FC = () => {
const { hasPlatinumLicense } = useValues(LicensingLogic);
const {
myRole: { canManageEngines },
} = useValues(AppLogic);

const {
dataLoading,
Expand Down Expand Up @@ -89,19 +81,6 @@ export const EnginesOverview: React.FC = () => {
</h2>
</EuiTitle>
</EuiPageContentHeaderSection>
<EuiPageContentHeaderSection>
{canManageEngines && (
<EuiButtonTo
color="secondary"
size="s"
iconType="plusInCircle"
data-test-subj="appSearchEnginesEngineCreationButton"
to={ENGINE_CREATION_PATH}
>
{CREATE_AN_ENGINE_BUTTON_LABEL}
</EuiButtonTo>
)}
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody data-test-subj="appSearchEngines">
<EuiSpacer />
Expand All @@ -127,19 +106,6 @@ export const EnginesOverview: React.FC = () => {
</h2>
</EuiTitle>
</EuiPageContentHeaderSection>
<EuiPageContentHeaderSection>
{canManageEngines && (
<EuiButtonTo
color="secondary"
size="s"
iconType="plusInCircle"
data-test-subj="appSearchEnginesMetaEngineCreationButton"
to={META_ENGINE_CREATION_PATH}
>
{CREATE_A_META_ENGINE_BUTTON_LABEL}
</EuiButtonTo>
)}
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody data-test-subj="appSearchMetaEngines">
<MetaEnginesTable
Expand All @@ -153,17 +119,6 @@ export const EnginesOverview: React.FC = () => {
<EuiEmptyPrompt
title={<h2>{META_ENGINE_EMPTY_PROMPT_TITLE}</h2>}
body={<p>{META_ENGINE_EMPTY_PROMPT_DESCRIPTION}</p>}
actions={
canManageEngines && (
<EuiButtonTo
data-test-subj="appSearchMetaEnginesEmptyStateCreationButton"
fill
to={META_ENGINE_CREATION_PATH}
>
{CREATE_A_META_ENGINE_BUTTON_LABEL}
</EuiButtonTo>
)
}
/>
}
onChange={handlePageChange(onMetaEnginesPagination)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('AppSearchConfigured', () => {
});

it('renders with layout', () => {
expect(wrapper.find(Layout)).toHaveLength(2);
expect(wrapper.find(Layout)).toHaveLength(1);
expect(wrapper.find(Layout).last().prop('readOnlyMode')).toBeFalsy();
expect(wrapper.find(EnginesOverview)).toHaveLength(1);
expect(wrapper.find(EngineRouter)).toHaveLength(1);
Expand Down
Loading