import { getException } from '../../objects/exception' ; import { getNewRule } from '../../objects/rule' ; import { ALERTS_COUNT , EMPTY_ALERT_TABLE , NUMBER_OF_ALERTS } from '../../screens/alerts' ; import { RULE_STATUS } from '../../screens/create_new_rule' ; import { addExceptionFromFirstAlert , goToClosedAlerts , goToManageAlertsDetectionRules , goToOpenedAlerts , waitForAlertsIndexToBeCreated , } from '../../tasks/alerts' ; import { createCustomRule } from '../../tasks/api_calls/rules' ; import { goToRuleDetails } from '../../tasks/alerts_detection_rules' ; import { waitForAlertsToPopulate } from '../../tasks/create_new_rule' ; import { esArchiverLoad , esArchiverUnload } from '../../tasks/es_archiver' ; import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login' ; import { activatesRule , addsException , goToAlertsTab , goToExceptionsTab , removeException , waitForTheRuleToBeExecuted , } from '../../tasks/rule_details' ; import { ALERTS_URL } from '../../urls/navigation' ; import { cleanKibana } from '../../tasks/common' ; describe ( 'From alert' , ( ) => { const NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS = '1 alert' ; beforeEach ( ( ) => { cleanKibana ( ) ; loginAndWaitForPageWithoutDateRange ( ALERTS_URL ) ; waitForAlertsIndexToBeCreated ( ) ; createCustomRule ( getNewRule ( ) , 'rule_testing' , '10s' ) ; goToManageAlertsDetectionRules ( ) ; goToRuleDetails ( ) ; cy . get ( RULE_STATUS ) . should ( 'have.text' , '—' ) ; esArchiverLoad ( 'auditbeat_for_exceptions' ) ; activatesRule ( ) ; waitForTheRuleToBeExecuted ( ) ; waitForAlertsToPopulate ( ) ; cy . get ( ALERTS_COUNT ) . should ( 'exist' ) ; cy . get ( NUMBER_OF_ALERTS ) . should ( 'have.text' , NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS ) ; } ) ; afterEach ( ( ) => { esArchiverUnload ( 'auditbeat_for_exceptions' ) ; esArchiverUnload ( 'auditbeat_for_exceptions2' ) ; } ) ; it ( 'Creates an exception and deletes it' , ( ) => { addExceptionFromFirstAlert ( ) ; addsException ( getException ( ) ) ; esArchiverLoad ( 'auditbeat_for_exceptions2' ) ; cy . get ( EMPTY_ALERT_TABLE ) . should ( 'exist' ) ; goToClosedAlerts ( ) ; cy . get ( ALERTS_COUNT ) . should ( 'exist' ) ; cy . get ( NUMBER_OF_ALERTS ) . should ( 'have.text' , `${ NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS }` ) ; goToOpenedAlerts ( ) ; waitForTheRuleToBeExecuted ( ) ; cy . get ( EMPTY_ALERT_TABLE ) . should ( 'exist' ) ; goToExceptionsTab ( ) ; removeException ( ) ; goToAlertsTab ( ) ; waitForTheRuleToBeExecuted ( ) ; waitForAlertsToPopulate ( ) ; cy . get ( ALERTS_COUNT ) . should ( 'exist' ) ; cy . get ( NUMBER_OF_ALERTS ) . should ( 'have.text' , `${ NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS }` ) ; } ) ; } ) ;