[8.12] [Investigations] - Unskip and refactor discover state tests (#173308) (#174914)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Investigations] - Unskip and refactor discover state tests
(#173308)](https://github.com/elastic/kibana/pull/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":"michael.olorunnisola@elastic.co"},"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
<jan.monschke@elastic.co>","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
<jan.monschke@elastic.co>","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
<jan.monschke@elastic.co>","sha":"1172c0ec09eb72f478b7c0cb7afc6016fabdc400"}}]}]
BACKPORT-->

---------

Co-authored-by: Michael Olorunnisola <michael.olorunnisola@elastic.co>
This commit is contained in:
Jan Monschke 2024-01-17 13:10:13 +01:00 committed by GitHub
parent f8ce81c4ea
commit 818b9bbc35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 97 additions and 113 deletions

View file

@ -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') {
return;
}
dispatch(
timelineActions.startTimelineSaving({
id: TimelineId.active,
@ -218,7 +222,7 @@ export const useDiscoverInTimelineActions = (
const responseIsEmpty = !response || !response?.id;
if (responseIsEmpty) {
throw new Error('Response is empty');
} else if (!savedSearchId && !responseIsEmpty && status !== 'loading') {
} else if (!savedSearchId && !responseIsEmpty) {
dispatch(
timelineActions.updateSavedSearchId({
id: TimelineId.active,

View file

@ -6,9 +6,11 @@
*/
import { visitWithTimeRange } from '../../../../tasks/navigation';
import { TIMELINE_TITLE } from '../../../../screens/timeline';
import { BASIC_TABLE_LOADING } from '../../../../screens/common';
import { goToSavedObjectSettings } from '../../../../tasks/stack_management';
import {
clickSavedObjectTagsFilter,
goToSavedObjectSettings,
} from '../../../../tasks/stack_management';
import {
navigateFromKibanaCollapsibleTo,
openKibanaNavigation,
@ -31,9 +33,9 @@ import {
import { updateDateRangeInLocalDatePickers } from '../../../../tasks/date_picker';
import { login } from '../../../../tasks/login';
import {
addDescriptionToTimeline,
addNameToTimelineAndSave,
createNewTimeline,
createTimelineOptionsPopoverBottomBar,
goToEsqlTab,
openTimelineById,
openTimelineFromSettings,
@ -43,15 +45,10 @@ import { STACK_MANAGEMENT_PAGE } from '../../../../screens/kibana_navigation';
import {
GET_SAVED_OBJECTS_TAGS_OPTION,
SAVED_OBJECTS_ROW_TITLES,
SAVED_OBJECTS_TAGS_FILTER,
} from '../../../../screens/common/stack_management';
const INITIAL_START_DATE = 'Jan 18, 2021 @ 20:33:29.186';
const INITIAL_END_DATE = 'Jan 19, 2024 @ 20:33:29.186';
const SAVED_SEARCH_UPDATE_REQ = 'SAVED_SEARCH_UPDATE_REQ';
const SAVED_SEARCH_UPDATE_WITH_DESCRIPTION = 'SAVED_SEARCH_UPDATE_WITH_DESCRIPTION';
const SAVED_SEARCH_CREATE_REQ = 'SAVED_SEARCH_CREATE_REQ';
const SAVED_SEARCH_GET_REQ = 'SAVED_SEARCH_GET_REQ';
const TIMELINE_REQ_WITH_SAVED_SEARCH = 'TIMELINE_REQ_WITH_SAVED_SEARCH';
const TIMELINE_PATCH_REQ = 'TIMELINE_PATCH_REQ';
@ -59,59 +56,37 @@ const TIMELINE_RESPONSE_SAVED_OBJECT_ID_PATH =
'response.body.data.persistTimeline.timeline.savedObjectId';
const esqlQuery = 'from auditbeat-* | where ecs.version == "8.0.0"';
// FLAKY: https://github.com/elastic/kibana/issues/168745
describe.skip(
const handleIntercepts = () => {
cy.intercept('PATCH', '/api/timeline', (req) => {
if (req.body.hasOwnProperty('timeline') && req.body.timeline.savedSearchId === null) {
req.alias = TIMELINE_PATCH_REQ;
}
});
cy.intercept('PATCH', '/api/timeline', (req) => {
if (req.body.hasOwnProperty('timeline') && req.body.timeline.savedSearchId !== null) {
req.alias = TIMELINE_REQ_WITH_SAVED_SEARCH;
}
});
};
describe(
'Discover Timeline State Integration',
{
tags: ['@ess', '@brokenInServerless'],
// ESQL and test involving STACK_MANAGEMENT_PAGE are broken in serverless
},
() => {
beforeEach(() => {
cy.intercept('PATCH', '/api/timeline', (req) => {
if (req.body.hasOwnProperty('timeline') && req.body.timeline.savedSearchId === null) {
req.alias = TIMELINE_PATCH_REQ;
}
});
cy.intercept('PATCH', '/api/timeline', (req) => {
if (req.body.hasOwnProperty('timeline') && req.body.timeline.savedSearchId !== null) {
req.alias = TIMELINE_REQ_WITH_SAVED_SEARCH;
}
});
cy.intercept('POST', '/api/content_management/rpc/get', (req) => {
if (req.body.hasOwnProperty('contentTypeId') && req.body.contentTypeId === 'search') {
req.alias = SAVED_SEARCH_GET_REQ;
}
});
cy.intercept('POST', '/api/content_management/rpc/create', (req) => {
if (req.body.hasOwnProperty('contentTypeId') && req.body.contentTypeId === 'search') {
req.alias = SAVED_SEARCH_CREATE_REQ;
}
});
cy.intercept('POST', '/api/content_management/rpc/update', (req) => {
if (req.body.hasOwnProperty('contentTypeId') && req.body.contentTypeId === 'search') {
req.alias = SAVED_SEARCH_UPDATE_REQ;
}
});
cy.intercept('POST', '/api/content_management/rpc/update', (req) => {
if (
req.body.hasOwnProperty('data') &&
req.body.data.hasOwnProperty('description') &&
req.body.data.description.length > 0
) {
req.alias = SAVED_SEARCH_UPDATE_WITH_DESCRIPTION;
}
});
login();
visitWithTimeRange(ALERTS_URL);
createNewTimeline();
createTimelineOptionsPopoverBottomBar();
goToEsqlTab();
updateDateRangeInLocalDatePickers(DISCOVER_CONTAINER, INITIAL_START_DATE, INITIAL_END_DATE);
handleIntercepts();
});
context('save/restore', () => {
it('should be able create an empty timeline with default discover state', () => {
describe('ESQL tab state', () => {
it('should be able create an empty timeline with default esql tab state', () => {
addNameToTimelineAndSave('Timerange timeline');
createNewTimeline();
goToEsqlTab();
@ -120,7 +95,7 @@ describe.skip(
`Last 15 minutes`
);
});
it('should save/restore discover dataview/timerange/filter/query/columns when saving/resoring timeline', () => {
it('should save/restore esql tab dataview/timerange/filter/query/columns when saving/resoring timeline', () => {
const timelineSuffix = Date.now();
const timelineName = `DataView timeline-${timelineSuffix}`;
const column1 = 'event.category';
@ -151,7 +126,7 @@ describe.skip(
);
});
});
it('should save/restore discover dataview/timerange/filter/query/columns when timeline is opened via url', () => {
it('should save/restore esql tab dataview/timerange/filter/query/columns when timeline is opened via url', () => {
const timelineSuffix = Date.now();
const timelineName = `DataView timeline-${timelineSuffix}`;
const column1 = 'event.category';
@ -177,7 +152,7 @@ describe.skip(
);
});
});
it('should save/restore discover ES|QL when saving timeline', () => {
it('should save/restore esql tab ES|QL when saving timeline', () => {
const timelineSuffix = Date.now();
const timelineName = `ES|QL timeline-${timelineSuffix}`;
addNameToTimelineAndSave(timelineName);
@ -196,62 +171,53 @@ describe.skip(
});
});
});
/*
* skipping because it is @brokenInServerless and this cypress tag was somehow not working
* so skipping this test both in ess and serverless.
*
* Raised issue: https://github.com/elastic/kibana/issues/165913
*
* */
context.skip('saved search tags', () => {
it('should save discover saved search with `Security Solution` tag', () => {
describe('Discover saved search state for ESQL tab', () => {
it('should save esql tab saved search with `Security Solution` tag', () => {
const timelineSuffix = Date.now();
const timelineName = `SavedObject timeline-${timelineSuffix}`;
addDiscoverEsqlQuery(esqlQuery);
addNameToTimelineAndSave(timelineName);
cy.wait(`@${TIMELINE_REQ_WITH_SAVED_SEARCH}`);
cy.get(LOADING_INDICATOR).should('not.exist');
openKibanaNavigation();
navigateFromKibanaCollapsibleTo(STACK_MANAGEMENT_PAGE);
cy.get(LOADING_INDICATOR).should('not.exist');
goToSavedObjectSettings();
cy.get(LOADING_INDICATOR).should('not.exist');
clickSavedObjectTagsFilter();
cy.get(GET_SAVED_OBJECTS_TAGS_OPTION('Security_Solution')).trigger('click');
cy.get(BASIC_TABLE_LOADING).should('not.exist');
cy.get(SAVED_OBJECTS_ROW_TITLES).should(
'contain.text',
`Saved search for timeline - ${timelineName}`
);
});
it('should rename the saved search on timeline rename', () => {
const initialTimelineSuffix = Date.now();
const initialTimelineName = `Timeline-${initialTimelineSuffix}`;
addDiscoverEsqlQuery(esqlQuery);
addNameToTimelineAndSave(initialTimelineName);
cy.get(LOADING_INDICATOR).should('not.exist');
const timelineSuffix = Date.now();
const renamedTimelineName = `Rename timeline-${timelineSuffix}`;
addNameToTimelineAndSave(renamedTimelineName);
cy.wait(`@${TIMELINE_REQ_WITH_SAVED_SEARCH}`);
openKibanaNavigation();
navigateFromKibanaCollapsibleTo(STACK_MANAGEMENT_PAGE);
cy.get(LOADING_INDICATOR).should('not.exist');
goToSavedObjectSettings();
cy.get(LOADING_INDICATOR).should('not.exist');
cy.get(SAVED_OBJECTS_TAGS_FILTER).trigger('click');
clickSavedObjectTagsFilter();
cy.get(GET_SAVED_OBJECTS_TAGS_OPTION('Security_Solution')).trigger('click');
cy.get(BASIC_TABLE_LOADING).should('not.exist');
cy.get(SAVED_OBJECTS_ROW_TITLES).should(
'contain.text',
`Saved Search for timeline - ${timelineName}`
`Saved search for timeline - ${renamedTimelineName}`
);
});
});
context('saved search', () => {
it('should rename the saved search on timeline rename', () => {
const timelineSuffix = Date.now();
const timelineName = `Rename timeline-${timelineSuffix}`;
addDiscoverEsqlQuery(esqlQuery);
addNameToTimelineAndSave(timelineName);
cy.wait(`@${TIMELINE_PATCH_REQ}`)
.its(TIMELINE_RESPONSE_SAVED_OBJECT_ID_PATH)
.then((timelineId) => {
cy.wait(`@${SAVED_SEARCH_UPDATE_REQ}`);
cy.wait(`@${TIMELINE_REQ_WITH_SAVED_SEARCH}`);
// create an empty timeline
createNewTimeline();
// switch to old timeline
openTimelineFromSettings();
openTimelineById(timelineId);
cy.get(TIMELINE_TITLE).should('have.text', timelineName);
const timelineDesc = 'Timeline Description with Saved Seach';
addDescriptionToTimeline(timelineDesc);
cy.wait(`@${SAVED_SEARCH_UPDATE_WITH_DESCRIPTION}`, {
timeout: 30000,
}).then((interception) => {
expect(interception.request.body.data.description).eq(timelineDesc);
});
});
});
});
// Issue for enabling below tests: https://github.com/elastic/kibana/issues/165913
context.skip('Advanced Settings', () => {

View file

@ -5,6 +5,7 @@
* 2.0.
*/
import { recurse } from 'cypress-recurse';
import { KIBANA_LOADING_ICON } from '../screens/security_header';
import { EUI_BASIC_TABLE_LOADING } from '../screens/common/controls';
@ -81,3 +82,13 @@ export const waitForTableToLoad = () => {
cy.get(EUI_BASIC_TABLE_LOADING).should('exist');
cy.get(EUI_BASIC_TABLE_LOADING).should('not.exist');
};
export const waitForTabToBeLoaded = (tabId: string) => {
recurse(
() => cy.get(tabId).click(),
($el) => expect($el).to.have.class('euiTab-isSelected'),
{
delay: 500,
}
);
};

View file

@ -60,7 +60,7 @@ export const addDiscoverEsqlQuery = (esqlQuery: string) => {
selectCurrentDiscoverEsqlQuery(DISCOVER_ESQL_EDITABLE_INPUT);
cy.get(DISCOVER_ESQL_EDITABLE_INPUT).type(`${esqlQuery}`);
cy.get(DISCOVER_ESQL_EDITABLE_INPUT).blur();
cy.get(GET_LOCAL_SEARCH_BAR_SUBMIT_BUTTON(DISCOVER_CONTAINER)).realClick();
cy.get(GET_LOCAL_SEARCH_BAR_SUBMIT_BUTTON(DISCOVER_CONTAINER)).click();
};
export const convertNBSPToSP = (str: string) => {

View file

@ -5,10 +5,15 @@
* 2.0.
*/
import { SAVED_OBJECTS_SETTINGS } from '../screens/common/stack_management';
import {
SAVED_OBJECTS_SETTINGS,
SAVED_OBJECTS_TAGS_FILTER,
} from '../screens/common/stack_management';
export const goToSavedObjectSettings = () => {
cy.get(SAVED_OBJECTS_SETTINGS).scrollIntoView();
cy.get(SAVED_OBJECTS_SETTINGS).should('be.visible').focus();
cy.get(SAVED_OBJECTS_SETTINGS).should('be.visible').click();
cy.get(SAVED_OBJECTS_SETTINGS).click();
};
export const clickSavedObjectTagsFilter = () => {
cy.get(SAVED_OBJECTS_TAGS_FILTER).trigger('click');
};

View file

@ -307,7 +307,7 @@ export const attachTimelineToExistingCase = () => {
const clickIdHoverActionOverflowButton = () => {
cy.get(ID_HOVER_ACTION_OVERFLOW_BTN).should('exist');
cy.get(ID_HOVER_ACTION_OVERFLOW_BTN).click({ force: true });
cy.get(ID_HOVER_ACTION_OVERFLOW_BTN).click();
};
export const clickIdToggleField = () => {
@ -339,31 +339,31 @@ export const createNewTimeline = () => {
};
export const openCreateTimelineOptionsPopover = () => {
cy.get(NEW_TIMELINE_ACTION).filter(':visible').should('be.visible').click();
cy.get(NEW_TIMELINE_ACTION).filter(':visible').click();
};
export const createTimelineOptionsPopoverBottomBar = () => {
recurse(
() => {
cy.get(TIMELINE_SETTINGS_ICON).filter(':visible').should('be.visible').click();
cy.get(TIMELINE_SETTINGS_ICON).filter(':visible').click();
return cy.get(CREATE_NEW_TIMELINE).eq(0);
},
(sub) => sub.is(':visible')
);
cy.get(CREATE_NEW_TIMELINE).eq(0).should('be.visible').click();
cy.get(CREATE_NEW_TIMELINE).eq(0).click();
};
export const createTimelineTemplateOptionsPopoverBottomBar = () => {
recurse(
() => {
cy.get(TIMELINE_SETTINGS_ICON).filter(':visible').should('be.visible').click();
cy.get(TIMELINE_SETTINGS_ICON).filter(':visible').click();
return cy.get(CREATE_NEW_TIMELINE_TEMPLATE).eq(0);
},
(sub) => sub.is(':visible')
);
cy.get(CREATE_NEW_TIMELINE_TEMPLATE).eq(0).should('be.visible').click();
cy.get(CREATE_NEW_TIMELINE_TEMPLATE).eq(0).click();
};
export const closeCreateTimelineOptionsPopover = () => {
@ -385,7 +385,7 @@ export const executeTimelineSearch = (query: string) => {
};
export const expandFirstTimelineEventDetails = () => {
cy.get(TOGGLE_TIMELINE_EXPAND_EVENT).first().click({ force: true });
cy.get(TOGGLE_TIMELINE_EXPAND_EVENT).first().click();
};
/**
@ -425,7 +425,7 @@ export const openTimelineFieldsBrowser = () => {
export const openTimelineInspectButton = () => {
cy.get(TIMELINE_INSPECT_BUTTON).should('not.be.disabled');
cy.get(TIMELINE_INSPECT_BUTTON).click({ force: true });
cy.get(TIMELINE_INSPECT_BUTTON).click();
};
export const openTimelineFromSettings = () => {
@ -473,7 +473,7 @@ export const populateTimeline = () => {
const clickTimestampHoverActionOverflowButton = () => {
cy.get(TIMESTAMP_HOVER_ACTION_OVERFLOW_BTN).should('exist');
cy.get(TIMESTAMP_HOVER_ACTION_OVERFLOW_BTN).click({ force: true });
cy.get(TIMESTAMP_HOVER_ACTION_OVERFLOW_BTN).click();
};
export const clickTimestampToggleField = () => {
@ -481,7 +481,7 @@ export const clickTimestampToggleField = () => {
cy.get(TIMESTAMP_TOGGLE_FIELD).should('exist');
cy.get(TIMESTAMP_TOGGLE_FIELD).click({ force: true });
cy.get(TIMESTAMP_TOGGLE_FIELD).click();
};
export const removeColumn = (columnName: string) => {
@ -492,7 +492,7 @@ export const removeColumn = (columnName: string) => {
};
export const resetFields = () => {
cy.get(RESET_FIELDS).click({ force: true });
cy.get(RESET_FIELDS).click();
};
export const selectCase = (caseId: string) => {

View file

@ -28,17 +28,15 @@ export const expandNotes = () => {
export const importTimeline = (timeline: string) => {
cy.get(IMPORT_TIMELINE_BTN).click();
cy.get(INPUT_FILE).click({ force: true });
cy.get(INPUT_FILE).click();
cy.get(INPUT_FILE).attachFile(timeline);
cy.get(INPUT_FILE).trigger('change');
cy.get(IMPORT_BTN).last().click({ force: true });
cy.get(IMPORT_BTN).last().click();
cy.get(INPUT_FILE).should('not.exist');
};
export const openTimeline = (id?: string) => {
cy.get(id ? TIMELINE(id) : TIMELINE_NAME)
.should('be.visible')
.click();
cy.get(id ? TIMELINE(id) : TIMELINE_NAME).click();
};
export const waitForTimelinesPanelToBeLoaded = () => {