diff --git a/cypress/integration/core_opensearch_dashboards/sidebar_test_spec.js b/cypress/integration/core_opensearch_dashboards/sidebar_test_spec.js index 192aaf70f8af..fc421373c52c 100644 --- a/cypress/integration/core_opensearch_dashboards/sidebar_test_spec.js +++ b/cypress/integration/core_opensearch_dashboards/sidebar_test_spec.js @@ -14,22 +14,19 @@ describe('sidebar spec', function () { miscUtils.visitPage('app/data-explorer/discover'); }); - describe('results display and interaction in table', function () { - describe('filter by sidebar fields', function () { + describe('filter by sidebar fields', function () { + describe('add fields', function () { const expectedValues = ['50', '57', '52', '66', '46']; + const testFields = ['_id', 'age', 'birthdate', 'salary']; + const pplQuery = 'source = vis-builder* | where age > 40'; + const sqlQuery = 'SELECT * FROM vis-builder* WHERE age > 40'; it('index pattern: DQL to PPL and SQL', function () { - DataExplorerPage.setQueryEditorLanguage('DQL'); - DataExplorerPage.setSearchRelativeDateRange('15', 'Years ago'); - - cy.intercept('/internal/search/opensearch-with-long-numerals').as('data'); DataExplorerPage.selectIndexPatternDataset('DQL'); - cy.wait('@data').then(function () { - // Check default second column - DataExplorerPage.getDocTableHeader(1).should('have.text', '_source'); - }); - const testFields = ['_id', 'age', 'birthdate', 'salary']; + DataExplorerPage.setQueryEditorLanguage('DQL'); + DataExplorerPage.setSearchRelativeDateRange('15', 'Years ago'); + DataExplorerPage.getDocTableHeader(1).should('have.text', '_source'); // Select some fields testFields.forEach((field) => { @@ -73,7 +70,7 @@ describe('sidebar spec', function () { // Send PPL query cy.intercept('/api/enhancements/search/ppl').as('pplQuery'); - DataExplorerPage.sendQueryOnMultilineEditor('source = vis-builder* | where age > 40'); + DataExplorerPage.sendQueryOnMultilineEditor(pplQuery); cy.wait('@pplQuery').then(function () { // Check table headers persistence after PPL query DataExplorerPage.checkTableHeadersByArray(testFields); @@ -87,10 +84,7 @@ describe('sidebar spec', function () { // Send SQL query DataExplorerPage.setQueryEditorLanguage('OpenSearch SQL'); cy.intercept('/api/enhancements/search/sql').as('sqlQuery'); - DataExplorerPage.sendQueryOnMultilineEditor( - 'SELECT * FROM vis-builder* WHERE age > 40', - false - ); + DataExplorerPage.sendQueryOnMultilineEditor(sqlQuery, false); cy.wait('@sqlQuery').then(function () { // Check table headers persistence after SQL query DataExplorerPage.checkTableHeadersByArray(testFields); @@ -101,17 +95,11 @@ describe('sidebar spec', function () { }); it('index: SQL and PPL', function () { - cy.intercept('/api/enhancements/search/sql').as('sqlData'); DataExplorerPage.selectIndexDataset( 'OpenSearch SQL', "I don't want to use the time filter" ); - cy.wait('@sqlData').then(function () { - // Check default first column - DataExplorerPage.getDocTableHeader(0).should('have.text', '_source'); - }); - - const testFields = ['_id', 'age', 'birthdate', 'salary']; + DataExplorerPage.getDocTableHeader(0).should('have.text', '_source'); // Select some fields testFields.forEach((field) => { @@ -150,7 +138,7 @@ describe('sidebar spec', function () { // Send PPL query cy.intercept('/api/enhancements/search/ppl').as('pplQuery'); - DataExplorerPage.sendQueryOnMultilineEditor('source = vis-builder* | where age > 40'); + DataExplorerPage.sendQueryOnMultilineEditor(pplQuery); cy.wait('@pplQuery').then(function () { // Check table headers persistence after PPL query DataExplorerPage.checkTableHeadersByArray(testFields, 0); @@ -161,10 +149,7 @@ describe('sidebar spec', function () { // Send SQL query DataExplorerPage.setQueryEditorLanguage('OpenSearch SQL'); cy.intercept('/api/enhancements/search/sql').as('sqlQuery'); - DataExplorerPage.sendQueryOnMultilineEditor( - 'SELECT * FROM vis-builder* WHERE age > 40', - false - ); + DataExplorerPage.sendQueryOnMultilineEditor(sqlQuery, false); cy.wait('@sqlQuery').then(function () { // Check table headers persistence after SQL query DataExplorerPage.checkTableHeadersByArray(testFields, 0); @@ -173,5 +158,39 @@ describe('sidebar spec', function () { }); }); }); + + describe('filter fields', function () { + it('index pattern: DQL, PPL and SQL', function () { + DataExplorerPage.selectIndexPatternDataset('DQL'); + DataExplorerPage.setQueryEditorLanguage('DQL'); + DataExplorerPage.setSearchRelativeDateRange('15', 'Years ago'); + DataExplorerPage.checkSidebarFilterBarResults('equal', 'categories'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'a'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'ag'); + + DataExplorerPage.setQueryEditorLanguage('PPL'); + DataExplorerPage.checkSidebarFilterBarResults('equal', 'categories'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'a'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'ag'); + + DataExplorerPage.setQueryEditorLanguage('OpenSearch SQL'); + DataExplorerPage.checkSidebarFilterBarResults('equal', 'categories'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'a'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'ag'); + }); + + it('index: PPL and SQL', function () { + DataExplorerPage.selectIndexDataset('PPL', "I don't want to use the time filter"); + DataExplorerPage.setQueryEditorLanguage('PPL'); + DataExplorerPage.checkSidebarFilterBarResults('equal', 'categories'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'a'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'ag'); + + DataExplorerPage.setQueryEditorLanguage('OpenSearch SQL'); + DataExplorerPage.checkSidebarFilterBarResults('equal', 'categories'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'a'); + DataExplorerPage.checkSidebarFilterBarResults('include', 'ag'); + }); + }); }); }); diff --git a/cypress/utils/dashboards/data_explorer/data_explorer_page.po.js b/cypress/utils/dashboards/data_explorer/data_explorer_page.po.js index 57acb2c29887..ee64479e8ca3 100644 --- a/cypress/utils/dashboards/data_explorer/data_explorer_page.po.js +++ b/cypress/utils/dashboards/data_explorer/data_explorer_page.po.js @@ -192,6 +192,20 @@ export class DataExplorerPage { return cy.getElementByTestId(DATA_EXPLORER_PAGE_ELEMENTS.GLOBAL_FILTER_BAR); } + /** + * Get sidebar filter bar. + */ + static getSidebarFilterBar() { + return cy.getElementByTestId(DATA_EXPLORER_PAGE_ELEMENTS.SIDEBAR_FILTER_BAR); + } + + /** + * Click on the "Clear input" button on the sidebar filter bar. + */ + static clearSidebarFilterBar() { + return cy.get('button[aria-label="Clear input"]').click(); + } + /** * Get sidebar add field button by index. * @param index Integer that starts at 0 for the first add button. @@ -207,6 +221,31 @@ export class DataExplorerPage { return cy.getElementByTestId('fieldToggle-' + name); } + /** + * Get all sidebar add field button. + */ + static getAllSidebarAddFields() { + return cy.get('[data-test-subj^="field-"]:not([data-test-subj$="showDetails"])'); + } + + /** + * Check the results of the sidebar filter bar search. + * @param search string to look up + * @param assertion the type of assertion that is going to be performed. Example: 'eq', 'include' + */ + static checkSidebarFilterBarResults(assertion, search) { + DataExplorerPage.getSidebarFilterBar().type(search); + DataExplorerPage.getAllSidebarAddFields().each(function ($field) { + cy.wrap($field) + .should('be.visible') + .invoke('text') + .then(function ($fieldTxt) { + cy.wrap($fieldTxt).should(assertion, search); + }); + }); + DataExplorerPage.clearSidebarFilterBar(); + } + /** * Open window to select Dataset */ diff --git a/cypress/utils/dashboards/data_explorer/elements.js b/cypress/utils/dashboards/data_explorer/elements.js index 84ea6db46b82..b484a6500fbb 100644 --- a/cypress/utils/dashboards/data_explorer/elements.js +++ b/cypress/utils/dashboards/data_explorer/elements.js @@ -28,4 +28,5 @@ export const DATA_EXPLORER_PAGE_ELEMENTS = { QUERY_EDITOR_MULTILINE: 'osdQueryEditor__multiLine', GLOBAL_QUERY_EDITOR_FILTER_VALUE: 'globalFilterLabelValue', GLOBAL_FILTER_BAR: 'globalFilterBar', + SIDEBAR_FILTER_BAR: 'fieldFilterSearchInput', };