Skip to content

Commit

Permalink
Refactor (#113699)
Browse files Browse the repository at this point in the history
* refactors timeline test

* tries to remove flakiness on indicator match test

* fixes issues

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
MadameSheema and kibanamachine authored Oct 5, 2021
1 parent 00bb597 commit 723370a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ import { TIMELINES_URL } from '../../urls/navigation';
describe('Timeline Templates', () => {
beforeEach(() => {
cleanKibana();
loginAndWaitForPageWithoutDateRange(TIMELINES_URL);

cy.intercept('PATCH', '/api/timeline').as('timeline');
});

it('Creates a timeline template', async () => {
loginAndWaitForPageWithoutDateRange(TIMELINES_URL);
openTimelineUsingToggle();
createNewTimelineTemplate();
populateTimeline();
Expand Down Expand Up @@ -103,20 +102,15 @@ describe('Timeline Templates', () => {
});

it('Create template from timeline', () => {
createTimeline(getTimeline());
loginAndWaitForPageWithoutDateRange(TIMELINES_URL);
waitForTimelinesPanelToBeLoaded();
expandEventAction();
clickingOnCreateTemplateFromTimelineBtn();

createTimeline(getTimeline()).then(() => {
expandEventAction();
clickingOnCreateTemplateFromTimelineBtn();
cy.wait('@timeline', { timeout: 100000 }).then(({ request }) => {
expect(request.body.timeline).to.haveOwnProperty('templateTimelineId');
expect(request.body.timeline).to.haveOwnProperty('description', getTimeline().description);
expect(request.body.timeline.kqlQuery.filterQuery.kuery).to.haveOwnProperty(
'expression',
getTimeline().query
);
cy.get(TIMELINE_FLYOUT_WRAPPER).should('have.css', 'visibility', 'visible');
});
});
cy.wait('@timeline', { timeout: 100000 });
cy.get(TIMELINE_FLYOUT_WRAPPER).should('have.css', 'visibility', 'visible');
cy.get(TIMELINE_DESCRIPTION).should('have.text', getTimeline().description);
cy.get(TIMELINE_QUERY).should('have.text', getTimeline().query);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
import { createTimelineTemplate } from '../../tasks/api_calls/timelines';

import { cleanKibana } from '../../tasks/common';

import { loginAndWaitForPage, loginAndWaitForPageWithoutDateRange } from '../../tasks/login';
import { openTimelineUsingToggle } from '../../tasks/security_main';
import { selectCustomTemplates } from '../../tasks/templates';
import {
addEqlToTimeline,
addFilter,
Expand Down Expand Up @@ -115,22 +115,22 @@ describe('Timelines', (): void => {

describe('Create a timeline from a template', () => {
before(() => {
cy.intercept('/api/timeline*').as('timeline');
cleanKibana();
createTimelineTemplate(getTimeline());
loginAndWaitForPageWithoutDateRange(TIMELINE_TEMPLATES_URL);
waitForTimelinesPanelToBeLoaded();
});

it('Should have the same query and open the timeline modal', () => {
createTimelineTemplate(getTimeline()).then(() => {
expandEventAction();
cy.intercept('/api/timeline').as('timeline');

clickingOnCreateTimelineFormTemplateBtn();
cy.wait('@timeline', { timeout: 100000 });

cy.get(TIMELINE_FLYOUT_WRAPPER).should('have.css', 'visibility', 'visible');
cy.get(TIMELINE_DESCRIPTION).should('have.text', getTimeline().description);
cy.get(TIMELINE_QUERY).should('have.text', getTimeline().query);
});
selectCustomTemplates();
cy.wait('@timeline', { timeout: 100000 });
expandEventAction();
clickingOnCreateTimelineFormTemplateBtn();
cy.wait('@timeline', { timeout: 100000 });

cy.get(TIMELINE_FLYOUT_WRAPPER).should('have.css', 'visibility', 'visible');
cy.get(TIMELINE_DESCRIPTION).should('have.text', getTimeline().description);
cy.get(TIMELINE_QUERY).should('have.text', getTimeline().query);
});
});
8 changes: 8 additions & 0 deletions x-pack/plugins/security_solution/cypress/screens/templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const CUSTOM_TEMPLATES = '[data-test-subj="Custom templates"]';
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@ export const duplicateFirstRule = () => {
* flake.
*/
export const duplicateRuleFromMenu = () => {
const click = ($el: Cypress.ObjectLike) => cy.wrap($el).click({ force: true });
cy.get(LOADING_INDICATOR).should('not.exist');
cy.root()
.pipe(($el) => {
$el.find(ALL_ACTIONS).trigger('click');
return $el.find(DUPLICATE_RULE_MENU_PANEL_BTN);
})
.should(($el) => expect($el).to.be.visible);
cy.get(ALL_ACTIONS).pipe(click);
cy.get(DUPLICATE_RULE_MENU_PANEL_BTN).should('be.visible');

// Because of a fade effect and fast clicking this can produce more than one click
cy.get(DUPLICATE_RULE_MENU_PANEL_BTN).pipe(($el) => $el.trigger('click'));
cy.get(DUPLICATE_RULE_MENU_PANEL_BTN).pipe(click);
};

/**
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { CUSTOM_TEMPLATES } from '../screens/templates';

export const selectCustomTemplates = () => {
cy.get(CUSTOM_TEMPLATES).click({ force: true });
};
7 changes: 6 additions & 1 deletion x-pack/plugins/security_solution/cypress/tasks/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,10 @@ export const clickingOnCreateTemplateFromTimelineBtn = () => {
};

export const expandEventAction = () => {
cy.get(TIMELINE_COLLAPSED_ITEMS_BTN).first().click();
cy.waitUntil(() => {
cy.get(TIMELINE_COLLAPSED_ITEMS_BTN).should('exist');
cy.get(TIMELINE_COLLAPSED_ITEMS_BTN).should('be.visible');
return cy.get(TIMELINE_COLLAPSED_ITEMS_BTN).then(($el) => $el.length === 1);
});
cy.get(TIMELINE_COLLAPSED_ITEMS_BTN).click();
};
7 changes: 5 additions & 2 deletions x-pack/plugins/security_solution/cypress/tasks/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { LOADING_INDICATOR } from '../screens/security_header';
import {
TIMELINE_CHECKBOX,
BULK_ACTIONS,
Expand All @@ -24,6 +25,8 @@ export const openTimeline = (id: string) => {
cy.get(TIMELINE(id)).should('be.visible').pipe(click);
};

export const waitForTimelinesPanelToBeLoaded = (): Cypress.Chainable<JQuery<HTMLElement>> => {
return cy.get(TIMELINES_TABLE).should('exist');
export const waitForTimelinesPanelToBeLoaded = () => {
cy.get(LOADING_INDICATOR).should('exist');
cy.get(LOADING_INDICATOR).should('not.exist');
cy.get(TIMELINES_TABLE).should('exist');
};
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const SearchRow = React.memo<Props>(
? i18n.SEARCH_PLACEHOLDER
: i18n.SEARCH_TEMPLATE_PLACEHOLDER,
incremental: false,
'data-test-subj': 'search-bar',
}),
[timelineType]
);
Expand All @@ -70,7 +71,7 @@ export const SearchRow = React.memo<Props>(
<SearchRowContainer>
<SearchRowFlexGroup gutterSize="s">
<EuiFlexItem>
<EuiSearchBar data-test-subj="search-bar" box={searchBox} onChange={onQueryChange} />
<EuiSearchBar box={searchBox} onChange={onQueryChange} />
</EuiFlexItem>

<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const useTimelineStatus = ({
onClick={onFilterClicked.bind(null, tab.id)}
withNext={tab.withNext}
isDisabled={tab.disabled}
data-test-subj={tab.name}
>
{tab.name}
</EuiFilterButton>
Expand Down

0 comments on commit 723370a

Please sign in to comment.