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

[Endpoint] Refactor Management List Tests #58148

Merged
merged 6 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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',
],
Copy link
Contributor

@nnamdifrankie nnamdifrankie Feb 21, 2020

Choose a reason for hiding this comment

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

You might want to comment that this is the header row

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I will add that on my next PR.

[
'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()
)
);
},
};
}