[Endpoint] Refactor Management List Tests (#58148) (#58889)

* endpoint-161-refactor-management-list-test

* fix location of es archive file

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Charlie Pichette 2020-03-02 10:46:37 -05:00 committed by GitHub
parent 908e0a1c44
commit f185e93849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 16 deletions

View file

@ -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 () => {

View file

@ -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 {
/**
@ -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()
)
);
},
};
}