Skip to content

Commit

Permalink
[Uptime] Add callout for synthetics UI (elastic#79563)
Browse files Browse the repository at this point in the history
* Add callout for synthetics UI.

* Refresh outdated test snapshots.

* Test synthetics callout component.

* Update callout copy.

* Update URL for announcement link.

* Update test snapshots.

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
justinkambic and kibanamachine authored Oct 7, 2020
1 parent 7f5b824 commit 8472bb7
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* 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 { shallowWithIntl } from 'test_utils/enzyme_helpers';
import React from 'react';
import { SyntheticsCallout } from '../synthetics_callout';

describe('SyntheticsCallout', () => {
let setItemMock;
let localStorageMock: any;

beforeEach(() => {
setItemMock = jest.fn();
localStorageMock = {
getItem: jest.fn().mockImplementation(() => null),
setItem: setItemMock,
};

// @ts-expect-error replacing a call to localStorage we use for monitor list size
global.localStorage = localStorageMock;
});

it('renders component if dismissal flag is unset', () => {
expect(shallowWithIntl(<SyntheticsCallout />)).toMatchInlineSnapshot(`
<Fragment>
<EuiCallOut
iconType="beaker"
title="Elastic Synthetics"
>
<p>
<FormattedMessage
defaultMessage="Uptime is now previewing support for scripted multi-step availability checks. This means you can interact with elements of a webpage and check the availability of an entire journey (such as making a purchase or signing into a system) instead of just a simple single page up/down check. Please click below to read more and, if you'd like to be one of the first to use these capabilities, you can download our preview synthetics agent and view your synthetic checks in Uptime."
id="xpack.uptime.overview.pageHeader.syntheticsCallout.content"
values={Object {}}
/>
</p>
<EuiFlexGroup>
<EuiFlexItem
grow={false}
>
<EuiButton
href="https://www.elastic.co/what-is/synthetic-monitoring"
>
<FormattedMessage
defaultMessage="Read announcement"
id="xpack.uptime.overview.pageHeader.syntheticsCallout.announcementLink"
values={Object {}}
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem
grow={false}
>
<EuiButtonEmpty
onClick={[Function]}
>
<FormattedMessage
defaultMessage="Dismiss"
id="xpack.uptime.overview.pageHeader.syntheticsCallout.dismissButtonText"
values={Object {}}
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiCallOut>
<EuiSpacer
size="s"
/>
</Fragment>
`);
});

it('returns null if callout has been dismissed', () => {
localStorageMock.getItem = jest.fn().mockImplementation(() => 'true');
expect(shallowWithIntl(<SyntheticsCallout />)).toEqual({});
});

it('renders the component, and then returns null when dismiss button clicked', () => {
localStorageMock.getItem = jest
.fn()
.mockImplementationOnce(() => null)
.mockImplementationOnce(() => 'true');
const wrapper = shallowWithIntl(<SyntheticsCallout />);
expect(wrapper).toMatchInlineSnapshot(`
<Fragment>
<EuiCallOut
iconType="beaker"
title="Elastic Synthetics"
>
<p>
<FormattedMessage
defaultMessage="Uptime is now previewing support for scripted multi-step availability checks. This means you can interact with elements of a webpage and check the availability of an entire journey (such as making a purchase or signing into a system) instead of just a simple single page up/down check. Please click below to read more and, if you'd like to be one of the first to use these capabilities, you can download our preview synthetics agent and view your synthetic checks in Uptime."
id="xpack.uptime.overview.pageHeader.syntheticsCallout.content"
values={Object {}}
/>
</p>
<EuiFlexGroup>
<EuiFlexItem
grow={false}
>
<EuiButton
href="https://www.elastic.co/what-is/synthetic-monitoring"
>
<FormattedMessage
defaultMessage="Read announcement"
id="xpack.uptime.overview.pageHeader.syntheticsCallout.announcementLink"
values={Object {}}
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem
grow={false}
>
<EuiButtonEmpty
onClick={[Function]}
>
<FormattedMessage
defaultMessage="Dismiss"
id="xpack.uptime.overview.pageHeader.syntheticsCallout.dismissButtonText"
values={Object {}}
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiCallOut>
<EuiSpacer
size="s"
/>
</Fragment>
`);
wrapper.find('EuiButton').simulate('click');
expect(wrapper).toEqual({});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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 {
EuiButton,
EuiButtonEmpty,
EuiCallOut,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
} from '@elastic/eui';
import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

const SYNTHETICS_CALLOUT_LS_KEY = 'xpack.uptime.syntheticsCallout.display';
const shouldShowSyntheticsCallout = () => {
let value = localStorage.getItem(SYNTHETICS_CALLOUT_LS_KEY);
if (value === null) {
localStorage.setItem(SYNTHETICS_CALLOUT_LS_KEY, 'true');
value = 'true';
}
return value === 'true';
};
const hideSyntheticsCallout = () => localStorage.setItem(SYNTHETICS_CALLOUT_LS_KEY, 'false');

export const SyntheticsCallout = () => {
const [shouldShow, setShouldShow] = useState<boolean>(shouldShowSyntheticsCallout());
if (!shouldShow) {
return null;
}
return (
<>
<EuiCallOut
title={i18n.translate('xpack.uptime.overview.pageHeader.syntheticsCallout.title', {
defaultMessage: 'Elastic Synthetics',
})}
iconType="beaker"
>
<p>
<FormattedMessage
id="xpack.uptime.overview.pageHeader.syntheticsCallout.content"
defaultMessage="Uptime is now previewing support for scripted multi-step availability checks. This means you can interact with elements of a webpage and check the availability of an entire journey (such as making a purchase or signing into a system) instead of just a simple single page up/down check. Please click below to read more and, if you'd like to be one of the first to use these capabilities, you can download our preview synthetics agent and view your synthetic checks in Uptime."
/>
</p>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButton href="https://www.elastic.co/what-is/synthetic-monitoring">
<FormattedMessage
id="xpack.uptime.overview.pageHeader.syntheticsCallout.announcementLink"
defaultMessage="Read announcement"
/>
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
onClick={() => {
if (shouldShow) {
hideSyntheticsCallout();
setShouldShow(false);
}
}}
>
<FormattedMessage
id="xpack.uptime.overview.pageHeader.syntheticsCallout.dismissButtonText"
defaultMessage="Dismiss"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiCallOut>
<EuiSpacer size="s" />
</>
);
};
Loading

0 comments on commit 8472bb7

Please sign in to comment.