Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] [Exceptions] Fix Exception Auto-populate from Alert actions #159908

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e123658
populate the rule exception with the alert highlighted fields
WafaaNasr Jun 5, 2023
d618d0a
Merge branch 'main' of https://github.com/elastic/kibana into 6405-au…
WafaaNasr Jun 5, 2023
702f330
add initial tests for the helper methods
WafaaNasr Jun 7, 2023
8cf53cb
Merge branch 'main' of https://github.com/elastic/kibana into 6405-au…
WafaaNasr Jun 8, 2023
ee9d078
handle fieldValue entry in case of array
WafaaNasr Jun 8, 2023
9156746
Merge branch 'main' of https://github.com/elastic/kibana into 6405-au…
WafaaNasr Jun 9, 2023
115eff7
add tests
WafaaNasr Jun 9, 2023
a88527c
Merge branch 'main' of https://github.com/elastic/kibana into 6405-au…
WafaaNasr Jun 12, 2023
033842c
add cypress test
WafaaNasr Jun 12, 2023
94283e4
Merge branch 'main' of https://github.com/elastic/kibana into 6405-au…
WafaaNasr Jun 12, 2023
a0cca84
fix comment assertion
WafaaNasr Jun 12, 2023
d6da91a
address comments
WafaaNasr Jun 13, 2023
78aedc3
fix stale state of exceptionListItems
WafaaNasr Jun 13, 2023
4daff25
Merge branch 'main' of https://github.com/elastic/kibana into 6405-au…
WafaaNasr Jun 13, 2023
9519b5b
Merge branch 'main' of https://github.com/elastic/kibana into 6405-au…
WafaaNasr Jun 14, 2023
e78b92a
Merge branch 'main' of https://github.com/elastic/kibana into 6405-au…
WafaaNasr Jun 14, 2023
ace134a
revert back changes until see if cypress is trusted
WafaaNasr Jun 14, 2023
58f350a
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 15, 2023
aaf86d3
fix autopopulate
WafaaNasr Jun 15, 2023
54e0588
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 19, 2023
4932445
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 19, 2023
20aa5bb
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 19, 2023
0bc6b56
try to unskip validations
WafaaNasr Jun 19, 2023
87829b1
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 19, 2023
0aa23bb
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 19, 2023
d8c5c32
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 20, 2023
20a7a46
skip the validations
WafaaNasr Jun 20, 2023
7f11193
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 20, 2023
24ae54f
add meta prop to the exceptionItems on update
WafaaNasr Jun 20, 2023
4375245
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 21, 2023
86f8b19
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 21, 2023
9c684cf
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 21, 2023
21c404c
fix reseting the exceptionListItems
WafaaNasr Jun 21, 2023
d0780b0
add check for eventfilters flyout
WafaaNasr Jun 21, 2023
471a6ce
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 22, 2023
2e280fd
add cypress test to validate change exception item multiple times wit…
WafaaNasr Jun 23, 2023
1b28f82
add cypress case for deleting all prefilled fields
WafaaNasr Jun 23, 2023
1382430
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 23, 2023
94b4d88
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 23, 2023
f676400
Merge branch 'main' into fix-endpointexception-autopopulateAlertActions
WafaaNasr Jun 23, 2023
0468b11
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 26, 2023
76d41f9
fix comment open default status
WafaaNasr Jun 26, 2023
ab3b222
Merge branch 'fix-endpointexception-autopopulateAlertActions' of http…
WafaaNasr Jun 26, 2023
823fbd9
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 26, 2023
3e8a70d
add timeout to add_exception_btn
WafaaNasr Jun 26, 2023
37a9f68
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 26, 2023
cbaf0ec
remove unused memo var
WafaaNasr Jun 26, 2023
e5cae86
separate opening alert summary and click add exception
WafaaNasr Jun 26, 2023
7843461
remove extra check from addexception
WafaaNasr Jun 26, 2023
046574c
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 26, 2023
f147868
Merge branch 'main' into fix-endpointexception-autopopulateAlertActions
kibanamachine Jun 27, 2023
6d0c1d4
Merge branch 'main' of https://github.com/elastic/kibana into fix-end…
WafaaNasr Jun 28, 2023
eab421e
update translation to include id in the exception comment
WafaaNasr Jun 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useCallback, useEffect, useMemo, useReducer } from 'react';
import React, { useCallback, useEffect, useMemo, useReducer, useState } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
import styled from 'styled-components';
import { HttpStart } from '@kbn/core/public';
Expand Down Expand Up @@ -34,14 +34,14 @@ import {
} from '@kbn/securitysolution-list-utils';
import { DataViewBase } from '@kbn/es-query';
import type { AutocompleteStart } from '@kbn/unified-search-plugin/public';
import deepEqual from 'fast-deep-equal';

import { AndOrBadge } from '../and_or_badge';

import { BuilderExceptionListItemComponent } from './exception_item_renderer';
import { BuilderLogicButtons } from './logic_buttons';
import { getTotalErrorExist } from './selectors';
import { EntryFieldError, State, exceptionsBuilderReducer } from './reducer';

const MyInvisibleAndBadge = styled(EuiFlexItem)`
visibility: hidden;
`;
Expand Down Expand Up @@ -131,6 +131,7 @@ export const ExceptionBuilderComponent = ({
disableNested: isNestedDisabled,
disableOr: isOrDisabled,
});
const [areAllEntriesDeleted, setAreAllEntriesDeleted] = useState<boolean>(false);

const {
addNested,
Expand Down Expand Up @@ -252,6 +253,7 @@ export const ExceptionBuilderComponent = ({
// just add a default entry to it
if (updatedExceptions.length === 0) {
setDefaultExceptions(item);
setAreAllEntriesDeleted(true);
} else if (updatedExceptions.length > 0 && exceptionListItemSchema.is(item)) {
setUpdateExceptionsToDelete([...exceptionsToDelete, item]);
} else {
Expand Down Expand Up @@ -394,12 +396,36 @@ export const ExceptionBuilderComponent = ({
}
}, [exceptions, handleAddNewExceptionItem]);

/**
* This component relies on the "exceptionListItems" to pre-fill its entries,
* but any subsequent updates to the entries are not reflected back to
* the "exceptionListItems". To ensure correct behavior, we need to only
* fill the entries from the "exceptionListItems" during initialization.
*
* In the initialization phase, if there are "exceptionListItems" with
* pre-filled entries, the exceptions array will be empty. However,
* there are cases where the "exceptionListItems" may not be sent
* correctly during initialization, leading to the exceptions
* array being filled with empty entries. Therefore, we need to
* check if the exception is correctly populated with a valid
* "field" when the "exceptionListItems" has entries. that's why
* "exceptionsEntriesPopulated" is used
*
* It's important to differentiate this case from when the user
* deletes all the entries and the "exceptionListItems" has pre-filled values.
* that's why "allEntriesDeleted" is used
*
* deepEqual(exceptionListItems, exceptions) to handle the exceptionListItems in
* the EventFiltersFlyout
*/
useEffect(() => {
if (exceptionListItems.length > 0) {
if (!exceptionListItems.length || deepEqual(exceptionListItems, exceptions)) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think we can rename exceptionListItems to initialExceptions or similar as it's only used as an initial value?

const exceptionsEntriesPopulated = exceptions.some((exception) =>
exception.entries.some((entry) => entry.field)
);
if (!exceptionsEntriesPopulated && !areAllEntriesDeleted)
setUpdateExceptions(exceptionListItems);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [areAllEntriesDeleted, exceptionListItems, exceptions, setUpdateExceptions]);
Comment on lines +422 to +428
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd avoid such a custom logic which needs a long explanation in comment, if possible


if I understand correctly, the problem is that the content of exceptionListItems comes too late, only after first render. if we need to solve this issue inside the ExceptionBuilderComponent, I suggest to use refs, too, but in a more general way, something like this:

  const hasInitializedExceptionsRef = useRef<boolean>(false);

  useEffect(() => {
    if (!hasInitializedExceptionsRef.current && exceptionListItems.length > 0) {
      setUpdateExceptions(exceptionListItems);
      hasInitializedExceptionsRef.current = true;
    }
  }, [exceptionListItems, setUpdateExceptions]);

we can go even further, and modify the type of exceptionListItems so it is either null or array, so we know that if it's null, it's uninitialized.


another way would be to solve it on the outside of the component, i.e. we say that the contract of ExceptionBuilderComponent declares that it uses the content of exceptionListItems only in the first render. this requirement could be met by rendering the component conditionally, only after we got the content, e.g. like this:

x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/components/flyout_components/item_conditions/index.tsx:

      {exceptionListItems.length > 0 &&
        getExceptionBuilderComponentLazy({
          [...props come here...]
        })}

what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @gergoabraham, for your review. I appreciate your valid points, and I agree with you.

Regarding this component, we @yctercero have a plan to refactor it soon because any change currently leads to inconsistent behavior. I added a lengthy comment to explain why we have to handle each case individually in this unideal way. I considered your solution of using useRef, but unfortunately, after testing all the behaviors, I noticed that the component flashes when the user changes the fields or values.

So what we are trying to achieve here is to fix the issue with not causing any others, until we totally replace this component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this works and you're already planning to replace the component, I'm okay with this. 👍

regarding the useRef, could you describe the behaviour where the flashing happens? I don't experience anything similar, but I just tested it based on the video in the parent issue. (just added the useRef code snippet to main, so I didn't have your other modifications)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gergoabraham definitely agree with the points you made. I'd chatted with @WafaaNasr and she'd noted there should be a more thorough fix, but given we're in post-feature freeze zone, we're trying to stick to minimal changes that address the bug and follow up with a fix to address the underlying issue 8.10.

@WafaaNasr do we know if there's any existing ticket to describe some of the issues with this component? Maybe we should add the 8.10 candidate tag to it, and if not, create one to track for 8.10.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @gergoabraham! Regarding the flashing issue, it occurred when I deleted all the pre-filled fields on a Rule Exception and added new fields along with a name. I tried to capture it on video, but unfortunately, I couldn't catch it again.

@yctercero, I thought that would be part of this ticket, as part of the design, let me know if not I will create a new one.

Copy link
Contributor

@gergoabraham gergoabraham Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the explanation @yctercero @WafaaNasr, totally understandable! it's great that you already have a refactor ticket 👏


return (
<EuiFlexGroup gutterSize="s" direction="column" data-test-subj="exceptionsBuilderWrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import { deleteAlertsAndRules } from '../../../tasks/common';
import {
expandFirstAlert,
goToClosedAlertsOnRuleDetailsPage,
goToOpenedAlertsOnRuleDetailsPage,
openAddEndpointExceptionFromAlertActionButton,
openAddEndpointExceptionFromFirstAlert,
} from '../../../tasks/alerts';
import { login, visitWithoutDateRange } from '../../../tasks/login';
Expand All @@ -26,13 +28,22 @@ import {
} from '../../../tasks/es_archiver';
import { DETECTIONS_RULE_MANAGEMENT_URL } from '../../../urls/navigation';
import {
addExceptionEntryFieldValue,
addExceptionEntryFieldValueValue,
addExceptionFlyoutItemName,
editExceptionFlyoutItemName,
selectCloseSingleAlerts,
submitNewExceptionItem,
validateExceptionConditionField,
} from '../../../tasks/exceptions';
import { ALERTS_COUNT, EMPTY_ALERT_TABLE } from '../../../screens/alerts';
import { NO_EXCEPTIONS_EXIST_PROMPT } from '../../../screens/exceptions';
import {
ADD_AND_BTN,
EXCEPTION_CARD_ITEM_CONDITIONS,
EXCEPTION_CARD_ITEM_NAME,
EXCEPTION_ITEM_VIEWER_CONTAINER,
NO_EXCEPTIONS_EXIST_PROMPT,
} from '../../../screens/exceptions';
import {
removeException,
goToAlertsTab,
Expand All @@ -41,10 +52,11 @@ import {

describe('Endpoint Exceptions workflows from Alert', () => {
const expectedNumberOfAlerts = 1;
before(() => {
esArchiverResetKibana();
});
const ITEM_NAME = 'Sample Exception List Item';
const ITEM_NAME_EDIT = 'Sample Exception List Item';
const ADDITIONAL_ENTRY = 'host.hostname';
beforeEach(() => {
esArchiverResetKibana();
login();
deleteAlertsAndRules();
esArchiverLoad('endpoint');
Expand All @@ -69,7 +81,7 @@ describe('Endpoint Exceptions workflows from Alert', () => {
validateExceptionConditionField('file.Ext.code_signature');

selectCloseSingleAlerts();
addExceptionFlyoutItemName('Sample Exception');
addExceptionFlyoutItemName(ITEM_NAME);
submitNewExceptionItem();

// Alerts table should now be empty from having added exception and closed
Expand Down Expand Up @@ -100,4 +112,39 @@ describe('Endpoint Exceptions workflows from Alert', () => {

cy.get(ALERTS_COUNT).should('have.text', `${expectedNumberOfAlerts} alert`);
});

it('Should be able to create Endpoint exception from Alerts take action button, and change multiple exception items without resetting to initial auto-prefilled entries', () => {
// Open first Alert Summary
expandFirstAlert();

// The Endpoint should populated with predefined fields
openAddEndpointExceptionFromAlertActionButton();

// As the endpoint.alerts-* is used to trigger the alert the
// file.Ext.code_signature will be auto-populated
validateExceptionConditionField('file.Ext.code_signature');
addExceptionFlyoutItemName(ITEM_NAME);

cy.get(ADD_AND_BTN).click();
// edit conditions
addExceptionEntryFieldValue(ADDITIONAL_ENTRY, 6);
addExceptionEntryFieldValueValue('foo', 4);

// Change the name again
editExceptionFlyoutItemName(ITEM_NAME_EDIT);

// validate the condition is still "agent.name" or got rest after the name is changed
validateExceptionConditionField(ADDITIONAL_ENTRY);

selectCloseSingleAlerts();
submitNewExceptionItem();

// Endpoint Exception will move to Endpoint List under Exception tab of rule
goToEndpointExceptionsTab();

// new exception item displays
cy.get(EXCEPTION_ITEM_VIEWER_CONTAINER).should('have.length', 1);
cy.get(EXCEPTION_CARD_ITEM_NAME).should('have.text', ITEM_NAME_EDIT);
cy.get(EXCEPTION_CARD_ITEM_CONDITIONS).contains('span', ADDITIONAL_ENTRY);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import { createRule } from '../../../tasks/api_calls/rules';
import { goToRuleDetails } from '../../../tasks/alerts_detection_rules';
import {
addExceptionFromFirstAlert,
expandFirstAlert,
goToClosedAlertsOnRuleDetailsPage,
goToOpenedAlertsOnRuleDetailsPage,
openAddRuleExceptionFromAlertActionButton,
} from '../../../tasks/alerts';
import {
addExceptionEntryFieldValue,
Expand All @@ -26,6 +28,9 @@ import {
validateExceptionItemAffectsTheCorrectRulesInRulePage,
validateExceptionConditionField,
validateExceptionCommentCountAndText,
editExceptionFlyoutItemName,
validateHighlightedFieldsPopulatedAsExceptionConditions,
validateEmptyExceptionConditionField,
} from '../../../tasks/exceptions';
import {
esArchiverLoad,
Expand All @@ -42,26 +47,44 @@ import {

import { DETECTIONS_RULE_MANAGEMENT_URL } from '../../../urls/navigation';
import { postDataView, deleteAlertsAndRules } from '../../../tasks/common';
import { NO_EXCEPTIONS_EXIST_PROMPT } from '../../../screens/exceptions';
import {
ADD_AND_BTN,
ENTRY_DELETE_BTN,
EXCEPTION_CARD_ITEM_CONDITIONS,
EXCEPTION_CARD_ITEM_NAME,
EXCEPTION_ITEM_VIEWER_CONTAINER,
NO_EXCEPTIONS_EXIST_PROMPT,
} from '../../../screens/exceptions';
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';

const loadEndpointRuleAndAlerts = () => {
esArchiverLoad('endpoint');
login();
createRule(getEndpointRule());
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL);
goToRuleDetails();
waitForAlertsToPopulate();
};

describe('Rule Exceptions workflows from Alert', () => {
const EXPECTED_NUMBER_OF_ALERTS = '1 alert';
const ITEM_NAME = 'Sample Exception List Item';
const ITEM_NAME = 'Sample Exception Item';
const ITEM_NAME_EDIT = 'Sample Exception Item Edit';
const ADDITIONAL_ENTRY = 'host.hostname';
const newRule = getNewRule();

beforeEach(() => {
esArchiverResetKibana();
deleteAlertsAndRules();
});
after(() => {
esArchiverUnload('exceptions');
deleteAlertsAndRules();
});
afterEach(() => {
esArchiverUnload('exceptions_2');
});

it('Creates an exception item from alert actions overflow menu and close all matching alerts', () => {
it('Should create a Rule exception item from alert actions overflow menu and close all matching alerts', () => {
esArchiverLoad('exceptions');
login();
postDataView('exceptions-*');
Expand Down Expand Up @@ -119,14 +142,8 @@ describe('Rule Exceptions workflows from Alert', () => {

cy.get(ALERTS_COUNT).should('have.text', '2 alerts');
});

it('Creates an exception item from alert actions overflow menu and auto populate the conditions using alert Highlighted fields ', () => {
esArchiverLoad('endpoint');
login();
createRule(getEndpointRule());
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL);
goToRuleDetails();
waitForAlertsToPopulate();
it('Should create a Rule exception item from alert actions overflow menu and auto populate the conditions using alert Highlighted fields', () => {
loadEndpointRuleAndAlerts();

cy.get(LOADING_INDICATOR).should('not.exist');
addExceptionFromFirstAlert();
Expand All @@ -144,20 +161,120 @@ describe('Rule Exceptions workflows from Alert', () => {
* fields are based on the alert document that should be generated
* when the endpoint rule runs
*/
highlightedFieldsBasedOnAlertDoc.forEach((field, index) => {
validateExceptionConditionField(field);
});
validateHighlightedFieldsPopulatedAsExceptionConditions(highlightedFieldsBasedOnAlertDoc);

/**
* Validate that the comments are opened by default with one comment added
* showing a text contains information about the pre-filled conditions
*/
validateExceptionCommentCountAndText(
1,
'Exception conditions are pre-filled with relevant data from alert with "id"'
);

addExceptionFlyoutItemName(ITEM_NAME);
submitNewExceptionItem();
});
it('Should create a Rule exception from Alerts take action button and change multiple exception items without resetting to initial auto-prefilled entries', () => {
loadEndpointRuleAndAlerts();

cy.get(LOADING_INDICATOR).should('not.exist');

// Open first Alert Summary
expandFirstAlert();

// The Rule exception should populated with highlighted fields
openAddRuleExceptionFromAlertActionButton();

const highlightedFieldsBasedOnAlertDoc = [
'host.name',
'agent.id',
'user.name',
'process.executable',
'file.path',
];

/**
* Validate the highlighted fields are auto populated, these
* fields are based on the alert document that should be generated
* when the endpoint rule runs
*/
validateHighlightedFieldsPopulatedAsExceptionConditions(highlightedFieldsBasedOnAlertDoc);

/**
* Validate that the comments are opened by default with one comment added
* showing a text contains information about the pre-filled conditions
*/
validateExceptionCommentCountAndText(
1,
'Exception conditions are pre-filled with relevant data from'
'Exception conditions are pre-filled with relevant data from alert with "id"'
);

addExceptionFlyoutItemName(ITEM_NAME);

cy.get(ADD_AND_BTN).click();

// edit conditions
addExceptionEntryFieldValue(ADDITIONAL_ENTRY, 5);
addExceptionEntryFieldValueValue('foo', 5);

// Change the name again
editExceptionFlyoutItemName(ITEM_NAME_EDIT);

// validate the condition is still 'host.hostname' or got rest after the name is changed
validateExceptionConditionField(ADDITIONAL_ENTRY);

submitNewExceptionItem();

goToExceptionsTab();

// new exception item displays
cy.get(EXCEPTION_ITEM_VIEWER_CONTAINER).should('have.length', 1);
cy.get(EXCEPTION_CARD_ITEM_NAME).should('have.text', ITEM_NAME_EDIT);
cy.get(EXCEPTION_CARD_ITEM_CONDITIONS).contains('span', 'host.hostname');
});
it('Should delete all prefilled exception entries when creating a Rule exception from Alerts take action button without resetting to initial auto-prefilled entries', () => {
loadEndpointRuleAndAlerts();

cy.get(LOADING_INDICATOR).should('not.exist');

// Open first Alert Summary
expandFirstAlert();

// The Rule exception should populated with highlighted fields
openAddRuleExceptionFromAlertActionButton();

const highlightedFieldsBasedOnAlertDoc = [
'host.name',
'agent.id',
'user.name',
'process.executable',
'file.path',
];

/**
* Validate the highlighted fields are auto populated, these
* fields are based on the alert document that should be generated
* when the endpoint rule runs
*/
validateHighlightedFieldsPopulatedAsExceptionConditions(highlightedFieldsBasedOnAlertDoc);

/**
* Delete all the highlighted fields to see if any condition
* will prefuilled again.
*/
const highlightedFieldsCount = highlightedFieldsBasedOnAlertDoc.length - 1;
highlightedFieldsBasedOnAlertDoc.forEach((_, index) =>
cy
.get(ENTRY_DELETE_BTN)
.eq(highlightedFieldsCount - index)
.click()
);

/**
* Validate that there are no highlighted fields are auto populated
* after the deletion
*/
validateEmptyExceptionConditionField();
});
});
Loading