Skip to content

Commit

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

* fix location of es archive file
  • Loading branch information
charlie-pichette authored Feb 21, 2020
1 parent 8686fc9 commit fb04b7a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 19 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
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"id": "fc0ff548-feba-41b6-8367-65e8790d0eaf",
"ip": [
"10.101.149.26",
"10.12.85.216"
"2606:a000:ffc0:39:11ef:37b9:3371:578c"
],
"mac": [
"e2-6d-f9-0-46-2e"
Expand Down Expand Up @@ -238,7 +238,7 @@
"id": "fc0ff548-feba-41b6-8367-65e8790d0eaf",
"ip": [
"10.101.149.26",
"10.12.85.216"
"2606:a000:ffc0:39:11ef:37b9:3371:578c"
],
"mac": [
"e2-6d-f9-0-46-2e"
Expand Down Expand Up @@ -365,7 +365,7 @@
"id": "fc0ff548-feba-41b6-8367-65e8790d0eaf",
"ip": [
"10.101.149.26",
"10.12.85.216"
"2606:a000:ffc0:39:11ef:37b9:3371:578c"
],
"mac": [
"e2-6d-f9-0-46-2e"
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 fb04b7a

Please sign in to comment.