Skip to content

Commit

Permalink
Merge branch 'endpoint-isolate-e2e-coverage-multipass' into endpoint-…
Browse files Browse the repository at this point in the history
…e2e-coverage-multipass
  • Loading branch information
szwarckonrad committed Apr 24, 2023
2 parents 678aaa7 + 2b07574 commit 7b8fe2a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 15 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { renderHook } from '@testing-library/react-hooks';
import type { XYState } from '@kbn/lens-plugin/public';
import { wrapper } from '../../../mocks';

import { useLensAttributes } from '../../../use_lens_attributes';
Expand Down Expand Up @@ -56,4 +57,42 @@ describe('getRiskScoreOverTimeAreaAttributes', () => {

expect(result?.current).toMatchSnapshot();
});

it('should render a Reference Line with an Alert icon', () => {
const { result } = renderHook(
() =>
useLensAttributes({
getLensAttributes: getRiskScoreOverTimeAreaAttributes,
stackByField: 'host',
extraOptions: {
spaceId: 'mockSpaceId',
},
}),
{ wrapper }
);

expect(
(result?.current?.state.visualization as XYState).layers.find(
(layer) => layer.layerType === 'referenceLine'
)
).toEqual(
expect.objectContaining({
layerId: '1dd5663b-f062-43f8-8688-fc8166c2ca8e',
layerType: 'referenceLine',
accessors: ['1dd5663b-f062-43f8-8688-fc8166c2ca8e'],
yConfig: [
{
forAccessor: '1dd5663b-f062-43f8-8688-fc8166c2ca8e',
axisMode: 'left',
lineWidth: 2,
color: '#aa6556',
icon: 'alert',
textVisibility: true,
fill: 'none',
iconPosition: 'left',
},
],
})
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const getRiskScoreOverTimeAreaAttributes: GetLensAttributes = (
axisMode: 'left',
lineWidth: 2,
color: '#aa6556',
icon: 'warning',
icon: 'alert',
textVisibility: true,
fill: 'none',
iconPosition: 'left',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Isolate command', () => {
cy.getByTestSubj('hostIsolateConfirmButton').click();
cy.contains(`Isolation on host ${endpointHostname} successfully submitted`);
cy.getByTestSubj('euiFlyoutCloseButton').click();
cy.getByTestSubj('rowIsolationStatus').should('contain.text', 'Isolated');
cy.getByTestSubj('rowHostStatus-actionStatuses').should('contain.text', 'Isolated');
filterOutIsolatedHosts();

checkEndpointListForIsolatedHosts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const API_ENDPOINT_ACTION_PATH = '/api/endpoint/action/*';
export const interceptActionRequests = (
cb: (responseBody: ActionDetails) => void,
alias: string
) => {
): void => {
cy.intercept('POST', API_ENDPOINT_ACTION_PATH, (req) => {
req.continue((res) => {
const {
Expand All @@ -24,36 +24,37 @@ export const interceptActionRequests = (
}).as(alias);
};

export const sendActionResponse = (action: ActionDetails) => {
export const sendActionResponse = (action: ActionDetails): void => {
cy.task('sendHostActionResponse', {
action,
state: { state: 'success' },
});
};

export const isolateHostWithComment = (comment: string, hostname: string) => {
export const isolateHostWithComment = (comment: string, hostname: string): void => {
cy.getByTestSubj('isolate-host-action-item').click();
cy.contains(`Isolate host ${hostname} from network.`);
cy.getByTestSubj('endpointHostIsolationForm');
cy.getByTestSubj('host_isolation_comment').type(comment);
};

export const releaseHostWithComment = (comment: string, hostname: string) => {
export const releaseHostWithComment = (comment: string, hostname: string): void => {
cy.contains(`${hostname} is currently isolated.`);
cy.getByTestSubj('endpointHostIsolationForm');
cy.getByTestSubj('host_isolation_comment').type(comment);
};

export const openAlertDetails = () => {
export const openAlertDetails = (): void => {
cy.getByTestSubj('expand-event').first().click();
cy.getByTestSubj('take-action-dropdown-btn').click();
};

export const openCaseAlertDetails = (alertId: string) => {
export const openCaseAlertDetails = (alertId: string): void => {
cy.getByTestSubj(`comment-action-show-alert-${alertId}`).click();
cy.getByTestSubj('take-action-dropdown-btn').click();
};
export const waitForReleaseOption = (alertId: string) => {

export const waitForReleaseOption = (alertId: string): void => {
openCaseAlertDetails(alertId);
cy.getByTestSubj('event-field-agent.status').then(($status) => {
if ($status.find('[title="Isolated"]').length > 0) {
Expand All @@ -73,7 +74,7 @@ export const visitRuleAlerts = (ruleName: string) => {
cy.visit('/app/security/rules');
cy.contains(ruleName).click();
};
export const checkFlyoutEndpointIsolation = () => {
export const checkFlyoutEndpointIsolation = (): void => {
cy.getByTestSubj('event-field-agent.status').then(($status) => {
if ($status.find('[title="Isolated"]').length > 0) {
cy.contains('Release host').click();
Expand All @@ -89,7 +90,7 @@ export const checkFlyoutEndpointIsolation = () => {
});
};

export const toggleRuleOffAndOn = (ruleName: string) => {
export const toggleRuleOffAndOn = (ruleName: string): void => {
cy.visit('/app/security/rules');
cy.wait(2000);
cy.contains(ruleName)
Expand All @@ -103,7 +104,7 @@ export const toggleRuleOffAndOn = (ruleName: string) => {
});
};

export const filterOutEndpoints = (endpointHostname: string) => {
export const filterOutEndpoints = (endpointHostname: string): void => {
cy.getByTestSubj('filters-global-container').within(() => {
cy.getByTestSubj('queryInput').click().type(`host.hostname : "${endpointHostname}"`);
cy.getByTestSubj('querySubmitButton').click();
Expand All @@ -123,12 +124,12 @@ export const createAgentPolicyTask = (
}).then(cb);
};

export const filterOutIsolatedHosts = () => {
export const filterOutIsolatedHosts = (): void => {
cy.getByTestSubj('adminSearchBar').click().type('united.endpoint.Endpoint.state.isolation: true');
cy.getByTestSubj('querySubmitButton').click();
};

export const checkEndpointListForIsolatedHosts = (expectIsolated = true) => {
export const checkEndpointListForIsolatedHosts = (expectIsolated = true): void => {
const chainer = expectIsolated ? 'contain.text' : 'not.contain.text';
cy.getByTestSubj('endpointListTable').within(() => {
cy.get('tbody tr').each(($tr) => {
Expand Down

0 comments on commit 7b8fe2a

Please sign in to comment.