Skip to content

Commit

Permalink
[Endpoint] Refactor Management List Tests (#58148) (#58889)
Browse files Browse the repository at this point in the history
* endpoint-161-refactor-management-list-test

* fix location of es archive file

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
charlie-pichette and elasticmachine authored Mar 2, 2020
1 parent 908e0a1 commit f185e93
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 16 deletions.
68 changes: 55 additions & 13 deletions x-pack/test/functional/apps/endpoint/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,61 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('displays table data', async () => {
const data = await pageObjects.endpoint.getManagementTableData();
[
'Hostnamecadmann-4.example.com',
'PolicyPolicy Name',
'Policy StatusPolicy Status',
'Alerts0',
'Operating Systemwindows 10.0',
'IP Address10.192.213.130, 10.70.28.129',
'Sensor Versionversion',
'Last Activexxxx',
].forEach((cellValue, index) => {
expect(data[1][index]).to.equal(cellValue);
});
const expectedData = [
[
'Hostname',
'Policy',
'Policy Status',
'Alerts',
'Operating System',
'IP Address',
'Sensor Version',
'Last Active',
],
[
'cadmann-4.example.com',
'Policy Name',
'Policy Status',
'0',
'windows 10.0',
'10.192.213.130, 10.70.28.129',
'version',
'xxxx',
],
[
'thurlow-9.example.com',
'Policy Name',
'Policy Status',
'0',
'windows 10.0',
'10.46.229.234',
'version',
'xxxx',
],
[
'rezzani-7.example.com',
'Policy Name',
'Policy Status',
'0',
'windows 10.0',
'10.101.149.26, 2606:a000:ffc0:39:11ef:37b9:3371:578c',
'version',
'xxxx',
],
];
const tableData = await pageObjects.endpoint.getEndpointAppTableData('managementListTable');
expect(tableData).to.eql(expectedData);
});

it('displays no items found', async () => {
// clear out the data and reload the page
await esArchiver.unload('endpoint/metadata/api_feature');
await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/management');
// get the table data and verify no entries appear
const tableData = await pageObjects.endpoint.getEndpointAppTableData('managementListTable');
expect(tableData[1][0]).to.equal('No items found');
// reload the data so the other tests continue to pass
await esArchiver.load('endpoint/metadata/api_feature');
});

after(async () => {
Expand Down
27 changes: 24 additions & 3 deletions x-pack/test/functional/page_objects/endpoint_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

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

export function EndpointPageProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const table = getService('table');

return {
/**
Expand All @@ -34,8 +34,29 @@ export function EndpointPageProvider({ getService }: FtrProviderContext) {
return await testSubjects.getVisibleText('welcomeTitle');
},

async getManagementTableData() {
return await table.getDataFromTestSubj('managementListTable');
/**
* Finds a table and returns the data in a nested array with row 0 is the headers if they exist.
* It uses euiTableCellContent to avoid poluting the array data with the euiTableRowCell__mobileHeader data.
* @param dataTestSubj
* @returns Promise<string[][]>
*/
async getEndpointAppTableData(dataTestSubj: string) {
await testSubjects.exists(dataTestSubj);
const hostTable: WebElementWrapper = await testSubjects.find(dataTestSubj);
const $ = await hostTable.parseDomContent();
return $('tr')
.toArray()
.map(row =>
$(row)
.find('.euiTableCellContent')
.toArray()
.map(cell =>
$(cell)
.text()
.replace(/&nbsp;/g, '')
.trim()
)
);
},
};
}

0 comments on commit f185e93

Please sign in to comment.