-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Get rid of goToRuleDetails()
in favor of goToRuleDetailsOf()
#165011
Conversation
9765fac
to
dd44054
Compare
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
goToRuleDetails()
in favor of goToRuleDetailsOf()
739ad46
to
8343dab
Compare
@@ -603,6 +610,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({ | |||
<RuleSwitch | |||
id={rule?.id ?? '-1'} | |||
isDisabled={ | |||
!rule?.id || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! :+1
@@ -316,7 +318,7 @@ describe('Custom query rules', { tags: ['@ess', '@brokenInServerless'] }, () => | |||
const initialNumberOfRules = rules.length; | |||
const expectedNumberOfRulesAfterDeletion = initialNumberOfRules - 1; | |||
|
|||
goToTheRuleDetailsOf('New Rule Test'); | |||
goToRuleDetailsOf('New Rule Test'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create a variable with the test details and use RULE.name
here?
duplicateFirstRule(); | ||
goBackToRuleDetails(); | ||
goBackToRulesTable(); | ||
checkDuplicatedRule('Indicator rule duplicate test [Duplicate]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, can we do somthing like:
checkDuplicatedRule(`${RULE_NAME} [Duplicate]`);
login(); | ||
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL); | ||
goToRuleDetails(); | ||
cy.get(RULE_STATUS).should('have.text', '—'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is skipped anyway, but are we sure this assertion:
cy.get(RULE_STATUS).should('have.text', '—');
Is not important and safe to be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to say as the test is skipped. I'd say it waits for the page to be loaded and we ideally need to incapsulate it in a helper function but I revert this line just in case.
@@ -106,8 +106,8 @@ export const goToEndpointExceptionsTab = () => { | |||
}; | |||
|
|||
export const openEditException = (index = 0) => { | |||
cy.get(EXCEPTION_ITEM_ACTIONS_BUTTON).eq(index).click({ force: true }); | |||
cy.get(EDIT_EXCEPTION_BTN).eq(index).click({ force: true }); | |||
cy.get(EXCEPTION_ITEM_ACTIONS_BUTTON).eq(index).click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see we don't need this force
anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rules Management LGTM! And thanks for this refactor, super valuable; great fixes.
a098da1
to
1ee4b72
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DE changes LGTM, left a few comments
@@ -603,6 +610,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({ | |||
<RuleSwitch | |||
id={rule?.id ?? '-1'} | |||
isDisabled={ | |||
!rule || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could show some loading state instead of the rule's details UI while rule is not available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global loader is considered as bad UX nowadays and skeleton loading is much more preferable. We display as much as we can as early as possible to avoid the loader flickering. If you still think it's worth to show some loader instead I suggest to discuss it out of scope of this PR.
}; | ||
|
||
export const goToTheRuleDetailsOf = (ruleName: string) => { | ||
export const goToRuleDetailsOf = (ruleName: string) => { | ||
cy.contains(RULE_NAME, ruleName).click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious how this will work if we have several rules with exactly same name or if we have two rules named "Test Rule" and "Test Rule 1" and we go to details of the rule "Test Rule". Won't it potentially find another rule in those cases?
Just trying to understand if we can safely use same names in tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@e40pud you are right about the pitfalls. If goToRuleDetailsOf()
is used the rule names should be unique and distinguishable. If there are Test Rule
and Test Rule 1
rules then goToRuleDetailsOf('Test Rule')
opens the first rule in the table. So it has to be take into account.
In the case of exactly same names goToRuleDetailsOf()
shouldn't be used. it rather resembles how users distinguish rules. Despite id identifies rules uniquely it takes much more effort than just compare names so obviously user expect unique rule names.
it('Only modifies rule active status on enable/disable', () => { | ||
enablesRule(); | ||
const editedRuleData = getEditedRule(); | ||
const expectedEditedtags = editedRuleData.tags?.join(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could rename expectedEditedtags
into expectedEditedTags
to follow the rest of the names
db04d46
to
60eadb2
Compare
f7a8dbd
to
b788ee0
Compare
💔 Build FailedFailed CI StepsMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @maximpn |
Addresses: #164513
Summary
This PR gets rid of Rules Management
goToRuleDetails()
Cypress helper replacing it withgoToRuleDetailsOf()
.Details
The following has been done
goToRuleDetails()
replaced withgoToRuleDetailsOf()
where it makes sense (rule creation, scenarios validating something on the rules management table and then on the rule details page and etc).For quite a number of tests expectations are done on the rule details page but it's opened via rules management table page. In fact this unnecessary step may be flaky as rules table has auto resfresh feature and it should be ideally disabled as well as this requires loading of lazy UI resources and increases test's execution time. It can be avoided by directly opening the details page via
goToRuleDetails()
was removed from such tests in favor of opening the rule details page directly.Does opening rule detail page directly make the tests less stable?
Yes, it can give such side effect but it will help to either find and fix some bugs in our code or make our tests more robust by adding an universal page ready expectation.
While working on this PR I had to fix a few problems on the rule details page caused by getting rid of unnecessary opening rule details page via rules management table but it fact it revealed rule details page's problems
-1
is sent as rule id. In fact it's a page loading problem. Rule switch become available while the rule isn't loaded yet and it can be easily reproduced in prod if the connection is slow. Disabling rule switch while rule isn't loaded yet solves the problem.useEffect
causing HTTP request fired much more often than it should due to exception list types defined in place and regenerated each render causing the list item to be in loading state while the request is in progress. It was fixed by moving the arrays to stable constants.Flaky test runner
Security Solution Cypress tests (150 runs) (there is no indication of negative impact)