Skip to content

Commit

Permalink
adds flyout validation and edit workflow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Mar 2, 2023
1 parent 2ceaa64 commit 55feb39
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const ExceptionItemCardMetaInfo = memo<ExceptionItemCardMetaInfoProps>(
</EuiFlexItem>
{item.expire_time != null && (
<>
<EuiFlexItem css={itemCss} grow={false}>
<EuiFlexItem css={itemCss} grow={false} data-test-subj="metaInfoExpireTime">
<MetaInfoDetails
label={
isExpired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
addExceptionEntryOperatorValue,
addExceptionFlyoutItemName,
closeExceptionBuilderFlyout,
editExceptionFlyoutExpireTime,
} from '../../../tasks/exceptions';
import {
ADD_AND_BTN,
Expand Down Expand Up @@ -321,6 +322,28 @@ describe('Exceptions flyout', () => {
closeExceptionBuilderFlyout();
});

it('Validates expire time field correctly', () => {
// open add exception modal
openExceptionFlyoutFromEmptyViewerPrompt();

// add exception item name
addExceptionFlyoutItemName('My item name');

// add an entry with a value and submit button should enable
addExceptionEntryFieldValue('agent.name', 0);
addExceptionEntryFieldValueValue('test', 0);

// set an expiration date in the past
editExceptionFlyoutExpireTime(new Date(Date.now() - 1000000).toISOString());
cy.get(CONFIRM_BTN).should('be.disabled');

// set an expiration date in the future
editExceptionFlyoutExpireTime(new Date(Date.now() + 1000000).toISOString());
cy.get(CONFIRM_BTN).should('be.enabled');

closeExceptionBuilderFlyout();
});

// TODO - Add back in error states into modal
describe.skip('flyout errors', () => {
beforeEach(() => {
Expand All @@ -341,6 +364,7 @@ describe('Exceptions flyout', () => {
value: ['some host', 'another host'],
},
],
expire_time: undefined,
});

reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import {
addExceptionConditions,
addExceptionFlyoutItemName,
clearExceptionFlyoutExpireTime,
editException,
editExceptionFlyoutItemName,
selectAddToRuleRadio,
Expand All @@ -56,6 +57,7 @@ import {
EXCEPTION_CARD_ITEM_NAME,
EXCEPTION_CARD_ITEM_CONDITIONS,
FIELD_INPUT_PARENT,
EXCEPTION_CARD_ITEM_META_INFO,
} from '../../../screens/exceptions';
import {
createExceptionList,
Expand Down Expand Up @@ -118,6 +120,7 @@ describe('Add/edit exception from rule details', () => {
value: ['foo'],
},
],
expire_time: new Date(Date.now() + 1000000).toISOString(),
});
});

Expand All @@ -135,6 +138,7 @@ describe('Add/edit exception from rule details', () => {
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('not.exist');
cy.get(EXCEPTION_CARD_ITEM_NAME).should('have.text', ITEM_NAME);
cy.get(EXCEPTION_CARD_ITEM_CONDITIONS).should('have.text', ' unique_value.testis one of foo');
cy.get(EXCEPTION_CARD_ITEM_META_INFO).should('exist');

// open edit exception modal
openEditException();
Expand All @@ -152,6 +156,7 @@ describe('Add/edit exception from rule details', () => {

// edit conditions
editException(FIELD_DIFFERENT_FROM_EXISTING_ITEM_FIELD, 0, 0);
clearExceptionFlyoutExpireTime();

// submit
submitEditedExceptionItem();
Expand All @@ -162,6 +167,7 @@ describe('Add/edit exception from rule details', () => {
// check that updates stuck
cy.get(EXCEPTION_CARD_ITEM_NAME).should('have.text', NEW_ITEM_NAME);
cy.get(EXCEPTION_CARD_ITEM_CONDITIONS).should('have.text', ' agent.nameIS foo');
cy.get(EXCEPTION_CARD_ITEM_META_INFO).should('not.exist');
});

describe('rule with existing shared exceptions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ExceptionListItem {
tags: string[];
type: 'simple';
entries: Array<{ field: string; operator: string; type: string; value: string[] }>;
expire_time: string | undefined;
}

export const getExceptionList = (): ExceptionList => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export const EXCEPTION_CARD_ITEM_NAME = '[data-test-subj="exceptionItemCardHeade
export const EXCEPTION_CARD_ITEM_CONDITIONS =
'[data-test-subj="exceptionItemCardConditions-condition"]';

export const EXCEPTION_CARD_ITEM_META_INFO =
'[data-test-subj="exceptionItemCardMetaInfo-expireTime-value1"]';

// Exception flyout components
export const EXCEPTION_ITEM_NAME_INPUT = 'input[data-test-subj="exceptionFlyoutNameInput"]';

Expand All @@ -123,3 +126,6 @@ export const MANAGE_EXCEPTION_CREATE_BUTTON_EXCEPTION =
'[data-test-subj="manageExceptionListCreateExceptionButton"]';

export const RULE_ACTION_LINK_RULE_SWITCH = '[data-test-subj="ruleActionLinkRuleSwitch"]';

export const EXCEPTION_ITEM_EXPIRE_TIME_INPUT =
'[data-test-subj="exceptionExpireTimeInputRow"] input.euiDatePicker';
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const createExceptionListItem = (
value: ['some host', 'another host'],
},
],
expire_time: exceptionListItem?.expire_time,
},
headers: { 'kbn-xsrf': 'cypress-creds' },
failOnStatusCode: false,
Expand Down
20 changes: 20 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import moment from 'moment';
import type { Exception } from '../objects/exception';
import {
FIELD_INPUT,
Expand All @@ -24,6 +25,7 @@ import {
SHARED_LIST_SWITCH,
OS_SELECTION_SECTION,
OS_INPUT,
EXCEPTION_ITEM_EXPIRE_TIME_INPUT,
} from '../screens/exceptions';

export const addExceptionEntryFieldValueOfItemX = (
Expand Down Expand Up @@ -93,6 +95,24 @@ export const editExceptionFlyoutItemName = (name: string) => {
.should('have.value', name);
};

export const editExceptionFlyoutExpireTime = (date: string) => {
const formattedDate = moment(new Date(date).toISOString()).format('MM DD YYYY hh:mm a');
cy.root()
.pipe(($el) => {
return $el.find(EXCEPTION_ITEM_EXPIRE_TIME_INPUT);
})
.clear()
.type(`${formattedDate}{enter}`);
};

export const clearExceptionFlyoutExpireTime = () => {
cy.root()
.pipe(($el) => {
return $el.find(EXCEPTION_ITEM_EXPIRE_TIME_INPUT);
})
.clear();
};

export const selectBulkCloseAlerts = () => {
cy.get(CLOSE_ALERTS_CHECKBOX).should('exist');
cy.get(CLOSE_ALERTS_CHECKBOX).click({ force: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ const ExceptionItemExpireTime: React.FC<ExceptionItmeExpireTimeProps> = ({
<h3>{i18n.EXCEPTION_EXPIRE_TIME_HEADER}</h3>
</SectionHeader>
<EuiSpacer size="s" />
<EuiFormRow error={errors} isInvalid={isInvalid} label={i18n.EXPIRE_TIME_LABEL}>
<EuiFormRow
data-test-subj="exceptionExpireTimeInputRow"
error={errors}
isInvalid={isInvalid}
label={i18n.EXPIRE_TIME_LABEL}
>
<EuiDatePicker
placeholder="Select an expiration date"
showTimeSelect
selected={dateTime}
isInvalid={isInvalid}
Expand Down

0 comments on commit 55feb39

Please sign in to comment.