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

[SecuritySolution] Fix issue with duplicate timeline reloading #198652

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('dispatchUpdateTimeline', () => {
...mockTimelineModel,
version: null,
updated: undefined,
changed: undefined,
changed: true,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export const useUpdateTimeline = () => {
}: UpdateTimeline) => {
let _timeline = timeline;
if (duplicate) {
_timeline = { ...timeline, updated: undefined, changed: undefined, version: null };
// Reset the `updated` and `version` fields because a duplicated timeline has not been saved yet.
// The `changed` field is set to true because the duplicated timeline needs to be saved.
_timeline = { ...timeline, updated: undefined, changed: true, version: null };
}
if (!isEmpty(_timeline.indexNames)) {
dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
openKibanaNavigation,
} from '../../../tasks/kibana_navigation';
import { login } from '../../../tasks/login';
import { visitWithTimeRange } from '../../../tasks/navigation';
import { visit, visitWithTimeRange } from '../../../tasks/navigation';
import {
closeTimelineUsingCloseButton,
openTimelineUsingToggle,
Expand All @@ -32,13 +32,14 @@ import {
} from '../../../tasks/serverless/navigation';
import {
addNameToTimelineAndSave,
closeTimeline,
createNewTimeline,
duplicateFirstTimeline,
populateTimeline,
} from '../../../tasks/timeline';
import { EXPLORE_URL, hostsUrl, MANAGE_URL } from '../../../urls/navigation';
import { EXPLORE_URL, hostsUrl, MANAGE_URL, TIMELINES_URL } from '../../../urls/navigation';

// FLAKY: https://github.com/elastic/kibana/issues/174068
describe.skip('[ESS] Save Timeline Prompts', { tags: ['@ess'] }, () => {
describe('[ESS] Save Timeline Prompts', { tags: ['@ess'] }, () => {
beforeEach(() => {
login();
visitWithTimeRange(hostsUrl('allHosts'));
Expand Down Expand Up @@ -119,6 +120,17 @@ describe.skip('[ESS] Save Timeline Prompts', { tags: ['@ess'] }, () => {
cy.get(TIMELINE_SAVE_MODAL).should('not.exist');
cy.url().should('not.contain', MANAGE_URL);
});

it('should prompt when a timeline is duplicated but not saved', () => {
addNameToTimelineAndSave('Original');
closeTimeline();
visit(TIMELINES_URL);
duplicateFirstTimeline();
closeTimeline();
openKibanaNavigation();
navigateFromKibanaCollapsibleTo(MANAGE_PAGE);
cy.get(APP_LEAVE_CONFIRM_MODAL).should('be.visible');
});
});

// In serverless it is not possible to use the navigation menu without closing the timeline
Expand Down Expand Up @@ -201,4 +213,14 @@ describe('[serverless] Save Timeline Prompts', { tags: ['@serverless'] }, () =>
navigateToExploreUsingBreadcrumb(); // explore has timelines disabled
cy.get(APP_LEAVE_CONFIRM_MODAL).should('not.exist');
});

it('should prompt when a timeline is duplicated but not saved', () => {
addNameToTimelineAndSave('Original');
closeTimeline();
visit(TIMELINES_URL);
duplicateFirstTimeline();
closeTimeline();
navigateToExplorePageInServerless(); // security page with timelines disabled
cy.get(APP_LEAVE_CONFIRM_MODAL).should('be.visible');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const TIMELINES_PINNED_EVENT_COUNT = '[data-test-subj="pinned-event-count

export const TIMELINES_TABLE = '[data-test-subj="timelines-table"]';

export const DUPLICATE_TIMELINE = '[data-test-subj="open-duplicate"]';

export const TIMELINES_USERNAME = '[data-test-subj="username"]';

export const REFRESH_BUTTON = '[data-test-subj="refreshButton-linkIcon"]';
Expand Down
19 changes: 17 additions & 2 deletions x-pack/test/security_solution_cypress/cypress/tasks/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,22 @@ import {
QUERY_EVENT_COUNT,
TIMELINE_ENABLE_DISABLE_ALL_ROW_RENDERER,
TIMELINE_DISCOVER_FIELDS_BUTTON,
TIMELINE_TITLE,
} from '../screens/timeline';

import { REFRESH_BUTTON, TIMELINE, TIMELINES_TAB_TEMPLATE } from '../screens/timelines';
import {
DUPLICATE_TIMELINE,
REFRESH_BUTTON,
TIMELINE,
TIMELINES_TABLE,
TIMELINES_TAB_TEMPLATE,
} from '../screens/timelines';
import { waitForTabToBeLoaded } from './common';

import { closeFieldsBrowser, filterFieldsBrowser } from './fields_browser';
import { TIMELINE_CONTEXT_MENU_BTN } from '../screens/alerts';
import { LOADING_INDICATOR } from '../screens/security_header';
import { TOASTER } from '../screens/alerts_detection_rules';
import { COLLAPSED_ACTION_BTN, TOASTER } from '../screens/alerts_detection_rules';
import { RUNTIME_FIELD_INPUT, SAVE_FIELD_BUTTON } from '../screens/create_runtime_field';

const hostExistsQuery = 'host.name: *';
Expand Down Expand Up @@ -150,6 +157,14 @@ export const addNameAndDescriptionToTimeline = (
cy.get(TIMELINE_TITLE_INPUT).should('not.exist');
};

export const duplicateFirstTimeline = () => {
cy.get(TIMELINES_TABLE).within(() => {
cy.get(COLLAPSED_ACTION_BTN).first().click();
});
cy.get(DUPLICATE_TIMELINE).click();
cy.get(TIMELINE_TITLE).should('be.visible');
};

export const goToNotesTab = () => {
cy.get(NOTES_TAB_BUTTON).click();
cy.get(NOTES_TEXT_AREA).should('be.visible');
Expand Down