Skip to content

Commit 7fa8bca

Browse files
committed
Add assertions to our rule creation test
Asserts that our rule form repopulates with the provided values when going back to a previous step. This is to cover a regression that was not caught by CI (but which has now been fixed).
1 parent b174270 commit 7fa8bca

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import {
5858
createAndActivateRule,
5959
fillAboutRuleAndContinue,
6060
fillDefineCustomRuleWithImportedQueryAndContinue,
61+
expectDefineFormToRepopulateAndContinue,
62+
expectAboutFormToRepopulateAndContinue,
6163
} from '../tasks/create_new_rule';
6264
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
6365
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';
@@ -82,6 +84,8 @@ describe('Detection rules, custom', () => {
8284
goToCreateNewRule();
8385
fillDefineCustomRuleWithImportedQueryAndContinue(newRule);
8486
fillAboutRuleAndContinue(newRule);
87+
expectDefineFormToRepopulateAndContinue(newRule);
88+
expectAboutFormToRepopulateAndContinue(newRule);
8589
createAndActivateRule();
8690

8791
cy.get(CUSTOM_RULES_BTN).invoke('text').should('eql', 'Custom rules (1)');

x-pack/plugins/security_solution/cypress/screens/create_new_rule.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
export const ABOUT_CONTINUE_BTN = '[data-test-subj="about-continue"]';
88

9+
export const ABOUT_EDIT_BUTTON = '[data-test-subj="edit-about-rule"]';
10+
911
export const ADD_FALSE_POSITIVE_BTN =
1012
'[data-test-subj="detectionEngineStepAboutRuleFalsePositives"] .euiButtonEmpty__text';
1113

@@ -26,6 +28,8 @@ export const CUSTOM_QUERY_INPUT = '[data-test-subj="queryInput"]';
2628

2729
export const DEFINE_CONTINUE_BUTTON = '[data-test-subj="define-continue"]';
2830

31+
export const DEFINE_EDIT_BUTTON = '[data-test-subj="edit-define-rule"]';
32+
2933
export const IMPORT_QUERY_FROM_SAVED_TIMELINE_LINK =
3034
'[data-test-subj="importQueryFromSavedTimeline"]';
3135

x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import {
4848
THRESHOLD_FIELD_SELECTION,
4949
THRESHOLD_INPUT_AREA,
5050
THRESHOLD_TYPE,
51+
DEFINE_EDIT_BUTTON,
52+
ABOUT_EDIT_BUTTON,
5153
} from '../screens/create_new_rule';
5254
import { TIMELINE } from '../screens/timeline';
5355

@@ -175,6 +177,20 @@ export const fillDefineCustomRuleWithImportedQueryAndContinue = (
175177
cy.get(CUSTOM_QUERY_INPUT).should('not.exist');
176178
};
177179

180+
export const expectDefineFormToRepopulateAndContinue = (rule: CustomRule) => {
181+
cy.get(DEFINE_EDIT_BUTTON).click();
182+
cy.get(CUSTOM_QUERY_INPUT).invoke('text').should('eq', rule.customQuery);
183+
cy.get(DEFINE_CONTINUE_BUTTON).should('exist').click({ force: true });
184+
cy.get(DEFINE_CONTINUE_BUTTON).should('not.exist');
185+
};
186+
187+
export const expectAboutFormToRepopulateAndContinue = (rule: CustomRule) => {
188+
cy.get(ABOUT_EDIT_BUTTON).click();
189+
cy.get(RULE_NAME_INPUT).invoke('val').should('eq', rule.name);
190+
cy.get(ABOUT_CONTINUE_BTN).should('exist').click({ force: true });
191+
cy.get(ABOUT_CONTINUE_BTN).should('not.exist');
192+
};
193+
178194
export const fillDefineThresholdRuleAndContinue = (rule: ThresholdRule) => {
179195
const thresholdField = 0;
180196
const threshold = 1;

x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ const CreateRulePageComponent: React.FC = () => {
310310
extraAction={
311311
stepsData.current[RuleStep.defineRule].isValid && (
312312
<EuiButtonEmpty
313+
data-test-subj="edit-define-rule"
313314
iconType="pencil"
314315
size="xs"
315316
onClick={manageIsEditable.bind(null, RuleStep.defineRule)}
@@ -343,6 +344,7 @@ const CreateRulePageComponent: React.FC = () => {
343344
extraAction={
344345
stepsData.current[RuleStep.aboutRule].isValid && (
345346
<EuiButtonEmpty
347+
data-test-subj="edit-about-rule"
346348
iconType="pencil"
347349
size="xs"
348350
onClick={manageIsEditable.bind(null, RuleStep.aboutRule)}

0 commit comments

Comments
 (0)