From 87162c7f71f29041173160eaa2da4321d1f56271 Mon Sep 17 00:00:00 2001 From: Shenoy Pratik Date: Wed, 10 Jan 2024 14:56:15 -0800 Subject: [PATCH] remove cypress delay and wait calls Signed-off-by: Shenoy Pratik --- gantt-chart/.cypress/integration/ui.spec.js | 78 +++++++-------------- gantt-chart/.cypress/utils/constants.js | 1 - 2 files changed, 24 insertions(+), 55 deletions(-) diff --git a/gantt-chart/.cypress/integration/ui.spec.js b/gantt-chart/.cypress/integration/ui.spec.js index f9b50fa..93e470c 100644 --- a/gantt-chart/.cypress/integration/ui.spec.js +++ b/gantt-chart/.cypress/integration/ui.spec.js @@ -7,7 +7,7 @@ import customParseFormat from 'dayjs/plugin/customParseFormat'; import dayjs from 'dayjs'; -import { delay, GANTT_VIS_NAME, Y_LABEL, X_LABEL, DEFAULT_SIZE } from '../utils/constants'; +import { GANTT_VIS_NAME, Y_LABEL, X_LABEL, DEFAULT_SIZE } from '../utils/constants'; dayjs.extend(customParseFormat); describe('Dump test data', () => { @@ -51,19 +51,13 @@ describe('Save a gantt chart', () => { it('Creates and saves a gantt chart', () => { cy.get('.euiButton__text').contains('Create ').click({ force: true }); - cy.wait(delay); cy.get('[data-test-subj="visTypeTitle"]').contains('Gantt Chart').click({ force: true }); - cy.wait(delay); cy.contains(/^jaeger$/).click({ force: true }); - cy.wait(delay); cy.contains('Save').click({ force: true }); - cy.wait(delay); cy.get('input[data-test-subj="savedObjectTitle"]').type(GANTT_VIS_NAME); - cy.wait(delay); cy.get('button[data-test-subj="confirmSaveSavedObjectButton"]').click({ force: true, }); - cy.wait(delay); cy.contains('Saved').should('exist'); }); @@ -80,31 +74,23 @@ describe('Render and configure a gantt chart', () => { }); it('Renders the chart', () => { - cy.get('button.euiSuperSelectControl').eq(0).click({ force: true }); - cy.wait(delay); + cy.get('button[data-test-subj="gantt-chart-editor-label-field"]').click(); cy.get('.euiContextMenuItem__text') .contains(/^spanID$/) - .click({ force: true }); - cy.wait(delay); - cy.get('button.euiSuperSelectControl').eq(1).click({ force: true }); - cy.wait(delay); + .click(); + cy.get('button[data-test-subj="gantt-chart-editor-start-time-field"]').click(); cy.get('.euiContextMenuItem__text') .contains(/^startTime$/) - .click({ force: true }); - cy.wait(delay); - cy.get('button.euiSuperSelectControl').eq(2).click({ force: true }); - cy.wait(delay); + .click(); + cy.get('button[data-test-subj="gantt-chart-editor-duration-field"]').click(); cy.get('.euiContextMenuItem__text') .contains(/^duration$/) - .click({ force: true }); - cy.wait(delay); + .click(); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(delay); cy.get('.traces').should('have.length', DEFAULT_SIZE); cy.get('.euiButton__text').contains('Save').click({ force: true }); - cy.wait(delay); cy.get('button[data-test-subj="confirmSaveSavedObjectButton"]').click({ force: true, }); @@ -120,90 +106,79 @@ describe('Configure panel settings', () => { it('Changes y-axis label', () => { cy.get('input.euiFieldText[placeholder="Label"]').eq(0).focus().type(Y_LABEL); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(delay); cy.get('text.ytitle').contains(Y_LABEL).should('exist'); cy.get('.euiSwitch__label').contains('Show Y-axis label').click({ force: true }); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(delay); cy.get('text.ytitle').should('not.exist'); }); it('Changes x-axis label', () => { cy.get('input.euiFieldText[placeholder="Label"]').eq(1).focus().type(X_LABEL); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(delay); cy.get('text.xtitle').contains(X_LABEL).should('exist'); cy.get('.euiSwitch__label').contains('Show X-axis label').click({ force: true }); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(delay); cy.get('text.xtitle').should('not.exist'); }); it('Changes time formats', () => { + cy.intercept({ method: 'POST', url: '**/api/gantt_vis/query' }).as('timeUpdateRequest'); + cy.get('select').eq(3).select('MM/DD hh:mm:ss A'); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(1000); + cy.wait('@timeUpdateRequest'); cy.get('.xtick') .eq(0) .invoke('text') - .then((text) => { - expect(dayjs(text, 'MM/DD hh:mm:ss A', true).isValid()).to.be.true; + .should('satisfy', (text) => { + return dayjs(text, 'MM/DD hh:mm:ss A', true).isValid(); }); cy.get('select').eq(3).select('MM/DD/YY hh:mm A'); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(1000); + cy.wait('@timeUpdateRequest'); cy.get('.xtick') .eq(0) .invoke('text') - .then((text) => { - expect(dayjs(text, 'MM/DD/YY hh:mm A', true).isValid()).to.be.true; + .should('satisfy', (text) => { + return dayjs(text, 'MM/DD/YY hh:mm A', true).isValid(); }); cy.get('select').eq(3).select('HH:mm:ss.SSS'); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(1000); + cy.wait('@timeUpdateRequest'); cy.get('.xtick') .eq(0) .invoke('text') - .then((text) => { - expect(dayjs(text, 'HH:mm:ss.SSS', true).isValid()).to.be.true; + .should('satisfy', (text) => { + return dayjs(text, 'HH:mm:ss.SSS', true).isValid(); }); cy.get('select').eq(3).select('MM/DD HH:mm:ss'); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(1000); + cy.wait('@timeUpdateRequest'); cy.get('.xtick') .eq(0) .invoke('text') - .then((text) => { - expect(dayjs(text, 'MM/DD HH:mm:ss', true).isValid()).to.be.true; + .should('satisfy', (text) => { + return dayjs(text, 'MM/DD HH:mm:ss', true).isValid(); }); cy.get('select').eq(3).select('MM/DD/YY HH:mm'); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(1000); + cy.wait('@timeUpdateRequest'); cy.get('.xtick') .eq(0) .invoke('text') - .then((text) => { - expect(dayjs(text, 'MM/DD/YY HH:mm', true).isValid()).to.be.true; + .should('satisfy', (text) => { + return dayjs(text, 'MM/DD/YY HH:mm', true).isValid(); }); }); @@ -211,9 +186,7 @@ describe('Configure panel settings', () => { cy.get('g.traces').should('have.length', DEFAULT_SIZE); cy.get('.euiSwitch__label').contains('Show legend').click({ force: true }); - cy.wait(delay); cy.get('.euiButton__text').contains('Update').click({ force: true }); - cy.wait(delay); cy.get('g.traces').should('not.exist'); }); @@ -224,13 +197,10 @@ describe('Add gantt chart to dashboard', () => { cy.visit(`${Cypress.env('opensearchDashboards')}/app/dashboards#/create`); cy.contains('Add an existing').click({ force: true }); - cy.wait(delay); cy.get('input[data-test-subj="savedObjectFinderSearchInput"]').focus().type(GANTT_VIS_NAME); - cy.wait(delay); cy.get(`.euiListGroupItem__label[title="${GANTT_VIS_NAME}"]`).click({ force: true, }); - cy.wait(delay); cy.get('g.traces').should('have.length', DEFAULT_SIZE); }); diff --git a/gantt-chart/.cypress/utils/constants.js b/gantt-chart/.cypress/utils/constants.js index a8a4d73..3854318 100644 --- a/gantt-chart/.cypress/utils/constants.js +++ b/gantt-chart/.cypress/utils/constants.js @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -export const delay = 100; export const GANTT_VIS_NAME = 'A test gantt chart ' + Math.random().toString(36).substring(2); export const Y_LABEL = 'A unique label for Y-axis'; export const X_LABEL = 'A unique label for X-axis';