Skip to content

Commit

Permalink
[Fleet] [Spacetime] Refactoring Fleet Cypress tests (elastic#139693)
Browse files Browse the repository at this point in the history
* [Fleet] [Spacetime]  Refactoring Fleet Cypress tests

* Fix agent spec and unskip integration spec

* Integrations.real refactor

* Other fixes to integrations.real spec

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* Selectors changes

* Fix fleet-startup spec

* Keep fixing failures

* Reorganise selectors

* More refactoring

* Fix missing selector

* Other fixes

* Fix flakyness in integrations spec

* Add enrollment token spec

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Replace selectors

* Add timeout

* Use API to create new policy

* Fix multiple selectors

* Clean up tokens

* Revise test

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
criamico and kibanamachine authored Sep 7, 2022
1 parent 5af2544 commit a5a4884
Show file tree
Hide file tree
Showing 31 changed files with 470 additions and 227 deletions.
37 changes: 20 additions & 17 deletions x-pack/plugins/fleet/cypress/integration/a11y/home_page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,50 @@ import 'cypress-real-events/support';
import { checkA11y } from '../../support/commands';
import { FLEET, navigateTo } from '../../tasks/navigation';
import {
AGENT_FLYOUT,
GENERATE_FLEET_SERVER_POLICY_BUTTON,
AGENTS_QUICK_START_TAB_BUTTON,
PLATFORM_TYPE_LINUX_BUTTON,
AGENTS_ADVANCED_TAB_BUTTON,
ADVANCED_FLEET_SERVER_ADD_HOST_BUTTON,
ADVANCED_FLEET_SERVER_GENERATE_SERVICE_TOKEN_BUTTON,
AGENT_POLICIES_TAB,
AGENT_POLICIES_CREATE_AGENT_POLICY_BUTTON,
AGENT_POLICIES_CREATE_AGENT_POLICY_FLYOUT_TITLE,
AGENT_POLICIES_CREATE_AGENT_POLICY_FLYOUT,
AGENT_POLICY_CREATE_AGENT_POLICY_NAME_FIELD,
AGENT_POLICIES_FLYOUT_ADVANCED_DEFAULT_NAMESPACE_HEADER,
AGENT_POLICY_FLYOUT_CREATE_BUTTON,
ENROLLMENT_TOKENS_TAB,
ENROLLMENT_TOKENS_CREATE_TOKEN_BUTTON,
ENROLLMENT_TOKENS_CREATE_TOKEN_NAME_FIELD,
ENROLLMENT_TOKENS,
DATA_STREAMS_TAB,
SETTINGS_TAB,
SETTINGS_FLEET_SERVER_HOST_HEADING,
FLEET_SERVER_HOST_INPUT,
} from '../../screens/fleet';
import { AGENT_POLICY_NAME_LINK } from '../../screens/integrations';
import { cleanupAgentPolicies, unenrollAgent } from '../../tasks/cleanup';
describe('Home page', () => {
before(() => {
navigateTo(FLEET);
cy.getBySel(AGENTS_QUICK_START_TAB_BUTTON, { timeout: 15000 }).should('be.visible');
cy.getBySel(AGENT_FLYOUT.QUICK_START_TAB_BUTTON, { timeout: 15000 }).should('be.visible');
});

describe('Agents', () => {
const fleetServerHost = 'https://localhost:8220';

describe('Quick Start', () => {
it('Get started with fleet', () => {
checkA11y({ skipFailures: false });
});
it('Install Fleet Server', () => {
cy.getBySel('fleetServerHostInput', { timeout: 15000 }).should('be.visible');
cy.getBySel('fleetServerHostInput').getBySel('comboBoxSearchInput').type(fleetServerHost);
cy.getBySel(FLEET_SERVER_HOST_INPUT, { timeout: 15000 }).should('be.visible');
cy.getBySel(FLEET_SERVER_HOST_INPUT).getBySel('comboBoxSearchInput').type(fleetServerHost);
cy.getBySel(GENERATE_FLEET_SERVER_POLICY_BUTTON).click();
cy.getBySel(PLATFORM_TYPE_LINUX_BUTTON, { timeout: 15000 }).should('be.visible');
checkA11y({ skipFailures: false });
});
});

describe('Advanced', () => {
before(() => {
cy.getBySel(AGENTS_ADVANCED_TAB_BUTTON).click();
cy.getBySel(AGENT_FLYOUT.ADVANCED_TAB_BUTTON).click();
});
it('Select policy for fleet', () => {
checkA11y({ skipFailures: false });
Expand All @@ -69,19 +69,20 @@ describe('Home page', () => {
});
});
});

describe('Agent Policies', () => {
before(() => {
cy.getBySel(AGENT_POLICIES_TAB).click();
cy.getBySel(AGENT_POLICIES_CREATE_AGENT_POLICY_BUTTON, { timeout: 15000 }).should(
'be.visible'
);
cy.getBySel(AGENT_POLICIES_CREATE_AGENT_POLICY_FLYOUT.CREATE_BUTTON, {
timeout: 15000,
}).should('be.visible');
});
it('Agent Table', () => {
checkA11y({ skipFailures: false });
});
it('Create Policy Flyout', () => {
cy.getBySel(AGENT_POLICIES_CREATE_AGENT_POLICY_BUTTON).click();
cy.getBySel(AGENT_POLICIES_CREATE_AGENT_POLICY_FLYOUT_TITLE, { timeout: 15000 }).should(
cy.getBySel(AGENT_POLICIES_CREATE_AGENT_POLICY_FLYOUT.CREATE_BUTTON).click();
cy.getBySel(AGENT_POLICIES_CREATE_AGENT_POLICY_FLYOUT.TITLE, { timeout: 15000 }).should(
'be.visible'
);
cy.getBySel(AGENT_POLICY_CREATE_AGENT_POLICY_NAME_FIELD).type('testName');
Expand All @@ -97,6 +98,7 @@ describe('Home page', () => {
checkA11y({ skipFailures: true });
});
});

describe('Enrollment Tokens', () => {
before(() => {
cy.getBySel(ENROLLMENT_TOKENS_TAB).click();
Expand All @@ -106,13 +108,14 @@ describe('Home page', () => {
checkA11y({ skipFailures: false });
});
it('Create Enrollment Token Modal', () => {
cy.getBySel(ENROLLMENT_TOKENS_CREATE_TOKEN_BUTTON).click();
cy.getBySel(ENROLLMENT_TOKENS_CREATE_TOKEN_NAME_FIELD, { timeout: 15000 }).should(
cy.getBySel(ENROLLMENT_TOKENS.CREATE_TOKEN_BUTTON).click();
cy.getBySel(ENROLLMENT_TOKENS.CREATE_TOKEN_MODAL_NAME_FIELD, { timeout: 15000 }).should(
'be.visible'
);
checkA11y({ skipFailures: false });
});
});

describe('Data Streams', () => {
before(() => {
cy.getBySel('confirmModalCancelButton').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
AGENT_BINARY_SOURCES_TABLE_ACTIONS,
AGENT_BINARY_SOURCES_FLYOUT,
AGENT_POLICY_FORM,
CONFIRM_MODAL_CONFIRM_BUTTON,
} from '../screens/fleet';
import { cleanupDownloadSources } from '../tasks/cleanup';
import { FLEET, navigateTo } from '../tasks/navigation';
import { CONFIRM_MODAL } from '../screens/navigation';

describe('Agent binary download source section', () => {
beforeEach(() => {
Expand All @@ -35,7 +35,7 @@ describe('Agent binary download source section', () => {
.clear()
.type('https://edited-default-host.co');
cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.SUBMIT_BUTTON).click();
cy.getBySel(CONFIRM_MODAL_CONFIRM_BUTTON).click();
cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click();

cy.intercept('api/fleet/agent_download_sources/fleet-default-download-source', {
host: 'https://edited-default-host.co',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { FLEET_AGENT_LIST_PAGE } from '../screens/fleet';

import { createAgentDoc } from '../tasks/agents';
import { setupFleetServer } from '../tasks/fleet_server';
import { deleteFleetServerDocs, deleteAgentDocs } from '../tasks/cleanup';

const createAgentDocs = (kibanaVersion: string) => [
createAgentDoc('agent-1', 'policy-1'), // this agent will have upgrade available
Expand All @@ -14,29 +18,39 @@ const createAgentDocs = (kibanaVersion: string) => [
];

let docs: any[] = [];
// TODO: create fleet server, fix version of agent to upgrade to an allowed version (>= fleet server's, < kibana)
// https://github.com/elastic/kibana/issues/138121
describe.skip('View agents', () => {

describe('View agents list', () => {
before(() => {
cy.task('deleteDocsByQuery', {
index: '.fleet-agents',
query: { match_all: {} },
ignoreUnavailable: true,
});
deleteFleetServerDocs(true);
deleteAgentDocs(true);
setupFleetServer();

cy.getKibanaVersion().then((version) => {
docs = createAgentDocs(version);
cy.task('insertDocs', { index: '.fleet-agents', docs });
});
});
after(() => {
cy.task('deleteDocsByQuery', {
index: '.fleet-agents',
query: { match_all: {} },
});
deleteFleetServerDocs();
deleteAgentDocs();
});
beforeEach(() => {
cy.intercept('/api/fleet/agents/setup', { isReady: true });
cy.intercept('/api/fleet/agents/setup', {
isReady: true,
missing_optional_features: [],
missing_requirements: [],
});
cy.intercept('/api/fleet/setup', { isInitialized: true, nonFatalErrors: [] });
cy.intercept('/api/fleet/agents_status', {
total: 18,
inactive: 0,
online: 18,
error: 0,
offline: 0,
updating: 0,
other: 0,
events: 0,
});
cy.intercept(/\/api\/fleet\/agent_policies(\?.*)?$/, {
items: [
{
Expand Down Expand Up @@ -78,136 +92,143 @@ describe.skip('View agents', () => {
describe('Agent filter suggestions', () => {
it('should filter based on agent id', () => {
cy.visit('/app/fleet/agents');
cy.getBySel('agentList.queryInput').type('agent.id: "agent-1"{enter}');
cy.getBySel('fleetAgentListTable');
cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 2);
cy.getBySel('fleetAgentListTable').contains('agent-1');
cy.getBySel(FLEET_AGENT_LIST_PAGE.QUERY_INPUT).type('agent.id: "agent-1"{enter}');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 2);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-1');
});
});

describe('Upgrade available filter', () => {
it('should only show agents with upgrade available after click', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.showUpgradeable').click();
cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 17);
cy.getBySel('fleetAgentListTable').contains('agent-1');
cy.getBySel(FLEET_AGENT_LIST_PAGE.SHOW_UPGRADEABLE).click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 17);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-1');
});

it('should clear filter on second click', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.showUpgradeable').click();
cy.getBySel('agentList.showUpgradeable').click();
cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 18);
cy.getBySel('fleetAgentListTable').contains('agent-1');
cy.getBySel('fleetAgentListTable').contains('agent-2');
cy.getBySel(FLEET_AGENT_LIST_PAGE.SHOW_UPGRADEABLE).click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.SHOW_UPGRADEABLE).click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 19);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-1');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-2');
});
});

describe('Agent policy filter', () => {
it('should should show all policies as options', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.policyFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.POLICY_FILTER).click();

cy.get('button').contains('Agent policy 1');
cy.get('button').contains('Agent policy 2');
cy.get('button').contains('Agent policy 3');
});

it('should filter on single policy (no results)', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.policyFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.POLICY_FILTER).click();

cy.get('button').contains('Agent policy 4').click();

cy.getBySel('fleetAgentListTable').contains('No agents found');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('No agents found');
});

it('should filter on single policy', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.policyFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.POLICY_FILTER).click();

cy.get('button').contains('Agent policy 1').click();

cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 2);
cy.getBySel('fleetAgentListTable').contains('agent-1');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 2);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-1');
});

it('should filter on multiple policies', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.policyFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.POLICY_FILTER).click();

cy.get('button').contains('Agent policy 1').click();
cy.get('button').contains('Agent policy 2').click();

cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 3);
cy.getBySel('fleetAgentListTable').contains('agent-1');
cy.getBySel('fleetAgentListTable').contains('agent-2');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 3);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-1');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-2');
});
});

describe('Agent status filter', () => {
it('should filter on healthy (16 result)', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.statusFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.STATUS_FILTER).click();

cy.get('button').contains('Healthy').click();

cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 17);
cy.getBySel('fleetAgentListTable').contains('agent-1');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 18);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-1');
});

it('should filter on unhealthy (1 result)', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.statusFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.STATUS_FILTER).click();

cy.get('button').contains('Unhealthy').click();

cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 2);
cy.getBySel('fleetAgentListTable').contains('agent-2');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 2);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-2');
});

it('should filter on inactive (0 result)', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.statusFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.STATUS_FILTER).click();

cy.get('button').contains('Inactive').click();

cy.getBySel('fleetAgentListTable').contains('No agents found');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('No agents found');
});

it('should filter on healthy and unhealthy', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.statusFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.STATUS_FILTER).click();

cy.get('button').contains('healthy').click();
cy.get('button').contains('Unhealthy').click();

cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 18);
cy.getBySel('fleetAgentListTable').contains('agent-1');
cy.getBySel('fleetAgentListTable').contains('agent-2');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 19);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-1');
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).contains('agent-2');
});
});

describe('Bulk actions', () => {
it('should allow to bulk upgrade agents', () => {
cy.visit('/app/fleet/agents');

cy.getBySel('agentList.policyFilter').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.POLICY_FILTER).click();

cy.get('button').contains('Agent policy 3').click();
cy.getBySel('fleetAgentListTable').find('tr').should('have.length', 16);
cy.getBySel(FLEET_AGENT_LIST_PAGE.TABLE).find('tr').should('have.length', 16);

cy.getBySel('checkboxSelectAll').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.CHECKBOX_SELECT_ALL).click();
// Trigger a bulk upgrade
cy.getBySel('agentBulkActionsButton').click();
cy.getBySel(FLEET_AGENT_LIST_PAGE.BULK_ACTIONS_BUTTON).click();
cy.get('button').contains('Upgrade 15 agents').click();
cy.get('.euiModalFooter button').contains('Upgrade 15 agents').click();
// Cancel upgrade
cy.getBySel('abortUpgradeBtn').click();
cy.get('button').contains('Confirm').click();
// Cancel upgrade - this assertion is currently flaky
// cy.getBySel(CURRENT_BULK_UPGRADES_CALLOUT.ABORT_BTN).click();
// cy.get('button').contains('Confirm').click();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { TOAST_CLOSE_BTN } from '../screens/navigation';

describe('Edit agent policy', () => {
beforeEach(() => {
Expand Down Expand Up @@ -33,7 +34,7 @@ describe('Edit agent policy', () => {

it('should edit agent policy', () => {
cy.visit('/app/fleet/policies/policy-1/settings');
cy.getBySel('toastCloseButton').click();
cy.getBySel(TOAST_CLOSE_BTN).click();
cy.get('[placeholder="Optional description"').clear().type('desc');

cy.intercept('/api/fleet/agent_policies/policy-1', {
Expand Down
Loading

0 comments on commit a5a4884

Please sign in to comment.