Skip to content

Commit

Permalink
Add a link to documentation in the alerts and actions management UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Oct 28, 2020
1 parent 756c3f1 commit c2fe4b1
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as React from 'react';
import { RouteComponentProps, Router } from 'react-router-dom';
import { createMemoryHistory, createLocation } from 'history';
import { mountWithIntl } from 'test_utils/enzyme_helpers';

import TriggersActionsUIHome, { MatchParams } from './home';
import { AppContextProvider } from './app_context';
import { getMockedAppDependencies } from './test_utils';

describe('home', () => {
it('renders the documentation link', async () => {
const deps = await getMockedAppDependencies();

const props: RouteComponentProps<MatchParams> = {
history: createMemoryHistory(),
location: createLocation('/'),
match: {
isExact: true,
path: `/alerts`,
url: '',
params: {
section: 'alerts',
},
},
};
const wrapper = mountWithIntl(
<Router history={deps.history}>
<AppContextProvider appDeps={deps}>
<TriggersActionsUIHome {...props} />
</AppContextProvider>
</Router>
);
const documentationLink = wrapper.find('[data-test-subj="documentationLink"]');
expect(documentationLink.exists()).toBeTruthy();
expect(documentationLink.first().prop('href')).toEqual(
'https://www.elastic.co/guide/en/kibana/mocked-test-branch/managing-alerts-and-actions.html'
);
});
});
46 changes: 30 additions & 16 deletions x-pack/plugins/triggers_actions_ui/public/application/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import { FormattedMessage } from '@kbn/i18n/react';
import {
EuiPageBody,
EuiPageContent,
EuiPageContentHeader,
EuiPageContentHeaderSection,
EuiSpacer,
EuiTab,
EuiTabs,
EuiTitle,
EuiBetaBadge,
EuiText,
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
Expand All @@ -33,7 +34,7 @@ import { PLUGIN } from './constants/plugin';
import { HealthCheck } from './components/health_check';
import { HealthContextProvider } from './context/health_context';

interface MatchParams {
export interface MatchParams {
section: Section;
}

Expand Down Expand Up @@ -83,9 +84,9 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<
return (
<EuiPageBody>
<EuiPageContent>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
<EuiTitle size="m">
<EuiTitle size="m">
<EuiFlexGroup>
<EuiFlexItem>
<h1 data-test-subj="appTitle">
<FormattedMessage
id="xpack.triggersActionsUI.home.appTitle"
Expand All @@ -106,18 +107,31 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<
)}
/>
</h1>
</EuiTitle>
<EuiSpacer size="s" />
<EuiText>
<p>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/managing-alerts-and-actions.html`}
target="_blank"
iconType="help"
data-test-subj="documentationLink"
>
<FormattedMessage
id="xpack.triggersActionsUI.home.sectionDescription"
defaultMessage="Detect conditions using alerts, and take actions using connectors."
id="xpack.triggersActionsUI.home.alertsAndActionsDocsLinkText"
defaultMessage="Alerts and Actions docs"
/>
</p>
</EuiText>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiTitle>
<EuiSpacer size="s" />
<EuiText>
<p>
<FormattedMessage
id="xpack.triggersActionsUI.home.sectionDescription"
defaultMessage="Detect conditions using alerts, and take actions using connectors."
/>
</p>
</EuiText>

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

import { chartPluginMock } from '../../../../../../src/plugins/charts/public/mocks';
import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks';
import { alertingPluginMock } from '../../../../alerts/public/mocks';
import { actionTypeRegistryMock } from '../action_type_registry.mock';
import { alertTypeRegistryMock } from '../alert_type_registry.mock';
import { coreMock, scopedHistoryMock } from '../../../../../../src/core/public/mocks';

export async function getMockedAppDependencies() {
const coreSetupMock = coreMock.createSetup();
const actionTypeRegistry = actionTypeRegistryMock.create();
const alertTypeRegistry = alertTypeRegistryMock.create();
const [
{
chrome,
docLinks,
application: { capabilities, navigateToApp },
},
] = await coreSetupMock.getStartServices();
return {
chrome,
docLinks,
dataPlugin: dataPluginMock.createStartContract(),
charts: chartPluginMock.createStartContract(),
alerting: alertingPluginMock.createStartContract(),
toastNotifications: coreSetupMock.notifications.toasts,
http: coreSetupMock.http,
uiSettings: coreSetupMock.uiSettings,
navigateToApp,
capabilities,
history: scopedHistoryMock.create(),
setBreadcrumbs: jest.fn(),
actionTypeRegistry: actionTypeRegistry as any,
alertTypeRegistry: alertTypeRegistry as any,
};
}

0 comments on commit c2fe4b1

Please sign in to comment.