From ebf030065af80274fcc7d9484a045e42d3112442 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:23:46 -0800 Subject: [PATCH] Enable cypress tests to run datagrid table in Discover (#1074) (#1077) * allow switch table * make sure the DatePickerMenu is open * update switchDiscoverTable to accomadate changing from toggle to button * skip saved queries * fixed flaky tests and missing ones --------- Signed-off-by: Anan Zhuang (cherry picked from commit 34a26307c685a405e958da16976416793e7bd59a) Co-authored-by: Anan Zhuang --- .../apps/data_explorer/date_nanos.spec.js | 1 + .../data_explorer/date_nanos_mixed.spec.js | 1 + .../apps/data_explorer/discover.spec.js | 12 ++++++ .../apps/data_explorer/doc_navigation.spec.js | 1 + .../apps/data_explorer/doc_table.spec.js | 1 + .../apps/data_explorer/field_data.spec.js | 11 +++++ .../index_pattern_with_encoded_id.spec.js | 1 + .../index_pattern_without_field.spec.js | 2 + .../apps/data_explorer/large_string.spec.js | 12 +++++- .../apps/data_explorer/saved_queries.spec.js | 8 +++- .../dashboards/data_explorer/commands.js | 43 +++++++++++++++++++ .../utils/dashboards/data_explorer/index.d.ts | 4 +- 12 files changed, 94 insertions(+), 3 deletions(-) diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos.spec.js index b17c78124..5a0dc3659 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos.spec.js @@ -34,6 +34,7 @@ describe('date_nanos', () => { }); miscUtils.visitPage('app/data-explorer/discover#/'); cy.waitForLoader(); + cy.switchDiscoverTable('new'); cy.setTopNavDate(fromTime, toTime); cy.waitForSearch(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos_mixed.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos_mixed.spec.js index 07e48047f..b56b2ab54 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos_mixed.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/date_nanos_mixed.spec.js @@ -31,6 +31,7 @@ describe('date_nanos_mixed', () => { }); miscUtils.visitPage('app/data-explorer/discover#/'); cy.waitForLoader(); + cy.switchDiscoverTable('new'); const fromTime = 'Jan 1, 2019 @ 00:00:00.000'; const toTime = 'Jan 1, 2019 @ 23:59:59.999'; diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/discover.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/discover.spec.js index 711ed3f5c..a11258d08 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/discover.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/discover.spec.js @@ -62,6 +62,7 @@ describe('discover app', { scrollBehavior: false }, () => { `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` ); cy.waitForLoader(); + cy.switchDiscoverTable('new'); cy.waitForSearch(); }); @@ -70,6 +71,9 @@ describe('discover app', { scrollBehavior: false }, () => { describe('save search', () => { const saveSearch1 = 'Save Search # 1'; const saveSearch2 = 'Modified Save Search # 1'; + beforeEach(() => { + cy.switchDiscoverTable('new'); + }); it('should show correct time range string by timepicker', function () { cy.verifyTimeConfig(DE_DEFAULT_START_TIME, DE_DEFAULT_END_TIME); @@ -146,6 +150,7 @@ describe('discover app', { scrollBehavior: false }, () => { const toTime = 'Jun 12, 1999 @ 11:21:04.000'; before(() => { + cy.switchDiscoverTable('new'); cy.setTopNavDate(fromTime, toTime); }); @@ -259,6 +264,10 @@ describe('discover app', { scrollBehavior: false }, () => { }); describe('refresh interval', function () { + beforeEach(() => { + cy.switchDiscoverTable('new'); + }); + it('should refetch when autofresh is enabled', () => { cy.getElementByTestId('openInspectorButton').click(); cy.getElementByTestId('inspectorPanel') @@ -276,12 +285,15 @@ describe('discover app', { scrollBehavior: false }, () => { .should('be.visible') .clear() .type('2'); + + cy.makeDatePickerMenuOpen(); cy.getElementByTestId('superDatePickerToggleRefreshButton').click(); // Let auto refresh run cy.wait(100); // Close the auto refresh + cy.makeDatePickerMenuOpen(); cy.getElementByTestId('superDatePickerToggleRefreshButton').click(); // Check the timestamp of the last request, it should be different than the first timestamp diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_navigation.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_navigation.spec.js index 40ad4c7d9..9901acf4e 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_navigation.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_navigation.spec.js @@ -46,6 +46,7 @@ describe('doc link in discover', () => { `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` ); cy.waitForLoader(); + cy.switchDiscoverTable('new'); cy.waitForSearch(); }); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_table.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_table.spec.js index e79c33fb3..8b49c671c 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_table.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/doc_table.spec.js @@ -46,6 +46,7 @@ describe('discover doc table', () => { `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` ); cy.waitForLoader(); + cy.switchDiscoverTable('new'); cy.waitForSearch(); }); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/field_data.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/field_data.spec.js index 2cbf475ae..6f350710c 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/field_data.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/field_data.spec.js @@ -46,12 +46,17 @@ describe('discover tab', () => { `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` ); cy.waitForLoader(); + cy.switchDiscoverTable('new'); cy.waitForSearch(); }); after(() => {}); describe('field data', function () { + before(() => { + cy.switchDiscoverTable('new'); + }); + it('search php should show the correct hit count', function () { const expectedHitCount = '445'; cy.setTopNavQuery('php'); @@ -65,12 +70,18 @@ describe('discover tab', () => { }); it('search type:apache should show the correct hit count', () => { + // add this line to address flakiness in Cypress: + // ensures stable switching to the new Discover table format. + cy.switchDiscoverTable('new'); const expectedHitCount = '11,156'; cy.setTopNavQuery('type:apache'); cy.verifyHitCount(expectedHitCount); }); it('doc view should show Time and _source columns', function () { + // add this line to address flakiness in Cypress: + // ensures stable switching to the new Discover table format. + cy.switchDiscoverTable('new'); cy.getElementByTestId('dataGridHeaderCell-@timestamp').should( 'be.visible' ); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_with_encoded_id.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_with_encoded_id.spec.js index 6d99eecc5..8e4d4766f 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_with_encoded_id.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_with_encoded_id.spec.js @@ -36,6 +36,7 @@ describe('index pattern with encoded id', () => { // Go to the Discover page miscUtils.visitPage('app/data-explorer/discover#/'); + cy.switchDiscoverTable('new'); cy.setTopNavDate(DE_DEFAULT_START_TIME, DE_DEFAULT_END_TIME); cy.waitForLoader(); }); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_without_field.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_without_field.spec.js index bc09964e2..5eeb2a57e 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_without_field.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/index_pattern_without_field.spec.js @@ -33,6 +33,7 @@ describe('index pattern without field spec', () => { // Go to the Discover page miscUtils.visitPage('app/data-explorer/discover#/'); cy.waitForLoader(); + cy.switchDiscoverTable('new'); }); after(() => { @@ -49,6 +50,7 @@ describe('index pattern without field spec', () => { it('should display a timepicker after switching to an index pattern with timefield', () => { const indexName = 'with-timefield'; + cy.switchDiscoverTable('new'); cy.getElementByTestId('comboBoxToggleListButton') .should('be.visible') .click(); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/large_string.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/large_string.spec.js index 825bcbd60..c2a1fc1a2 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/large_string.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/large_string.spec.js @@ -44,6 +44,7 @@ describe('test large strings', () => { // Go to the Discover page miscUtils.visitPage('app/data-explorer/discover#/'); cy.waitForLoader(); + cy.switchDiscoverTable('new'); const ExpectedDoc = 'Project Gutenberg EBook of Hamlet'; @@ -56,7 +57,7 @@ describe('test large strings', () => { }); describe('test large data', function () { - it('search Newsletter should show the correct hit count', function () { + it('search Newsletter should show the correct hit count in legacy table', function () { cy.log('test Newsletter keyword is searched'); const expectedHitCount = '1'; const query = 'Newsletter'; @@ -64,6 +65,15 @@ describe('test large strings', () => { cy.verifyHitCount(expectedHitCount); }); + it('search Newsletter should show the correct hit count in datagrid table', function () { + cy.log('test Newsletter keyword is searched'); + cy.switchDiscoverTable('new'); + const expectedHitCount = '1'; + const query = 'Newsletter'; + cy.setTopNavQuery(query); + cy.verifyHitCount(expectedHitCount); + }); + // flaky when looking for the highlighted mark it.skip('the search term Newsletter should be highlighted in the field data', function () { cy.log('Newsletter appears only once'); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/saved_queries.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/saved_queries.spec.js index 8173db2cb..f6b5bf711 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/saved_queries.spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/data_explorer/saved_queries.spec.js @@ -24,7 +24,7 @@ const indexSet = [ 'logstash-2015.09.20', ]; -describe('saved queries saved objects', () => { +describe.skip('saved queries saved objects', () => { const fromTime = 'Sep 20, 2015 @ 08:00:00.000'; const toTime = 'Sep 21, 2015 @ 08:00:00.000'; before(() => { @@ -50,6 +50,8 @@ describe('saved queries saved objects', () => { // Go to the Discover page miscUtils.visitPage('app/data-explorer/discover#/'); + cy.waitForLoader(); + cy.switchDiscoverTable('new'); // Set time filter cy.setTopNavDate(fromTime, toTime); @@ -62,6 +64,10 @@ describe('saved queries saved objects', () => { }); describe('saved query management component functionality', function () { + beforeEach(() => { + cy.switchDiscoverTable('new'); + }); + it('should show the saved query management component when there are no saved queries', () => { cy.getElementByTestId('saved-query-management-popover-button').click(); cy.getElementByTestId('saved-query-management-popover') diff --git a/cypress/utils/dashboards/data_explorer/commands.js b/cypress/utils/dashboards/data_explorer/commands.js index 968558b89..8170089d6 100644 --- a/cypress/utils/dashboards/data_explorer/commands.js +++ b/cypress/utils/dashboards/data_explorer/commands.js @@ -133,3 +133,46 @@ Cypress.Commands.add('deleteSaveQuery', (name) => { }); cy.getElementByTestId('confirmModalConfirmButton').click(); }); + +Cypress.Commands.add('switchDiscoverTable', (name) => { + cy.getElementByTestId('datagridTableButton') + .then(($button) => { + const buttonText = $button.text(); + + if (name === 'new' && buttonText.includes('Try new Discover')) { + cy.wrap($button).click(); + } + if (name === 'legacy' && buttonText.includes('Use legacy Discover')) { + cy.wrap($button).click(); + } + cy.waitForLoader(); + }) + .then(() => { + checkForElementVisibility(); + }); +}); + +Cypress.Commands.add('makeDatePickerMenuOpen', () => { + cy.get( + '[class="euiFormControlLayout euiFormControlLayout--group euiSuperDatePicker"]' + ).then(($popover) => { + // Check if the popover does not have the 'euiPopover-isOpen' class + if (!$popover.hasClass('euiPopover-isOpen')) { + // If not open, click the button to open the quick menu + cy.getElementByTestId('superDatePickerToggleQuickMenuButton').click(); + } + }); +}); + +function checkForElementVisibility() { + cy.getElementsByTestIds('queryInput') + .should('be.visible') + .then(($element) => { + if ($element.is(':visible')) { + return; + } else { + cy.wait(500); // Wait for half a second before checking again + checkForElementVisibility(); // Recursive call + } + }); +} diff --git a/cypress/utils/dashboards/data_explorer/index.d.ts b/cypress/utils/dashboards/data_explorer/index.d.ts index ef7c5980d..bc71c6ade 100644 --- a/cypress/utils/dashboards/data_explorer/index.d.ts +++ b/cypress/utils/dashboards/data_explorer/index.d.ts @@ -15,6 +15,8 @@ declare namespace Cypress { saveQuery(name: string, description: string): Chainable; loadSaveQuery(name: string): Chainable; clearSaveQuery(): Chainable; - deleteSaveQuery(name: string):Chainable; + deleteSaveQuery(name: string): Chainable; + switchDiscoverTable(name: string): Chainable; + makeDatePickerMenuOpen(): Chainable; } } \ No newline at end of file