Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Jul 7, 2021
1 parent c9cc124 commit 04aafa4
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,16 @@ describe('disable button', () => {
<AlertDetails alert={alert} alertType={alertType} actionTypes={[]} {...mockAlertApis} />
)
.find(EuiSwitch)
.find('[name="disable"]')
.find('[name="enable"]')
.first();

expect(enableButton.props()).toMatchObject({
checked: false,
checked: true,
disabled: false,
});
});

it('should render a disable button when alert is disabled', () => {
it('should render a enable button when alert is disabled', () => {
const alert = mockAlert({
enabled: false,
});
Expand All @@ -390,11 +390,11 @@ describe('disable button', () => {
<AlertDetails alert={alert} alertType={alertType} actionTypes={[]} {...mockAlertApis} />
)
.find(EuiSwitch)
.find('[name="disable"]')
.find('[name="enable"]')
.first();

expect(enableButton.props()).toMatchObject({
checked: true,
checked: false,
disabled: false,
});
});
Expand Down Expand Up @@ -428,7 +428,7 @@ describe('disable button', () => {
/>
)
.find(EuiSwitch)
.find('[name="disable"]')
.find('[name="enable"]')
.first();

enableButton.simulate('click');
Expand Down Expand Up @@ -468,7 +468,7 @@ describe('disable button', () => {
/>
)
.find(EuiSwitch)
.find('[name="disable"]')
.find('[name="enable"]')
.first();

enableButton.simulate('click');
Expand Down Expand Up @@ -531,14 +531,14 @@ describe('disable button', () => {

// Disable the alert
await act(async () => {
wrapper.find('[data-test-subj="disableSwitch"] .euiSwitch__button').first().simulate('click');
wrapper.find('[data-test-subj="enableSwitch"] .euiSwitch__button').first().simulate('click');
await nextTick();
});
expect(disableAlert).toHaveBeenCalled();

// Enable the alert
await act(async () => {
wrapper.find('[data-test-subj="disableSwitch"] .euiSwitch__button').first().simulate('click');
wrapper.find('[data-test-subj="enableSwitch"] .euiSwitch__button').first().simulate('click');
await nextTick();
});
expect(enableAlert).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
<EuiFlexGroup justifyContent="flexEnd" wrap responsive={false} gutterSize="m">
<EuiFlexItem grow={false}>
<EuiSwitch
name="disable"
name="enable"
disabled={!canSaveAlert || !alertType.enabledInLicense}
checked={!isEnabled}
data-test-subj="disableSwitch"
checked={isEnabled}
data-test-subj="enableSwitch"
onChange={async () => {
if (isEnabled) {
setIsEnabled(false);
Expand All @@ -237,8 +237,8 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
}}
label={
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertDetails.collapsedItemActons.disableTitle"
defaultMessage="Disable"
id="xpack.triggersActionsUI.sections.alertDetails.collapsedItemActons.enableTitle"
defaultMessage="Enable"
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ describe('alerts_list component with items', () => {
it('sorts alerts when clicking the name column', async () => {
await setup();
wrapper
.find('[data-test-subj="tableHeaderCell_name_0"] .euiTableHeaderButton')
.find('[data-test-subj="tableHeaderCell_name_1"] .euiTableHeaderButton')
.first()
.simulate('click');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import { useHistory } from 'react-router-dom';

import { isEmpty } from 'lodash';
import moment from 'moment';
import { ActionType, Alert, AlertTableItem, AlertTypeIndex, Pagination } from '../../../../types';
import { AlertAdd, AlertEdit } from '../../alert_form';
import { BulkOperationPopover } from '../../common/components/bulk_operation_popover';
Expand Down Expand Up @@ -323,30 +322,24 @@ export const AlertsList: React.FunctionComponent = () => {
);
};

const disabledLabel = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.disabledLabel',
{ defaultMessage: 'Disabled' }
);
const enabledLabel = i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.enabledLabel',
{ defaultMessage: 'Active' }
);

const alertsTableColumns = [
{
name: '',
width: '120px',
render(item: AlertTableItem) {
let isEnabled = !!item.enabled;
field: 'enabled',
name: i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.enabledTitle',
{ defaultMessage: 'Enabled' }
),
width: '90px',
render(enabled: boolean | undefined, item: AlertTableItem) {
let isEnabled = !!enabled;
return (
<EuiSwitch
name="disable"
name="enable"
disabled={!item.isEditable || !item.enabledInLicense}
compressed
checked={isEnabled}
data-test-subj="disableSwitch"
data-test-subj="enableSwitch"
onChange={async () => {
const enabled = item.enabled;
asyncScheduler.schedule(async () => {
if (enabled) {
await disableAlert({ http, id: item.id });
Expand All @@ -358,10 +351,11 @@ export const AlertsList: React.FunctionComponent = () => {
loadAlertsData();
}, 10);
}}
label={!item.enabled ? disabledLabel : enabledLabel}
label=""
/>
);
},
sortable: true,
'data-test-subj': 'alertsTableCell-enabled',
},
{
Expand Down Expand Up @@ -418,27 +412,6 @@ export const AlertsList: React.FunctionComponent = () => {
return renderAlertExecutionStatus(item.executionStatus, item);
},
},
{
field: 'lastUpdated',
width: '100px',
name: i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.lastUpdatedTitle',
{ defaultMessage: 'Last updated' }
),
render: (_count: number, item: AlertTableItem) => {
const today = moment(Date.now());
const updatedAt = moment(item.updatedAt);
const lastUpdatedMin = today.diff(updatedAt, 'minutes');
const lastUpdatedSec = today.diff(updatedAt, 'seconds');
return (
<EuiText size="s" key={item.id}>
{lastUpdatedMin === 0 ? `${lastUpdatedSec}s ago` : `${lastUpdatedMin}m ago`}
</EuiText>
);
},
sortable: true,
'data-test-subj': 'alertsTableCell-lastUpdated',
},
{
field: 'alertType',
name: i18n.translate(
Expand Down Expand Up @@ -468,25 +441,38 @@ export const AlertsList: React.FunctionComponent = () => {
},
{
field: 'schedule.interval',
width: '15%',
width: '6%',
name: i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.scheduleTitle',
{ defaultMessage: 'Schedule' }
),
render: (interval: number, item: AlertTableItem) => {
render: (interval: number) => {
return (
<EuiFlexGroup wrap responsive={false} gutterSize="xs">
<EuiFlexItem>
<EuiText size="s">
<EuiIcon color="subdued" type="clock" />
&nbsp;
{interval}
</EuiText>
</EuiFlexItem>
<EuiFlexItem>
<EuiText size="s">
<EuiIcon color="subdued" type="clock" />
&nbsp;
{interval}
</EuiText>
);
},
sortable: false,
truncateText: false,
'data-test-subj': 'alertsTableCell-interval',
},
{
width: '9%',
name: i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.actionsTitle',
{ defaultMessage: 'Actions' }
),
render: (item: AlertTableItem) => {
return (
<EuiFlexGroup wrap responsive={false} gutterSize="s">
<EuiFlexItem grow={false}>
<div>
<EuiText
size="s"
size="m"
data-test-subj="actionsCount"
title={i18n.translate(
'xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.actionsCountTooltip',
{ defaultMessage: 'Number of actions attached to the rule' }
Expand All @@ -498,9 +484,9 @@ export const AlertsList: React.FunctionComponent = () => {
</EuiText>
</div>
</EuiFlexItem>
<EuiFlexItem>
{item.muteAll ? (
<div>
<EuiFlexItem grow={false}>
<div>
{item.muteAll ? (
<EuiToolTip
position="bottom"
content={
Expand All @@ -512,6 +498,7 @@ export const AlertsList: React.FunctionComponent = () => {
>
<EuiButtonIcon
color={'danger'}
data-test-subj="unmuteIconButton"
onClick={async () => {
asyncScheduler.schedule(async () => {
await unmuteAlert({ http, id: item.id });
Expand All @@ -522,11 +509,10 @@ export const AlertsList: React.FunctionComponent = () => {
aria-label={'unmute'}
/>
</EuiToolTip>
</div>
) : (
<div className="alertSidebarItem">
) : (
<EuiToolTip
position="bottom"
data-test-subj="muteButton"
content={
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertsList.alertsListTable.columns.muteButtonTooltip"
Expand All @@ -536,7 +522,7 @@ export const AlertsList: React.FunctionComponent = () => {
>
<EuiButtonIcon
color={'primary'}
className="alertSidebarItem__action"
data-test-subj="muteIconButton"
onClick={async () => {
asyncScheduler.schedule(async () => {
await muteAlert({ http, id: item.id });
Expand All @@ -547,15 +533,13 @@ export const AlertsList: React.FunctionComponent = () => {
aria-label={'mute'}
/>
</EuiToolTip>
</div>
)}
)}
</div>
</EuiFlexItem>
</EuiFlexGroup>
);
},
sortable: false,
truncateText: false,
'data-test-subj': 'alertsTableCell-interval',
'data-test-subj': 'alertsTableCell-actions',
},
{
name: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@
}
}

.actCollapsedItemActions__item {
padding: $euiSizeM;
}

.actCollapsedItemActions {
display: flex;

.actCollapsedItemActions__deleteIcon {
width: $euiSwitchWidthCompressed;
text-align: center;
}

.actCollapsedItemActions__Label {
padding-left: $euiSizeS;
padding-top: $euiSizeXS * .5;
}
button[data-test-subj="deleteAlert"] {
color: $euiColorDanger;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const CollapsedItemActions: React.FunctionComponent<ComponentOpts> = ({
items: [
{
disabled: !(item.isEditable && !isDisabled) || !item.enabledInLicense,
'data-test-subj': 'muteSwitch',
'data-test-subj': 'muteButton',
onClick: async () => {
const muteAll = isMuted;
asyncScheduler.schedule(async () => {
Expand All @@ -86,7 +86,7 @@ export const CollapsedItemActions: React.FunctionComponent<ComponentOpts> = ({
},
{
disabled: !item.isEditable || !item.enabledInLicense,
'data-test-subj': 'disableSwitch',
'data-test-subj': 'disableButton',
onClick: async () => {
const enabled = !isDisabled;
asyncScheduler.schedule(async () => {
Expand Down Expand Up @@ -140,7 +140,7 @@ export const CollapsedItemActions: React.FunctionComponent<ComponentOpts> = ({
panelPaddingSize="none"
data-test-subj="collapsedItemActions"
>
<EuiContextMenu initialPanelId={0} panels={panels} />
<EuiContextMenu initialPanelId={0} panels={panels} className="actCollapsedItemActions" />
</EuiPopover>
);
};
Expand Down
Loading

0 comments on commit 04aafa4

Please sign in to comment.