Skip to content

Commit

Permalink
[RAC] [Observability] Functional tests for cell actions (#111963)
Browse files Browse the repository at this point in the history
* Add tests for cell actions
  • Loading branch information
Kerry350 authored Sep 20, 2021
1 parent 1fb0982 commit 0fd39c9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 13 deletions.
21 changes: 20 additions & 1 deletion x-pack/test/functional/services/observability/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const DATE_WITH_DATA = {
};

const ALERTS_FLYOUT_SELECTOR = 'alertsFlyout';
const COPY_TO_CLIPBOARD_BUTTON_SELECTOR = 'copy-to-clipboard';
const ALERTS_TABLE_CONTAINER_SELECTOR = 'events-viewer-panel';

const ACTION_COLUMN_INDEX = 1;
Expand Down Expand Up @@ -77,7 +78,7 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP
};

const clearQueryBar = async () => {
return await (await getQueryBar()).clearValueWithKeyboard({ charByChar: true });
return await (await getQueryBar()).clearValueWithKeyboard();
};

const typeInQueryBar = async (query: string) => {
Expand Down Expand Up @@ -132,6 +133,20 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP
return await testSubjects.findAllDescendant('alertsFlyoutDescriptionListDescription', flyout);
};

// Cell actions

const copyToClipboardButtonExists = async () => {
return await testSubjects.exists(COPY_TO_CLIPBOARD_BUTTON_SELECTOR);
};

const getCopyToClipboardButton = async () => {
return await testSubjects.find(COPY_TO_CLIPBOARD_BUTTON_SELECTOR);
};

const getFilterForValueButton = async () => {
return await testSubjects.find('filter-for-value');
};

const openActionsMenuForRow = async (rowIndex: number) => {
const rows = await getTableCellsInRows();
const actionsOverflowButton = await testSubjects.findDescendant(
Expand Down Expand Up @@ -163,6 +178,7 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP
};

return {
getQueryBar,
clearQueryBar,
closeAlertsFlyout,
getAlertsFlyout,
Expand All @@ -171,6 +187,9 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP
getAlertsFlyoutOrFail,
getAlertsFlyoutTitle,
getAlertsFlyoutViewInAppButtonOrFail,
getCopyToClipboardButton,
getFilterForValueButton,
copyToClipboardButtonExists,
getNoDataStateOrFail,
getTableCells,
getTableCellsInRows,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ async function asyncForEach<T>(array: T[], callback: (item: T, index: number) =>
}
}

const ACTIVE_ALERTS_CELL_COUNT = 48;
const RECOVERED_ALERTS_CELL_COUNT = 24;
const TOTAL_ALERTS_CELL_COUNT = 72;

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

// Failing: See https://github.com/elastic/kibana/issues/111907
describe.skip('Observability alerts', function () {
describe('Observability alerts', function () {
this.tags('includeFirefox');

const pageObjects = getPageObjects(['common']);
Expand All @@ -41,9 +44,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('Renders the correct number of cells', async () => {
// NOTE: This isn't ideal, but EuiDataGrid doesn't really have the concept of "rows"
const cells = await observability.alerts.getTableCells();
expect(cells.length).to.be(72);
await retry.try(async () => {
const cells = await observability.alerts.getTableCells();
expect(cells.length).to.be(TOTAL_ALERTS_CELL_COUNT);
});
});

describe('Filtering', () => {
Expand All @@ -67,7 +71,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await observability.alerts.submitQuery('kibana.alert.status: recovered');
await retry.try(async () => {
const cells = await observability.alerts.getTableCells();
expect(cells.length).to.be(24);
expect(cells.length).to.be(RECOVERED_ALERTS_CELL_COUNT);
});
});

Expand All @@ -87,9 +91,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await (await testSubjects.find('superDatePickerToggleQuickMenuButton')).click();
// We shouldn't expect any data for the last 15 minutes
await (await testSubjects.find('superDatePickerCommonlyUsed_Last_15 minutes')).click();
await observability.alerts.getNoDataStateOrFail();
await pageObjects.common.waitUntilUrlIncludes('rangeFrom=now-15m&rangeTo=now');
});
await observability.alerts.getNoDataStateOrFail();
await pageObjects.common.waitUntilUrlIncludes('rangeFrom=now-15m&rangeTo=now');
});
});

Expand All @@ -114,10 +118,12 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('Displays the correct title', async () => {
const titleText = await (
await observability.alerts.getAlertsFlyoutTitle()
).getVisibleText();
expect(titleText).to.contain('Log threshold');
await retry.try(async () => {
const titleText = await (
await observability.alerts.getAlertsFlyoutTitle()
).getVisibleText();
expect(titleText).to.contain('Log threshold');
});
});

it('Displays the correct content', async () => {
Expand Down Expand Up @@ -156,6 +162,43 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
});
});

describe('Cell actions', () => {
beforeEach(async () => {
await retry.try(async () => {
const cells = await observability.alerts.getTableCells();
const alertStatusCell = cells[2];
await alertStatusCell.moveMouseTo();
await retry.waitFor(
'cell actions visible',
async () => await observability.alerts.copyToClipboardButtonExists()
);
});
});

afterEach(async () => {
await observability.alerts.clearQueryBar();
});

it('Copy button works', async () => {
// NOTE: We don't have access to the clipboard in a headless environment,
// so we'll just check the button is clickable in the functional tests.
await (await observability.alerts.getCopyToClipboardButton()).click();
});

it('Filter for value works', async () => {
await (await observability.alerts.getFilterForValueButton()).click();
const queryBarValue = await (
await observability.alerts.getQueryBar()
).getAttribute('value');
expect(queryBarValue).to.be('kibana.alert.status: "active"');
// Wait for request
await retry.try(async () => {
const cells = await observability.alerts.getTableCells();
expect(cells.length).to.be(ACTIVE_ALERTS_CELL_COUNT);
});
});
});
});
});
};

0 comments on commit 0fd39c9

Please sign in to comment.