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

[Investigations] - Unskip and refactor discover state tests #173308

Merged
merged 8 commits into from
Jan 16, 2024

Conversation

@michaelolo24 michaelolo24 added release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting:Investigations Security Solution Investigations Team labels Dec 13, 2023
@michaelolo24 michaelolo24 force-pushed the unskip-discover-state-tests branch from 512e901 to d258f4f Compare December 18, 2023 17:24
@michaelolo24 michaelolo24 marked this pull request as ready for review December 18, 2023 17:25
@michaelolo24 michaelolo24 requested a review from a team as a code owner December 18, 2023 17:25
Copy link
Contributor

@PhilippeOberti PhilippeOberti left a comment

Choose a reason for hiding this comment

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

I left a few comments of extra things to potentially cleanup

createNewTimeline,
createTimelineOptionsPopoverBottomBar,
Copy link
Contributor

Choose a reason for hiding this comment

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

this method does not exist in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebase error, fixing

login();
visitWithTimeRange(ALERTS_URL);
createTimelineOptionsPopoverBottomBar();
goToEsqlTab();
Copy link
Contributor

Choose a reason for hiding this comment

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

diving into this function, I think we should remove the should('be.visible') here (Cypress already checks for visibility)

Copy link
Contributor

Choose a reason for hiding this comment

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

also I'm wondering if we could remove the about the delay 500? We're not using that delay in the expandable flyout Cypress tests and I don't remember seeing a test fail because of that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove should('be.visible'), and I figure the delay was put there because of how long it can take for the elements in the timeline tabs to load, but if it is necessary, there are definitely better ways of doing it besides an explicit delay time. Will look into it

describe('save/restore', () => {
beforeEach(() => {
handleIntercepts();
});
it('should be able create an empty timeline with default discover state', () => {
addNameToTimelineAndSave('Timerange timeline');
createNewTimeline();
Copy link
Contributor

Choose a reason for hiding this comment

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

diving into this function, we should be able to remove the should('be.visible') here (Cypress already checks for visibility)

Copy link
Contributor

Choose a reason for hiding this comment

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

same thing like 123, looking into the addDiscoverEsqlQuery function, should('be.visible') from here

Copy link
Contributor

Choose a reason for hiding this comment

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

also, line 136, looking into the openTimelineFromSettings function, I think we should be able to delete this line entirely

Copy link
Contributor

Choose a reason for hiding this comment

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

let's remove it from here as well, and also the force: true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just gonna remove all of them in the timeline related files

Comment on lines 362 to 371
export const confirmLeaveUnsavedTimeline = () => {
cy.get(DELETION_CONFIRMATION).click();
};

export const deleteTimeline = () => {
cy.get(TIMELINE_COLLAPSED_ITEMS_BTN).click();
cy.get(DELETE_TIMELINE_BTN).click();
cy.get(DELETION_CONFIRMATION).click();
};

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm getting errors where these constants are not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebase error, will address, thanks!

@@ -212,6 +203,7 @@ describe.skip(
cy.wait(`@${TIMELINE_REQ_WITH_SAVED_SEARCH}`);
openKibanaNavigation();
navigateFromKibanaCollapsibleTo(STACK_MANAGEMENT_PAGE);
confirmLeaveUnsavedTimeline();
cy.get(LOADING_INDICATOR).should('not.exist');
goToSavedObjectSettings();
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a chance we could remove line 11 and 12 of this goToSavedObjectSettings no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, will do

@@ -212,6 +203,7 @@ describe.skip(
cy.wait(`@${TIMELINE_REQ_WITH_SAVED_SEARCH}`);
openKibanaNavigation();
navigateFromKibanaCollapsibleTo(STACK_MANAGEMENT_PAGE);
confirmLeaveUnsavedTimeline();
cy.get(LOADING_INDICATOR).should('not.exist');
goToSavedObjectSettings();
cy.get(LOADING_INDICATOR).should('not.exist');
Copy link
Contributor

Choose a reason for hiding this comment

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

should we extract the line below into a task function? (cy.get(SAVED_OBJECTS_TAGS_FILTER).trigger('click');)

Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about removing the nested describes (line 105 describe('save/restore', () => { and line 194 describe('saved search', () => {)?
With clear text title I don't think the describe are necessary. They both have the same beforeEach code so that should work. It would make the file a bit easier to read.

Also I wonder if we could move the const handleIntercepts method above the top describe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, will move the handle intercepts up, but I lean leaving the nested describe blocks as while all the beforeEach logic is the same, the context of what each block is testing is different, but I'll rename them to make them clearer

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of using describe just to separate tests like this but I'm not totally against it either 😄

If we keep these nested describe, let's update the test titles to not contains the same string then? We probably don't need the repetition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I had updated the titles in the last commit :)

@michaelolo24 michaelolo24 requested a review from a team as a code owner January 15, 2024 15:08
@janmonschke
Copy link
Contributor

@kqualters-elastic Could you have a look at e770e35? I noticed that with the original fix, it would still sometimes create two saved searches.

@kibana-ci
Copy link
Collaborator

kibana-ci commented Jan 15, 2024

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 11.4MB 11.4MB +6.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@lgestc lgestc left a comment

Choose a reason for hiding this comment

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

just one nit about magic value used

@@ -205,6 +205,10 @@ export const useDiscoverInTimelineActions = (
} else {
// If no saved search exists. Create a new saved search instance and associate it with the timeline.
try {
// Make sure we're not creating a saved search while a previous creation call is in progress
if (status !== 'idle') {
Copy link
Contributor

Choose a reason for hiding this comment

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

isnt there some kind of enum we could use here?

Copy link
Contributor

Choose a reason for hiding this comment

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

@lgestc status comes from @tanstack/query-core and is union of string literals:

export type MutationStatus = 'idle' | 'loading' | 'success' | 'error'

So the type is checked, just not as an enum :)

@janmonschke janmonschke self-assigned this Jan 16, 2024
@janmonschke janmonschke merged commit 1172c0e into elastic:main Jan 16, 2024
43 of 44 checks passed
@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.12 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 173308

Questions ?

Please refer to the Backport tool documentation

@janmonschke
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.12

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

janmonschke pushed a commit to janmonschke/kibana that referenced this pull request Jan 16, 2024
…173308)

Dependent on: elastic#173015

- fixes elastic#165663
- fixes elastic#165747

[Flaky Tests
(100/100)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4870)

---------

Co-authored-by: Jan Monschke <[email protected]>
(cherry picked from commit 1172c0e)

# Conflicts:
#	x-pack/test/security_solution_cypress/cypress/tasks/common.ts
janmonschke added a commit that referenced this pull request Jan 17, 2024
…173308) (#174914)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Investigations] - Unskip and refactor discover state tests
(#173308)](#173308)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Michael
Olorunnisola","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-01-16T12:18:26Z","message":"[Investigations]
- Unskip and refactor discover state tests (#173308)\n\nDependent on:
https://github.com/elastic/kibana/pull/173015\r\n\r\n- fixes
https://github.com/elastic/kibana/issues/165663\r\n- fixes
https://github.com/elastic/kibana/issues/165747\r\n\r\n[Flaky
Tests\r\n(100/100)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4870)\r\n\r\n---------\r\n\r\nCo-authored-by:
Jan Monschke
<[email protected]>","sha":"1172c0ec09eb72f478b7c0cb7afc6016fabdc400","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Threat
Hunting:Investigations","v8.12.1","v8.13.0"],"number":173308,"url":"https://github.com/elastic/kibana/pull/173308","mergeCommit":{"message":"[Investigations]
- Unskip and refactor discover state tests (#173308)\n\nDependent on:
https://github.com/elastic/kibana/pull/173015\r\n\r\n- fixes
https://github.com/elastic/kibana/issues/165663\r\n- fixes
https://github.com/elastic/kibana/issues/165747\r\n\r\n[Flaky
Tests\r\n(100/100)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4870)\r\n\r\n---------\r\n\r\nCo-authored-by:
Jan Monschke
<[email protected]>","sha":"1172c0ec09eb72f478b7c0cb7afc6016fabdc400"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/173308","number":173308,"mergeCommit":{"message":"[Investigations]
- Unskip and refactor discover state tests (#173308)\n\nDependent on:
https://github.com/elastic/kibana/pull/173015\r\n\r\n- fixes
https://github.com/elastic/kibana/issues/165663\r\n- fixes
https://github.com/elastic/kibana/issues/165747\r\n\r\n[Flaky
Tests\r\n(100/100)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4870)\r\n\r\n---------\r\n\r\nCo-authored-by:
Jan Monschke
<[email protected]>","sha":"1172c0ec09eb72f478b7c0cb7afc6016fabdc400"}}]}]
BACKPORT-->

---------

Co-authored-by: Michael Olorunnisola <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment