Skip to content

Commit

Permalink
[8.8] [Infarstructure UI] Fix hosts view functional test (#155772) (#…
Browse files Browse the repository at this point in the history
…156360)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Infarstructure UI] Fix hosts view functional test
(#155772)](#155772)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Carlos
Crespo","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-05-02T11:40:48Z","message":"[Infarstructure
UI] Fix hosts view functional test (#155772)\n\ncloses
https://github.com/elastic/kibana/issues/155429\r\ncloses
https://github.com/elastic/kibana/issues/155293\r\n\r\n##
Summary\r\n\r\n\r\nThis PR fixes the hosts view functional test,
stabilizing the flaky test\r\ncases that started to fail after changes
were made to the page\r\n\r\n\r\n### How to test\r\n\r\n- `yarn
test:ftr:server
--config\r\nx-pack/test/functional/apps/infra/config.ts`\r\n- `yarn
test:ftr:runner --config\r\nx-pack/test/functional/apps/infra/config.ts
--include\r\nx-pack/test/functional/apps/infra/hosts_view.ts`\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"c4669323f7a1a781eaa2eaddab74971c480c80e8","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Metrics
UI","Team:Infra Monitoring
UI","release_note:skip","backport:prev-minor","Feature:ObsHosts","v8.9.0"],"number":155772,"url":"https://github.com/elastic/kibana/pull/155772","mergeCommit":{"message":"[Infarstructure
UI] Fix hosts view functional test (#155772)\n\ncloses
https://github.com/elastic/kibana/issues/155429\r\ncloses
https://github.com/elastic/kibana/issues/155293\r\n\r\n##
Summary\r\n\r\n\r\nThis PR fixes the hosts view functional test,
stabilizing the flaky test\r\ncases that started to fail after changes
were made to the page\r\n\r\n\r\n### How to test\r\n\r\n- `yarn
test:ftr:server
--config\r\nx-pack/test/functional/apps/infra/config.ts`\r\n- `yarn
test:ftr:runner --config\r\nx-pack/test/functional/apps/infra/config.ts
--include\r\nx-pack/test/functional/apps/infra/hosts_view.ts`\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"c4669323f7a1a781eaa2eaddab74971c480c80e8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/155772","number":155772,"mergeCommit":{"message":"[Infarstructure
UI] Fix hosts view functional test (#155772)\n\ncloses
https://github.com/elastic/kibana/issues/155429\r\ncloses
https://github.com/elastic/kibana/issues/155293\r\n\r\n##
Summary\r\n\r\n\r\nThis PR fixes the hosts view functional test,
stabilizing the flaky test\r\ncases that started to fail after changes
were made to the page\r\n\r\n\r\n### How to test\r\n\r\n- `yarn
test:ftr:server
--config\r\nx-pack/test/functional/apps/infra/config.ts`\r\n- `yarn
test:ftr:runner --config\r\nx-pack/test/functional/apps/infra/config.ts
--include\r\nx-pack/test/functional/apps/infra/hosts_view.ts`\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"c4669323f7a1a781eaa2eaddab74971c480c80e8"}}]}]
BACKPORT-->

Co-authored-by: Carlos Crespo <[email protected]>
  • Loading branch information
kibanamachine and crespocarlos authored May 2, 2023
1 parent 9988768 commit 595cc3f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const CHARTS_IN_ORDER: Array<Pick<MetricChartProps, 'title' | 'type'> & { fullRo

export const MetricsGrid = React.memo(() => {
return (
<EuiFlexGrid columns={2} gutterSize="s">
<EuiFlexGrid columns={2} gutterSize="s" data-test-subj="hostsView-metricChart">
{CHARTS_IN_ORDER.map(({ fullRow, ...chartProp }) => (
<EuiFlexItem key={chartProp.type} style={fullRow ? { gridColumn: '1/-1' } : {}}>
<MetricChart breakdownSize={DEFAULT_BREAKDOWN_SIZE} {...chartProp} />
Expand Down
46 changes: 33 additions & 13 deletions x-pack/test/functional/apps/infra/hosts_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const enableHostView = () => pageObjects.infraHostsView.clickEnableHostViewButton();

// Tests

// Failing: See https://github.com/elastic/kibana/issues/155429
describe.skip('Hosts View', function () {
describe('Hosts View', function () {
this.tags('includeFirefox');

before(async () => {
Expand Down Expand Up @@ -328,6 +326,13 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
START_DATE.format(timepickerFormat),
END_DATE.format(timepickerFormat)
);

await retry.waitFor(
'wait for table and KPI charts to load',
async () =>
(await pageObjects.infraHostsView.isHostTableLoading()) &&
(await pageObjects.infraHostsView.isKPIChartsLoaded())
);
});

after(async () => {
Expand Down Expand Up @@ -361,7 +366,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

describe('KPI tiles', () => {
it('should render 5 metrics trend tiles', async () => {
const hosts = await pageObjects.infraHostsView.getAllMetricsTrendTiles();
const hosts = await pageObjects.infraHostsView.getAllKPITiles();
expect(hosts.length).to.equal(5);
});

Expand All @@ -373,15 +378,17 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
{ metric: 'rx', value: 'N/A' },
].forEach(({ metric, value }) => {
it(`${metric} tile should show ${value}`, async () => {
const tileValue = await pageObjects.infraHostsView.getMetricsTrendTileValue(metric);
expect(tileValue).to.eql(value);
await retry.try(async () => {
const tileValue = await pageObjects.infraHostsView.getKPITileValue(metric);
expect(tileValue).to.eql(value);
});
});
});
});

describe('Metrics Tab', () => {
before(async () => {
browser.scrollTop();
await browser.scrollTop();
await pageObjects.infraHostsView.visitMetricsTab();
});

Expand All @@ -391,18 +398,18 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('should have an option to open the chart in lens', async () => {
await pageObjects.infraHostsView.getOpenInLensOption();
await pageObjects.infraHostsView.clickAndValidateMetriChartActionOptions();
});
});

describe('Logs Tab', () => {
before(async () => {
browser.scrollTop();
await browser.scrollTop();
await pageObjects.infraHostsView.visitLogsTab();
});

it('should load the Logs tab section when clicking on it', async () => {
testSubjects.existOrFail('hostsView-logs');
await testSubjects.existOrFail('hostsView-logs');
});
});

Expand All @@ -413,7 +420,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const COLUMNS = 5;

before(async () => {
browser.scrollTop();
await browser.scrollTop();
await pageObjects.infraHostsView.visitAlertTab();
});

Expand Down Expand Up @@ -474,7 +481,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const query = filtererEntries.map((entry) => `host.name :"${entry.title}"`).join(' or ');

before(async () => {
await browser.scrollTop();
await pageObjects.infraHostsView.submitQuery(query);
await retry.waitFor(
'wait for table and KPI charts to load',
async () =>
(await pageObjects.infraHostsView.isHostTableLoading()) &&
(await pageObjects.infraHostsView.isKPIChartsLoaded())
);
});

after(async () => {
Expand Down Expand Up @@ -502,8 +516,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
{ metric: 'tx', value: 'N/A' },
{ metric: 'rx', value: 'N/A' },
].map(async ({ metric, value }) => {
const tileValue = await pageObjects.infraHostsView.getMetricsTrendTileValue(metric);
expect(tileValue).to.eql(value);
await retry.try(async () => {
const tileValue = await pageObjects.infraHostsView.getKPITileValue(metric);
expect(tileValue).to.eql(value);
});
})
);
});
Expand Down Expand Up @@ -531,6 +547,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

describe('Pagination and Sorting', () => {
before(async () => {
await browser.scrollTop();
});

beforeEach(async () => {
await pageObjects.infraHostsView.changePageSize(5);
});
Expand Down
77 changes: 42 additions & 35 deletions x-pack/test/functional/page_objects/infra_hosts_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) {
return await testSubjects.click('hostsView-enable-feature-button');
},

async getHostsTable() {
return testSubjects.find('hostsView-table');
},

async isHostTableLoading() {
return !(await testSubjects.exists('tbody[class*=euiBasicTableBodyLoading]'));
},

async getHostsTableData() {
const table = await testSubjects.find('hostsView-table');
const table = await this.getHostsTable();
return table.findAllByTestSubject('hostsView-tableRow');
},

Expand All @@ -95,48 +103,55 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) {
return cellContent.getVisibleText();
},

async getMetricsTrendContainer() {
async getKPIContainer() {
return testSubjects.find('hostsView-metricsTrend');
},

async getChartsContainer() {
return testSubjects.find('hostsView-metricChart');
},

getMetricsTab() {
// MetricsTtab
async getMetricsTab() {
return testSubjects.find('hostsView-tabs-metrics');
},

async visitMetricsTab() {
const metricsTab = await this.getMetricsTab();
metricsTab.click();
},

async getAllMetricsTrendTiles() {
const container = await this.getMetricsTrendContainer();
return container.findAllByCssSelector('[data-test-subj*="hostsView-metricsTrend-"]');
},

async getMetricsTrendTileValue(type: string) {
const container = await this.getMetricsTrendContainer();
const element = await container.findByTestSubject(`hostsView-metricsTrend-${type}`);
const div = await element.findByClassName('echMetricText__value');
return await div.getAttribute('title');
await metricsTab.click();
},

async getAllMetricsCharts() {
const container = await this.getChartsContainer();
return container.findAllByCssSelector('[data-test-subj*="hostsView-metricChart-"]');
},

async getOpenInLensOption() {
const metricCharts = await this.getAllMetricsCharts();
const chart = metricCharts.at(-1)!;
await chart.moveMouseTo();
const button = await testSubjects.findDescendant('embeddablePanelToggleMenuIcon', chart);
async clickAndValidateMetriChartActionOptions() {
const element = await testSubjects.find('hostsView-metricChart-diskIOWrite');
await element.moveMouseTo();
const button = await element.findByTestSubject('embeddablePanelToggleMenuIcon');
await button.click();
await testSubjects.existOrFail('embeddablePanelContextMenuOpen');
return testSubjects.existOrFail('embeddablePanelAction-openInLens');
await testSubjects.existOrFail('embeddablePanelAction-openInLens');
// forces the modal to close
await element.click();
},

// KPIs
async isKPIChartsLoaded() {
return !(await testSubjects.exists(
'[data-test-subj=hostsView-metricsTrend] .echChartStatus[data-ech-render-complete=true]'
));
},

async getAllKPITiles() {
const container = await this.getKPIContainer();
return container.findAllByCssSelector('[data-test-subj*="hostsView-metricsTrend-"]');
},

async getKPITileValue(type: string) {
const element = await testSubjects.find(`hostsView-metricsTrend-${type}`);
const div = await element.findByClassName('echMetricText__value');
return await div.getAttribute('title');
},

// Flyout Tabs
Expand Down Expand Up @@ -187,7 +202,7 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) {

async visitLogsTab() {
const logsTab = await this.getLogsTab();
logsTab.click();
await logsTab.click();
},

async getLogEntries() {
Expand All @@ -212,7 +227,7 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) {

async visitAlertTab() {
const alertsTab = await this.getAlertsTab();
alertsTab.click();
await alertsTab.click();
},

setAlertStatusFilter(alertStatus?: AlertStatus) {
Expand All @@ -232,22 +247,14 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) {
return testSubjects.find('queryInput');
},

async clearQueryBar() {
const queryBar = await this.getQueryBar();

return queryBar.clearValueWithKeyboard();
},

async typeInQueryBar(query: string) {
const queryBar = await this.getQueryBar();

await queryBar.clearValueWithKeyboard();
return queryBar.type(query);
},

async submitQuery(query: string) {
await this.typeInQueryBar(query);

await testSubjects.click('querySubmitButton');
},

Expand Down Expand Up @@ -288,13 +295,13 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) {
async sortByDiskLatency() {
const diskLatency = await this.getDiskLatencyHeader();
const button = await testSubjects.findDescendant('tableHeaderSortButton', diskLatency);
return button.click();
await button.click();
},

async sortByTitle() {
const titleHeader = await this.getTitleHeader();
const button = await testSubjects.findDescendant('tableHeaderSortButton', titleHeader);
return button.click();
await button.click();
},
};
}

0 comments on commit 595cc3f

Please sign in to comment.