Skip to content

Commit

Permalink
fix ES|QL cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliidm committed May 17, 2024
1 parent 9125e5a commit f981ec6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { RULES_MANAGEMENT_URL } from '../../../../urls/rules_management';
import { getDetails } from '../../../../tasks/rule_details';
import { deleteAlertsAndRules } from '../../../../tasks/api_calls/common';
import {
clearEsqlQueryBar,
expandEsqlQueryBar,
fillEsqlQueryBar,
fillOverrideEsqlRuleName,
Expand Down Expand Up @@ -82,7 +81,6 @@ describe(
// ensure once edit form opened, correct query is displayed in ES|QL input
cy.get(ESQL_QUERY_BAR).contains(rule.query);

clearEsqlQueryBar();
fillEsqlQueryBar(expectedValidEsqlQuery);

saveEditedRule();
Expand All @@ -92,7 +90,6 @@ describe(
});

it('edits ES|QL rule query and override rule name with new property', () => {
clearEsqlQueryBar();
fillEsqlQueryBar(expectedValidEsqlQuery);

goToAboutStepTab();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,16 +613,23 @@ export const fillDefineNewTermsRuleAndContinue = (rule: NewTermsRuleCreateProps)
cy.get(DEFINE_CONTINUE_BUTTON).should('exist').click({ force: true });
};

export const fillEsqlQueryBar = (query: string) => {
const typeEsqlQueryBar = (query: string) => {
// eslint-disable-next-line cypress/no-force
cy.get(ESQL_QUERY_BAR_INPUT_AREA).should('not.be.disabled').type(query, { force: true });
};

export const clearEsqlQueryBar = () => {
// monaco editor under the hood is quite complex in matter to clear it
// underlying textarea holds just the last character of query displayed in search bar
// in order to clear it - it requires to select all text within editor and type in it
fillEsqlQueryBar(Cypress.platform === 'darwin' ? '{cmd}a' : '{ctrl}a');
/**
* clears ES|QL search bar first
* types new query
*/
export const fillEsqlQueryBar = (query: string) => {
// before typing anything in query bar, we need to clear it
// Since first click on ES|QL query bar trigger re-render. We need to clear search bar during second attempt
typeEsqlQueryBar(' ');
typeEsqlQueryBar(Cypress.platform === 'darwin' ? '{cmd}a{del}' : '{ctrl}a{del}');

// only after this query can be safely typed
typeEsqlQueryBar(query);
};

/**
Expand Down

0 comments on commit f981ec6

Please sign in to comment.