Skip to content

Commit

Permalink
[Entity Analytics] Flaky Cypress test fixes (elastic#186081)
Browse files Browse the repository at this point in the history
### Fix 1: Press refresh button after using date picker on dashboard

Closes elastic#183662
Closes elastic#183635
Closes elastic#183982

We shouldnt have to do this, but there is some condition where clicking
apply gets the UI in a stuck state and I cant figure it out.

### Fix 2: Use more specific selector for search bar on risk score
preview page

Closes elastic#184133

We were using a generic selector `[data-test-subj="unifiedQueryInput"]
textarea` which was bringing back two elements sometimes (no idea why),
I have given the box its own dedicated selector to hopefully prevent
this from happening

---------

Co-authored-by: Kibana Machine <[email protected]>
(cherry picked from commit c34bb46)
  • Loading branch information
hop-dev committed Jul 3, 2024
1 parent c47097b commit aae98fb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ const RiskEnginePreview = () => {
showDatePicker={true}
displayStyle={'inPage'}
submitButtonStyle={'iconOnly'}
dataTestSubj="risk-score-preview-search-bar-input"
/>
)}
</EuiFormRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>

describe('With host risk data', () => {
before(() => {
cy.task('esArchiverUnload', { archiveName: 'risk_scores_new' });
cy.task('esArchiverLoad', { archiveName: 'risk_scores_new' });
});

Expand Down Expand Up @@ -145,6 +146,7 @@ describe('Entity Analytics Dashboard', { tags: ['@ess', '@serverless'] }, () =>

describe('With alerts data', () => {
before(() => {
deleteAlertsAndRules();
createRule(getNewRule());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
LOCAL_QUERY_BAR_SELECTOR,
RISK_SCORE_ERROR_PANEL,
RISK_SCORE_STATUS,
LOCAL_QUERY_BAR_SEARCH_INPUT_SELECTOR,
} from '../../screens/entity_analytics_management';

import { deleteRiskScore, installRiskScoreModule } from '../../tasks/api_calls/risk_scores';
Expand All @@ -31,7 +32,7 @@ import {
interceptRiskInitError,
} from '../../tasks/api_calls/risk_engine';
import { updateDateRangeInLocalDatePickers } from '../../tasks/date_picker';
import { fillLocalSearchBar, submitLocalSearch } from '../../tasks/search_bar';
import { submitLocalSearch } from '../../tasks/search_bar';
import {
riskEngineStatusChange,
upgradeRiskEngine,
Expand Down Expand Up @@ -80,8 +81,7 @@ describe(
it('risk scores reacts on change in search bar query', () => {
cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5);
cy.get(USER_RISK_PREVIEW_TABLE_ROWS).should('have.length', 5);

fillLocalSearchBar('host.name: "test-host1"');
cy.get(LOCAL_QUERY_BAR_SEARCH_INPUT_SELECTOR).type('host.name: "test-host1"');
submitLocalSearch(LOCAL_QUERY_BAR_SELECTOR);

cy.get(HOST_RISK_PREVIEW_TABLE_ROWS).should('have.length', 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const RISK_PREVIEW_ERROR_BUTTON = '[data-test-subj="risk-preview-error-bu

export const LOCAL_QUERY_BAR_SELECTOR = getDataTestSubjectSelector('risk-score-preview-search-bar');

export const LOCAL_QUERY_BAR_SEARCH_INPUT_SELECTOR =
'[data-test-subj="risk-score-preview-search-bar-input"]';

export const RISK_SCORE_ERROR_PANEL = '[data-test-subj="risk-score-error-panel"]';

export const RISK_SCORE_UPDATE_CANCEL = '[data-test-subj="risk-score-update-cancel"]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import {
} from '../screens/entity_analytics_management';
import { visitWithTimeRange } from './navigation';
import { GET_DATE_PICKER_APPLY_BUTTON, GLOBAL_FILTERS_CONTAINER } from '../screens/date_picker';
import { LOADING_SPINNER } from '../screens/loading';
import { REFRESH_BUTTON } from '../screens/security_header';

export const updateDashboardTimeRange = () => {
// eslint-disable-next-line cypress/no-force
cy.get(GET_DATE_PICKER_APPLY_BUTTON(GLOBAL_FILTERS_CONTAINER)).click({ force: true }); // Force to fix global timerange flakiness
cy.get(LOADING_SPINNER).should('exist');
cy.get(LOADING_SPINNER).should('not.exist');
cy.get(REFRESH_BUTTON).click();
cy.get(REFRESH_BUTTON).should('not.have.attr', 'aria-label', 'Needs updating');
};

export const waitForAnomaliesToBeLoaded = () => {
Expand Down

0 comments on commit aae98fb

Please sign in to comment.