import { duplicatedRuleName } from '../objects/rule' ; import { BULK_ACTIONS_BTN , COLLAPSED_ACTION_BTN , CREATE_NEW_RULE_BTN , CUSTOM_RULES_BTN , DELETE_RULE_ACTION_BTN , DELETE_RULE_BULK_BTN , LOAD_PREBUILT_RULES_BTN , RULES_TABLE_INITIAL_LOADING_INDICATOR , RULES_TABLE_REFRESH_INDICATOR , RULES_TABLE_AUTOREFRESH_INDICATOR , PAGINATION_POPOVER_BTN , RELOAD_PREBUILT_RULES_BTN , RULE_CHECKBOX , RULE_NAME , RULE_SWITCH , RULE_SWITCH_LOADER , RULES_TABLE , SORT_RULES_BTN , EXPORT_ACTION_BTN , EDIT_RULE_ACTION_BTN , RULE_AUTO_REFRESH_IDLE_MODAL , RULE_AUTO_REFRESH_IDLE_MODAL_CONTINUE , rowsPerPageSelector , pageSelector , DUPLICATE_RULE_ACTION_BTN , DUPLICATE_RULE_MENU_PANEL_BTN , DUPLICATE_RULE_BULK_BTN , RULES_ROW , SELECT_ALL_RULES_BTN , MODAL_CONFIRMATION_BTN , RULES_DELETE_CONFIRMATION_MODAL , ACTIVATE_RULE_BULK_BTN , DEACTIVATE_RULE_BULK_BTN , RULE_DETAILS_DELETE_BTN , RULE_IMPORT_MODAL_BUTTON , RULE_IMPORT_MODAL , INPUT_FILE , TOASTER , RULE_IMPORT_OVERWRITE_CHECKBOX , RULE_IMPORT_OVERWRITE_EXCEPTIONS_CHECKBOX , } from '../screens/alerts_detection_rules' ; import { ALL_ACTIONS } from '../screens/rule_details' ; import { LOADING_INDICATOR } from '../screens/security_header' ; export const activateRule = ( rulePosition ) => { cy . get ( RULE_SWITCH ) . eq ( rulePosition ) . click ( { force : true } ) ; } ; export const editFirstRule = ( ) => { cy . get ( COLLAPSED_ACTION_BTN ) . should ( 'be.visible' ) ; cy . get ( COLLAPSED_ACTION_BTN ) . first ( ) . click ( { force : true } ) ; cy . get ( EDIT_RULE_ACTION_BTN ) . should ( 'be.visible' ) ; cy . get ( EDIT_RULE_ACTION_BTN ) . click ( ) ; } ; export const duplicateFirstRule = ( ) => { cy . get ( COLLAPSED_ACTION_BTN ) . should ( 'be.visible' ) ; cy . get ( COLLAPSED_ACTION_BTN ) . first ( ) . click ( { force : true } ) ; cy . get ( DUPLICATE_RULE_ACTION_BTN ) . should ( 'be.visible' ) ; cy . get ( DUPLICATE_RULE_ACTION_BTN ) . click ( ) ; } ; /**
 * Duplicates the rule from the menu and does additional
 * pipes and checking that the elements are present on the
 * page as well as removed when doing the clicks to help reduce
 * flake.
 */ export const duplicateRuleFromMenu = ( ) => { const click = ( $el ) => cy . wrap ( $el ) . click ( { force : true } ) ; cy . get ( LOADING_INDICATOR ) . should ( 'not.exist' ) ; cy . get ( ALL_ACTIONS ) . pipe ( click ) ; cy . get ( DUPLICATE_RULE_MENU_PANEL_BTN ) . should ( 'be.visible' ) ; cy . get ( DUPLICATE_RULE_MENU_PANEL_BTN ) . pipe ( click ) ; } ; /**
 * Check that the duplicated rule is on the table
 * and it is deactivated (default)
 */ export const checkDuplicatedRule = ( ) => { cy . contains ( RULE_NAME , duplicatedRuleName ) . parents ( RULES_ROW ) . find ( RULE_SWITCH ) . should ( 'have.attr' , 'aria-checked' , 'false' ) ; } ; export const deleteFirstRule = ( ) => { cy . get ( COLLAPSED_ACTION_BTN ) . first ( ) . click ( { force : true } ) ; cy . get ( DELETE_RULE_ACTION_BTN ) . click ( ) ; } ; export const deleteSelectedRules = ( ) => { cy . get ( BULK_ACTIONS_BTN ) . click ( { force : true } ) ; cy . get ( DELETE_RULE_BULK_BTN ) . click ( ) ; } ; export const deleteRuleFromDetailsPage = ( ) => { cy . get ( ALL_ACTIONS ) . should ( 'be.visible' ) ; cy . wait ( 1000 ) ; cy . get ( ALL_ACTIONS ) . click ( ) ; cy . get ( RULE_DETAILS_DELETE_BTN ) . should ( 'be.visible' ) ; cy . get ( RULE_DETAILS_DELETE_BTN ) . pipe ( ( $el ) => $el . trigger ( 'click' ) ) . should ( ( $el ) => expect ( $el ) . to . be . not . visible ) ; } ; export const duplicateSelectedRules = ( ) => { cy . get ( BULK_ACTIONS_BTN ) . click ( { force : true } ) ; cy . get ( DUPLICATE_RULE_BULK_BTN ) . click ( ) ; } ; export const activateSelectedRules = ( ) => { cy . get ( BULK_ACTIONS_BTN ) . click ( { force : true } ) ; cy . get ( ACTIVATE_RULE_BULK_BTN ) . click ( ) ; } ; export const deactivateSelectedRules = ( ) => { cy . get ( BULK_ACTIONS_BTN ) . click ( { force : true } ) ; cy . get ( DEACTIVATE_RULE_BULK_BTN ) . click ( ) ; } ; export const exportFirstRule = ( ) => { cy . get ( COLLAPSED_ACTION_BTN ) . first ( ) . click ( { force : true } ) ; cy . get ( EXPORT_ACTION_BTN ) . click ( ) ; cy . get ( EXPORT_ACTION_BTN ) . should ( 'not.exist' ) ; } ; export const filterByCustomRules = ( ) => { cy . get ( CUSTOM_RULES_BTN ) . click ( { force : true } ) ; waitForRulesTableToBeRefreshed ( ) ; } ; export const goToCreateNewRule = ( ) => { cy . get ( CREATE_NEW_RULE_BTN ) . click ( { force : true } ) ; } ; export const goToRuleDetails = ( ) => { cy . get ( RULE_NAME ) . first ( ) . click ( { force : true } ) ; } ; export const goToTheRuleDetailsOf = ( ruleName ) => { cy . get ( RULE_NAME ) . contains ( ruleName ) . click ( ) ; } ; export const loadPrebuiltDetectionRules = ( ) => { cy . get ( LOAD_PREBUILT_RULES_BTN ) . should ( 'exist' ) . click ( { force : true } ) ; } ; export const reloadDeletedRules = ( ) => { cy . get ( RELOAD_PREBUILT_RULES_BTN ) . click ( { force : true } ) ; } ; param numberOfRules export const selectNumberOfRules = ( numberOfRules ) => { for ( let i = 0 ; i < numberOfRules ; i ++ ) { cy . get ( RULE_CHECKBOX ) . eq ( i ) . pipe ( ( $el ) => $el . trigger ( 'click' ) ) . should ( 'be.checked' ) ; } } ; export const selectAllRules = ( ) => { cy . get ( SELECT_ALL_RULES_BTN ) . contains ( 'Select all' ) . click ( ) ; cy . get ( SELECT_ALL_RULES_BTN ) . contains ( 'Clear' ) ; } ; export const confirmRulesDelete = ( ) => { cy . get ( RULES_DELETE_CONFIRMATION_MODAL ) . should ( 'be.visible' ) ; cy . get ( MODAL_CONFIRMATION_BTN ) . click ( ) ; cy . get ( RULES_DELETE_CONFIRMATION_MODAL ) . should ( 'not.exist' ) ; } ; export const sortByActivatedRules = ( ) => { cy . get ( SORT_RULES_BTN ) . contains ( 'Activated' ) . click ( { force : true } ) ; waitForRulesTableToBeRefreshed ( ) ; cy . get ( SORT_RULES_BTN ) . contains ( 'Activated' ) . click ( { force : true } ) ; waitForRulesTableToBeRefreshed ( ) ; } ; export const waitForRulesTableToBeLoaded = ( ) => { cy . get ( RULES_TABLE_INITIAL_LOADING_INDICATOR ) . should ( 'exist' ) ; cy . get ( RULES_TABLE_INITIAL_LOADING_INDICATOR , { timeout : 300000 } ) . should ( 'not.exist' ) ; } ; export const waitForRulesTableToBeRefreshed = ( ) => { cy . get ( RULES_TABLE_REFRESH_INDICATOR ) . should ( 'exist' ) ; cy . get ( RULES_TABLE_REFRESH_INDICATOR ) . should ( 'not.exist' ) ; } ; export const waitForPrebuiltDetectionRulesToBeLoaded = ( ) => { cy . get ( LOAD_PREBUILT_RULES_BTN ) . should ( 'not.exist' ) ; cy . get ( RULES_TABLE ) . should ( 'exist' ) ; cy . get ( RULES_TABLE_REFRESH_INDICATOR ) . should ( 'not.exist' ) ; } ; export const waitForRuleToChangeStatus = ( ) => { cy . get ( RULE_SWITCH_LOADER ) . should ( 'exist' ) ; cy . get ( RULE_SWITCH_LOADER ) . should ( 'not.exist' ) ; } ; export const checkAutoRefresh = ( ms , condition ) => { cy . get ( RULES_TABLE_AUTOREFRESH_INDICATOR ) . should ( 'not.exist' ) ; cy . tick ( ms ) ; cy . get ( RULES_TABLE_AUTOREFRESH_INDICATOR ) . should ( condition ) ; } ; export const dismissAllRulesIdleModal = ( ) => { cy . get ( RULE_AUTO_REFRESH_IDLE_MODAL_CONTINUE ) . eq ( 1 ) . should ( 'exist' ) . click ( { force : true , multiple : true } ) ; cy . get ( RULE_AUTO_REFRESH_IDLE_MODAL ) . should ( 'not.exist' ) ; } ; export const checkAllRulesIdleModal = ( condition ) => { cy . tick ( 2700000 ) ; cy . get ( RULE_AUTO_REFRESH_IDLE_MODAL ) . should ( condition ) ; } ; export const resetAllRulesIdleModalTimeout = ( ) => { cy . tick ( 2000000 ) ; cy . window ( ) . trigger ( 'mousemove' , { force : true } ) ; cy . tick ( 700000 ) ; } ; export const changeRowsPerPageTo = ( rowsCount ) => { cy . get ( PAGINATION_POPOVER_BTN ) . click ( { force : true } ) ; cy . get ( rowsPerPageSelector ( rowsCount ) ) . pipe ( ( $el ) => $el . trigger ( 'click' ) ) . should ( 'not.be.visible' ) ; waitForRulesTableToBeRefreshed ( ) ; } ; export const changeRowsPerPageTo100 = ( ) => { changeRowsPerPageTo ( 100 ) ; } ; export const goToPage = ( pageNumber ) => { cy . get ( RULES_TABLE_REFRESH_INDICATOR ) . should ( 'not.exist' ) ; cy . get ( pageSelector ( pageNumber ) ) . last ( ) . click ( { force : true } ) ; waitForRulesTableToBeRefreshed ( ) ; } ; export const importRules = ( rulesFile ) => { cy . get ( RULE_IMPORT_MODAL ) . click ( ) ; cy . get ( INPUT_FILE ) . should ( 'exist' ) ; cy . get ( INPUT_FILE ) . trigger ( 'click' , { force : true } ) . attachFile ( rulesFile ) . trigger ( 'change' ) ; cy . get ( RULE_IMPORT_MODAL_BUTTON ) . last ( ) . click ( { force : true } ) ; cy . get ( INPUT_FILE ) . should ( 'not.exist' ) ; } ; export const getRulesImportToast = ( headers ) => { cy . get ( TOASTER ) . should ( 'exist' ) . then ( ( $els ) => { const arrayOfText = Cypress . $ . makeArray ( $els ) . map ( ( el ) => el . innerText ) ; return headers . reduce ( ( areAllIncluded , header ) => { const isContained = arrayOfText . includes ( header ) ; if ( ! areAllIncluded ) { return false ; } else { return isContained ; } } , true ) ; } ) . should ( 'be.true' ) ; } ; export const selectOverwriteRulesImport = ( ) => { cy . get ( RULE_IMPORT_OVERWRITE_CHECKBOX ) . pipe ( ( $el ) => $el . trigger ( 'click' ) ) . should ( 'be.checked' ) ; } ; export const selectOverwriteExceptionsRulesImport = ( ) => { cy . get ( RULE_IMPORT_OVERWRITE_EXCEPTIONS_CHECKBOX ) . pipe ( ( $el ) => $el . trigger ( 'click' ) ) . should ( 'be.checked' ) ; } ; export const importRulesWithOverwriteAll = ( rulesFile ) => { cy . get ( RULE_IMPORT_MODAL ) . click ( ) ; cy . get ( INPUT_FILE ) . should ( 'exist' ) ; cy . get ( INPUT_FILE ) . trigger ( 'click' , { force : true } ) . attachFile ( rulesFile ) . trigger ( 'change' ) ; selectOverwriteRulesImport ( ) ; selectOverwriteExceptionsRulesImport ( ) ; cy . get ( RULE_IMPORT_MODAL_BUTTON ) . last ( ) . click ( { force : true } ) ; cy . get ( INPUT_FILE ) . should ( 'not.exist' ) ; } ;