Skip to content

Commit

Permalink
Add tests for renderMonitorType.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Jun 29, 2021
1 parent 0d713a9 commit ff57c00
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { renderMonitorType } from './status_bar';

describe('StatusBar component', () => {
describe('renderMonitorType', () => {
it('handles http type', () => {
expect(renderMonitorType('http')).toBe('HTTP');
});

it('handles tcp type', () => {
expect(renderMonitorType('tcp')).toBe('TCP');
});

it('handles icmp type', () => {
expect(renderMonitorType('icmp')).toBe('ICMP');
});

it('handles browser type', () => {
expect(renderMonitorType('browser')).toBe('Browser');
});

it('returns empty string for `undefined`', () => {
expect(renderMonitorType(undefined)).toBe('');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EuiDescriptionListDescription,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { MonitorSSLCertificate } from './ssl_certificate';
import * as labels from '../translations';
import { StatusByLocations } from './status_by_location';
Expand All @@ -40,36 +41,24 @@ export const MonListDescription = styled(EuiDescriptionListDescription)`
}
`;

const renderMonitorType = (type: string) => {
export const renderMonitorType = (type: string | undefined) => {
switch (type) {
case 'http':
return (
<FormattedMessage
id="xpack.uptime.monitorDetails.statusBar.pingType.http"
defaultMessage="HTTP"
/>
);
return i18n.translate('xpack.uptime.monitorDetails.statusBar.pingType.http', {
defaultMessage: 'HTTP',
});
case 'tcp':
return (
<FormattedMessage
id="xpack.uptime.monitorDetails.statusBar.pingType.tcp"
defaultMessage="TCP"
/>
);
return i18n.translate('xpack.uptime.monitorDetails.statusBar.pingType.tcp', {
defaultMessage: 'TCP',
});
case 'icmp':
return (
<FormattedMessage
id="xpack.uptime.monitorDetails.statusBar.pingType.icmp"
defaultMessage="ICMP"
/>
);
return i18n.translate('xpack.uptime.monitorDetails.statusBar.pingType.icmp', {
defaultMessage: 'ICMP',
});
case 'browser':
return (
<FormattedMessage
id="xpack.uptime.monitorDetails.statusBar.pingType.browser"
defaultMessage="Browser"
/>
);
return i18n.translate('xpack.uptime.monitorDetails.statusBar.pingType.browser', {
defaultMessage: 'Browser',
});
default:
return '';
}
Expand Down

0 comments on commit ff57c00

Please sign in to comment.