Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAC] [Observability] Add functional tests covering the alert workflow status #111788

Merged
merged 6 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -277,6 +277,7 @@ function ObservabilityActions({
iconType="boxesHorizontal"
aria-label="More"
onClick={() => toggleActionsPopover(eventId)}
data-test-subj="alerts-table-row-action-more"
/>
}
isOpen={openActionsPopoverId === eventId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('StatusFilter', () => {
const props = { onChange, status };

const { getByTestId } = render(<WorkflowStatusFilter {...props} />);
const button = getByTestId(`WorkflowStatusFilter ${status} button`);
const button = getByTestId(`workflow-status-filter-${status}-button`);
const input = button.querySelector('input') as Element;

Simulate.change(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const options: Array<EuiButtonGroupOptionProps & { id: AlertWorkflowStatus }> =
label: i18n.translate('xpack.observability.alerts.workflowStatusFilter.openButtonLabel', {
defaultMessage: 'Open',
}),
'data-test-subj': 'WorkflowStatusFilter open button',
'data-test-subj': 'workflow-status-filter-open-button',
},
{
id: 'acknowledged',
Expand All @@ -31,14 +31,14 @@ const options: Array<EuiButtonGroupOptionProps & { id: AlertWorkflowStatus }> =
defaultMessage: 'Acknowledged',
}
),
'data-test-subj': 'WorkflowStatusFilter acknowledged button',
'data-test-subj': 'workflow-status-filter-acknowledged-button',
},
{
id: 'closed',
label: i18n.translate('xpack.observability.alerts.workflowStatusFilter.closedButtonLabel', {
defaultMessage: 'Closed',
}),
'data-test-subj': 'WorkflowStatusFilter closed button',
'data-test-subj': 'workflow-status-filter-closed-button',
},
];

Expand Down
79 changes: 68 additions & 11 deletions x-pack/test/functional/services/observability/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import querystring from 'querystring';
import { chunk } from 'lodash';
import { FtrProviderContext } from '../../ftr_provider_context';
import { WebElementWrapper } from '../../../../../test/functional/services/lib/web_element_wrapper';

Expand All @@ -17,11 +18,14 @@ const DATE_WITH_DATA = {

const ALERTS_FLYOUT_SELECTOR = 'alertsFlyout';

const ACTION_COLUMN_INDEX = 1;

export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const flyoutService = getService('flyout');
const pageObjects = getPageObjects(['common']);
const retry = getService('retry');
const toasts = getService('toasts');

const navigateToTimeWithData = async () => {
return await pageObjects.common.navigateToUrlWithBrowserHistory(
Expand All @@ -31,11 +35,27 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP
);
};

const getTableColumnHeaders = async () => {
const table = await testSubjects.find('events-viewer-panel');
weltenwort marked this conversation as resolved.
Show resolved Hide resolved
const tableHeaderRow = await testSubjects.findDescendant('dataGridHeader', table);
const columnHeaders = await tableHeaderRow.findAllByXpath('./div');
return columnHeaders;
};

const getTableCells = async () => {
// NOTE: This isn't ideal, but EuiDataGrid doesn't really have the concept of "rows"
return await testSubjects.findAll('dataGridRowCell');
};

const getTableCellsInRows = async () => {
const columnHeaders = await getTableColumnHeaders();
if (columnHeaders.length <= 0) {
return [];
}
const cells = await getTableCells();
return chunk(cells, columnHeaders.length);
};

const getTableOrFail = async () => {
return await testSubjects.existOrFail('events-viewer-panel');
};
Expand Down Expand Up @@ -109,21 +129,58 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP
return await testSubjects.findAllDescendant('alertsFlyoutDescriptionListDescription', flyout);
};

const openRowActionsOverflowMenu = async (rowIndex: number) => {
const rows = await getTableCellsInRows();
const actionsOverflowButton = await testSubjects.findDescendant(
'alerts-table-row-action-more',
rows[rowIndex][ACTION_COLUMN_INDEX]
);
await actionsOverflowButton.click();
};

const setSingleAlertWorkflowStatus = async (
rowIndex: number,
workflowStatus: 'open' | 'acknowledged' | 'closed'
weltenwort marked this conversation as resolved.
Show resolved Hide resolved
) => {
await openRowActionsOverflowMenu(rowIndex);

if (workflowStatus === 'closed') {
await testSubjects.click('close-alert-status');
} else {
await testSubjects.click(`${workflowStatus}-alert-status`);
}

// wait for a confirmation toast (the css index is 1-based)
await toasts.getToastElement(1);
await toasts.dismissAllToasts();
};

const setWorkflowStatusFilter = async (workflowStatus: 'open' | 'acknowledged' | 'closed') => {
const buttonGroupButton = await testSubjects.find(
`workflow-status-filter-${workflowStatus}-button`
);
await buttonGroupButton.click();
};

return {
clearQueryBar,
typeInQueryBar,
submitQuery,
getTableCells,
getTableOrFail,
getNoDataStateOrFail,
openAlertsFlyout,
getAlertsFlyout,
getAlertsFlyoutTitle,
closeAlertsFlyout,
navigateToTimeWithData,
getAlertsFlyout,
getAlertsFlyoutDescriptionListDescriptions,
getAlertsFlyoutDescriptionListTitles,
getAlertsFlyoutOrFail,
getAlertsFlyoutTitle,
getAlertsFlyoutViewInAppButtonOrFail,
getAlertsFlyoutDescriptionListTitles,
getAlertsFlyoutDescriptionListDescriptions,
getNoDataStateOrFail,
getTableCells,
getTableCellsInRows,
getTableColumnHeaders,
getTableOrFail,
navigateToTimeWithData,
openAlertsFlyout,
setSingleAlertWorkflowStatus,
setWorkflowStatusFilter,
submitQuery,
typeInQueryBar,
};
weltenwort marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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 expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';

export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');

describe('workflow status', function () {
weltenwort marked this conversation as resolved.
Show resolved Hide resolved
this.tags('includeFirefox');

const observability = getService('observability');
const retry = getService('retry');

before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts');
await observability.alerts.navigateToTimeWithData();
});

after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/observability/alerts');
});

it('is filtered for "open" by default', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is it more more common to say "filter by"? This confused my brain for a moment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In "filter by" I'm always wondering whether it means to include or exclude. But I can probably try harder to find an unambiguous description with more natural grammar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to make the test case names clearer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW for me, by always means include. Similar to how "sort by" works, you sort by what you desire, and you filter by what you desire. But the "predicate" nature of this makes it harder I agree.
But I would imagine it likes this: filter by $PREDICATE, where if the predicate is true you include it, so "open" vs "not open"

await retry.try(async () => {
weltenwort marked this conversation as resolved.
Show resolved Hide resolved
const tableRows = await observability.alerts.getTableCellsInRows();
expect(tableRows.length).to.be(12);
});
});

it('can be set to "acknowledged" using the row menu', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Similar here, this test name is still a bit unclear with regards to what "can be set". Maybe the word alert is needed here as well?
"an alert can be set to "acknowledged" using the row action menu"?

I don't think this needs to be changed, more looking to discuss patterns.

await observability.alerts.setSingleAlertWorkflowStatus(0, 'acknowledged');
miltonhultgren marked this conversation as resolved.
Show resolved Hide resolved

await retry.try(async () => {
const tableRows = await observability.alerts.getTableCellsInRows();
expect(tableRows.length).to.be(11);
});
});

it('can be filtered for "acknowledged" using the filter button', async () => {
await observability.alerts.setWorkflowStatusFilter('acknowledged');

await retry.try(async () => {
const tableRows = await observability.alerts.getTableCellsInRows();
expect(tableRows.length).to.be(3);
});
});

it('can be set to "closed" using the row menu', async () => {
await observability.alerts.setSingleAlertWorkflowStatus(0, 'closed');

await retry.try(async () => {
const tableRows = await observability.alerts.getTableCellsInRows();
expect(tableRows.length).to.be(2);
});
});

it('can be filtered for "closed" using the filter button', async () => {
await observability.alerts.setWorkflowStatusFilter('closed');

await retry.try(async () => {
const tableRows = await observability.alerts.getTableCellsInRows();
expect(tableRows.length).to.be(4);
});
});

it('can be set to "open" using the row menu', async () => {
await observability.alerts.setSingleAlertWorkflowStatus(0, 'open');

await retry.try(async () => {
const tableRows = await observability.alerts.getTableCellsInRows();
expect(tableRows.length).to.be(3);
});
});

it('can be filtered for "open" using the filter button', async () => {
await observability.alerts.setWorkflowStatusFilter('open');

await retry.try(async () => {
const tableRows = await observability.alerts.getTableCellsInRows();
expect(tableRows.length).to.be(12);
});
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
this.tags('ciGroup6');
loadTestFile(require.resolve('./feature_controls'));
loadTestFile(require.resolve('./alerts'));
loadTestFile(require.resolve('./alerts/workflow_status'));
});
}