Skip to content

Commit

Permalink
[Endpoint] Functional Tests cleanup (#68756)
Browse files Browse the repository at this point in the history
* Removed several unnecessary disabled eslint rules
* moved common pageobject from endpoint_list to page_utils
* Rename functional_endpoint to security_solution_endpoint
* Delete `functional_endpoint_ingest_failure` no longer applicable
  • Loading branch information
paul-tavares authored Jun 10, 2020
1 parent 28d9c14 commit 577381d
Show file tree
Hide file tree
Showing 26 changed files with 95 additions and 173 deletions.
3 changes: 1 addition & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@
/x-pack/plugins/endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/api_integration/apis/endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/endpoint_api_integration_no_ingest/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/functional_endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/functional_endpoint_ingest_failure/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/security_solution_endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/functional/es_archives/endpoint/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/plugin_functional/plugins/resolver_test/ @elastic/endpoint-app-team @elastic/siem
/x-pack/test/plugin_functional/test_suites/resolver/ @elastic/endpoint-app-team @elastic/siem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export const ManagementPageView = memo<Omit<PageViewProps, 'tabs'>>((options) =>
href: getManagementUrl({ name: 'policyList' }),
},
];
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tabName]);
}, [options.viewType, tabName]);
return <PageView {...options} tabs={tabs} />;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,14 @@ export const HostDetails = memo(({ details }: { details: HostMetadata }) => {
description: details.agent.version,
},
];
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
details.agent.version,
details.endpoint.policy.id,
details.host.hostname,
details.host.ip,
policyResponseUri.search,
policyStatusClickHandler,
details.host.hostname,
details.agent.version,
policyStatus,
policyResponseUri,
policyStatusClickHandler,
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ export const mockManagementState: Immutable<ManagementState> = {
export const managementReducer = immutableCombineReducers({
[MANAGEMENT_STORE_POLICY_LIST_NAMESPACE]: policyListReducer,
[MANAGEMENT_STORE_POLICY_DETAILS_NAMESPACE]: policyDetailsReducer,
// @ts-ignore
[MANAGEMENT_STORE_ENDPOINTS_NAMESPACE]: hostListReducer,
});
2 changes: 1 addition & 1 deletion x-pack/scripts/functional_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const alwaysImportedTests = [
require.resolve('../test/functional/config.js'),
require.resolve('../test/functional_endpoint/config.ts'),
require.resolve('../test/security_solution_endpoint/config.ts'),
require.resolve('../test/functional_with_es_ssl/config.ts'),
require.resolve('../test/functional/config_security_basic.ts'),
require.resolve('../test/functional/config_security_trial.ts'),
Expand Down
30 changes: 0 additions & 30 deletions x-pack/test/functional_endpoint/page_objects/page_utils.ts

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions x-pack/test/functional_endpoint_ingest_failure/config.ts

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/test/plugin_functional/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { pageObjects } from './page_objects';
/* eslint-disable import/no-default-export */
export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const xpackFunctionalConfig = await readConfigFile(
require.resolve('../functional_endpoint/config.ts')
require.resolve('../security_solution_endpoint/config.ts')
);

// Find all folders in ./plugins since we treat all them as plugin folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default ({ getPageObjects, getService }: FtrProviderContext) => {
const pageObjects = getPageObjects(['common', 'endpoint', 'header']);
const pageObjects = getPageObjects(['common', 'endpoint', 'header', 'endpointPageUtils']);
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');

Expand Down Expand Up @@ -73,7 +73,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
'Jan 24, 2020 @ 16:06:09.541',
],
];
const tableData = await pageObjects.endpoint.getEndpointAppTableData('hostListTable');
const tableData = await pageObjects.endpointPageUtils.tableData('hostListTable');
expect(tableData).to.eql(expectedData);
});

Expand Down Expand Up @@ -126,7 +126,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
it('displays no items found when empty', async () => {
// get the endpoint list table data and verify message
const [, [noItemsFoundMessage]] = await pageObjects.endpoint.getEndpointAppTableData(
const [, [noItemsFoundMessage]] = await pageObjects.endpointPageUtils.tableData(
'hostListTable'
);
expect(noItemsFoundMessage).to.equal('No items found');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
import { PolicyTestResourceInfo } from '../../services/endpoint_policy';

export default function ({ getPageObjects, getService }: FtrProviderContext) {
const pageObjects = getPageObjects(['common', 'endpoint', 'policy']);
const pageObjects = getPageObjects(['common', 'endpoint', 'policy', 'endpointPageUtils']);
const testSubjects = getService('testSubjects');
const policyTestResources = getService('policyTestResources');
const RELATIVE_DATE_FORMAT = /\d (?:seconds|minutes) ago/i;
Expand All @@ -31,7 +31,9 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(policyTotal).to.equal('0 Policies');
});
it('has correct table headers', async () => {
const allHeaderCells = await pageObjects.endpoint.tableHeaderVisibleText('policyTable');
const allHeaderCells = await pageObjects.endpointPageUtils.tableHeaderVisibleText(
'policyTable'
);
expect(allHeaderCells).to.eql([
'Policy Name',
'Created By',
Expand All @@ -43,7 +45,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
]);
});
it('should show empty table results message', async () => {
const [, [noItemsFoundMessage]] = await pageObjects.endpoint.getEndpointAppTableData(
const [, [noItemsFoundMessage]] = await pageObjects.endpointPageUtils.tableData(
'policyTable'
);
expect(noItemsFoundMessage).to.equal('No items found');
Expand All @@ -65,7 +67,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});

it('should show policy on the list', async () => {
const [, policyRow] = await pageObjects.endpoint.getEndpointAppTableData('policyTable');
const [, policyRow] = await pageObjects.endpointPageUtils.tableData('policyTable');
// Validate row data with the exception of the Date columns - since those are initially
// shown as relative.
expect([policyRow[0], policyRow[1], policyRow[3], policyRow[5], policyRow[6]]).to.eql([
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FtrProviderContext } from '../ftr_provider_context';

export function EndpointPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const pageObjects = getPageObjects(['common', 'header']);
const pageObjects = getPageObjects(['common', 'header', 'endpointPageUtils']);
const retry = getService('retry');

return {
Expand All @@ -23,53 +23,9 @@ export function EndpointPageProvider({ getService, getPageObjects }: FtrProvider
await pageObjects.header.waitUntilLoadingHasFinished();
},

/**
* Finds the Table with the given `selector` (test subject) and returns
* back an array containing the table's header column text
*
* @param selector
* @returns Promise<string[]>
*/
async tableHeaderVisibleText(selector: string) {
const $ = await (await testSubjects.find('policyTable')).parseDomContent();
return $('thead tr th')
.toArray()
.map((th) =>
$(th)
.text()
.replace(/&nbsp;/g, '')
.trim()
);
},

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

async waitForTableToHaveData(dataTestSubj: string) {
await retry.waitForWithTimeout('table to have data', 2000, async () => {
const tableData = await this.getEndpointAppTableData(dataTestSubj);
const tableData = await pageObjects.endpointPageUtils.tableData(dataTestSubj);
if (tableData[1][0] === 'No items found') {
return false;
}
Expand Down
76 changes: 76 additions & 0 deletions x-pack/test/security_solution_endpoint/page_objects/page_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

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

export function EndpointPageUtils({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const find = getService('find');

return {
/**
* Finds a given EuiCheckbox by test subject and clicks on it
*
* @param euiCheckBoxTestId
*/
async clickOnEuiCheckbox(euiCheckBoxTestId: string) {
// This utility is needed because EuiCheckbox forwards the test subject on to
// the actual `<input>` which is not actually visible/accessible on the page.
// In order to actually cause the state of the checkbox to change, the `<label>`
// must be clicked.
const euiCheckboxLabelElement = await find.byXPath(
`//input[@data-test-subj='${euiCheckBoxTestId}']/../label`
);

await euiCheckboxLabelElement.click();
},

/**
* Finds the Table with the given `selector` (test subject) and returns
* back an array containing the table's header column text
*
* @param selector
* @returns Promise<string[]>
*/
async tableHeaderVisibleText(selector: string) {
const $ = await (await testSubjects.find(selector)).parseDomContent();
return $('thead tr th')
.toArray()
.map((th) =>
$(th)
.text()
.replace(/&nbsp;/g, '')
.trim()
);
},

/**
* 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 tableData(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 577381d

Please sign in to comment.