Skip to content

Commit

Permalink
Add cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Nov 21, 2024
1 parent e3792b3 commit 8e4c019
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 28 deletions.
87 changes: 59 additions & 28 deletions x-pack/plugins/fleet/cypress/e2e/package_policy.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,46 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { EXISTING_HOSTS_TAB } from '../screens/fleet';
import {
ADD_INTEGRATION_POLICY_BTN,
CREATE_PACKAGE_POLICY_SAVE_BTN,
POLICY_EDITOR,
} from '../screens/integrations';
import { CONFIRM_MODAL } from '../screens/navigation';
import { login } from '../tasks/login';

describe('Edit package policy', () => {
const policyConfig = {
id: 'policy-1',
name: 'fleet_server-1',
namespace: 'default',
package: { name: 'fleet_server', title: 'Fleet Server', version: '1.1.0' },
enabled: true,
policy_id: 'fleet-server-policy',
policy_ids: ['fleet-server-policy'],
output_id: 'fleet-default-output',
inputs: [
{
type: 'fleet-server',
policy_template: 'fleet_server',
enabled: true,
streams: [],
vars: {
host: { value: ['0.0.0.0'], type: 'text' },
port: { value: [8220], type: 'integer' },
max_connections: { type: 'integer' },
custom: { value: '', type: 'yaml' },
},
compiled_input: { server: { port: 8220, host: '0.0.0.0' } },
},
],
};
describe('Package policy', () => {
beforeEach(() => {
login();
});

it('should edit package policy', () => {
const policyConfig = {
id: 'policy-1',
name: 'fleet_server-1',
namespace: 'default',
package: { name: 'fleet_server', title: 'Fleet Server', version: '1.1.0' },
enabled: true,
policy_id: 'fleet-server-policy',
policy_ids: ['fleet-server-policy'],
output_id: 'fleet-default-output',
inputs: [
{
type: 'fleet-server',
policy_template: 'fleet_server',
enabled: true,
streams: [],
vars: {
host: { value: ['0.0.0.0'], type: 'text' },
port: { value: [8220], type: 'integer' },
max_connections: { type: 'integer' },
custom: { value: '', type: 'yaml' },
},
compiled_input: { server: { port: 8220, host: '0.0.0.0' } },
},
],
};

cy.intercept('/api/fleet/package_policies/policy-1', {
item: policyConfig,
Expand Down Expand Up @@ -111,9 +121,7 @@ describe('Edit package policy', () => {
status: 'not_installed',
},
});
});

it('should edit package policy', () => {
cy.visit('/app/fleet/policies/fleet-server-policy/edit-integration/policy-1');
cy.getBySel('packagePolicyDescriptionInput').clear().type('desc');

Expand All @@ -128,4 +136,27 @@ describe('Edit package policy', () => {
expect(interception.request.body.description).to.equal('desc');
});
});

it('should create a new orphaned package policy', () => {
cy.visit('/app/integrations/detail/system');
cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click();
cy.getBySel(EXISTING_HOSTS_TAB).click();
cy.getBySel(POLICY_EDITOR.AGENT_POLICY_SELECT).should('exist');
cy.getBySel(POLICY_EDITOR.AGENT_POLICY_CLEAR).should('not.exist');
cy.getBySel(POLICY_EDITOR.POLICY_NAME_INPUT).clear().type('system-orphaned-test');

cy.intercept({
method: 'POST',
url: '/api/fleet/package_policies',
}).as('createPackagePolicy');

cy.getBySel(CREATE_PACKAGE_POLICY_SAVE_BTN).should('be.enabled').click();
cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click();

cy.wait('@createPackagePolicy').then((interception) => {
expect(interception.request.body.name).to.equal('system-orphaned-test');
expect(interception.request.body.policy_id).to.equal(undefined);
expect(interception.request.body.policy_ids).to.deep.equal([]);
});
});
});
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/cypress/screens/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const POLICY_EDITOR = {
POLICY_NAME_INPUT: 'packagePolicyNameInput',
DATASET_SELECT: 'datasetComboBox',
AGENT_POLICY_SELECT: 'agentPolicyMultiSelect',
AGENT_POLICY_CLEAR: 'comboBoxClearButton',
INSPECT_PIPELINES_BTN: 'datastreamInspectPipelineBtn',
EDIT_MAPPINGS_BTN: 'datastreamEditMappingsBtn',
CREATE_MAPPINGS_BTN: 'datastreamAddCustomComponentTemplateBtn',
Expand Down

0 comments on commit 8e4c019

Please sign in to comment.