Skip to content

Commit

Permalink
finish second test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Silva committed Dec 10, 2024
1 parent 1ce5e73 commit 62dbaf0
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 28 deletions.
75 changes: 47 additions & 28 deletions cypress/integration/core_opensearch_dashboards/sidebar_test_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) => {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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');
});
});
});
});
39 changes: 39 additions & 0 deletions cypress/utils/dashboards/data_explorer/data_explorer_page.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions cypress/utils/dashboards/data_explorer/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

0 comments on commit 62dbaf0

Please sign in to comment.