diff --git a/cypress.json b/cypress.json index f34fb820e..df859326c 100644 --- a/cypress.json +++ b/cypress.json @@ -7,6 +7,7 @@ "reporterOptions": { "configFile": "reporter-config.json" }, + "experimentalStudio": true, "viewportWidth": 2000, "viewportHeight": 1320, "env": { diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/datasource_selector.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/datasource_selector.spec.js new file mode 100644 index 000000000..42dbfca8f --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/datasource_selector.spec.js @@ -0,0 +1,155 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + MiscUtils, + TestFixtureHandler, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../../../utils/commands'; +import { cloneDeep } from 'lodash'; + +const miscUtils = new MiscUtils(cy); +const testFixtureHandler = new TestFixtureHandler( + cy, + Cypress.env('openSearchUrl') +); + +describe('Data source selector', () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_pattern_without_timefield/mappings.json.txt' + ); + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_pattern_without_timefield/data.json.txt' + ); + + miscUtils.visitPage('app/data-explorer/discover#/'); + }); + + after(() => { + testFixtureHandler.clearJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_pattern_without_timefield/mappings.json.txt' + ); + cy.deleteSavedObjectByType('index-pattern'); + }); + + it('displays all data sources by default', () => { + // Needs validation + cy.get('[data-test-subj="datasetSelectorButton"]').click({ force: true }); + cy.get('.euiSelectableListItem__text').should('have.length', 2); + }); + + it('filters options based on user input', () => { + cy.get('input[aria-label="Filter options"]').click().type('without', { + force: true, + }); + cy.get('.euiSelectableListItem__text').should('have.length', 1); + cy.get('.euiSelectableListItem__text') + .first() + .should('contain', 'without-timefield'); + }); + + it('updates the visual length of the dropdown based on filtered results', () => { + // cy.get('[data-test-subj="datasetSelectorButton"]').click({ force: true }); + cy.get('input[aria-label="Filter options"]').click().clear({ + force: true, + }); + cy.get('input[aria-label="Filter options"]') + .click() + .type('without-timefield', { + force: true, + }); + cy.get('.euiSelectableList').then(($listAfterFilter) => { + const heightAfterFilter = $listAfterFilter.height(); + cy.get('input[aria-label="Filter options"]').click().clear({ + force: true, + }); + cy.get('.euiSelectableList').should(($listAll) => { + expect($listAll.height()).to.be.greaterThan(heightAfterFilter); + }); + }); + }); + + it('selects the correct option when clicked', () => { + // cy.get('[data-test-subj="datasetSelectorButton"]').click({ force: true }); + cy.get('input[aria-label="Filter options"]') + .click() + .type('with-timefield', { + force: true, + }); + + cy.contains('.euiSelectableListItem__text', 'with-timefield').click(); + cy.get( + '[data-test-subj="datasetSelectorButton"] .euiButton__content' + ).should('contain', 'with-timefield'); + }); +}); + +describe('data source selector', () => { + before(() => { + // Creating additional index patterns + // logstash index pattern + + cy.createIndexPattern( + 'logstash-sample-1', + { + title: 'logstash-sample-1*', + timeFieldName: 'timestamp', + }, + { + securitytenant: ['global'], + } + ); + cy.createIndexPattern( + 'logstash-sample-2', + { + title: 'logstash-sample-2*', + timeFieldName: 'timestamp', + }, + { + securitytenant: ['global'], + } + ); + cy.wait(5000); // Intentional Wait + cy.reload(); + }); + it('check data source selector options are ordered', function () { + const indexPatterns = []; + cy.get('[data-test-subj="datasetSelectorButton"]').click({ force: true }); + cy.get('input[aria-label="Filter options"]') + .click() + .type('l') + .then(() => { + cy.get('[role="option"]') + .each((res) => { + indexPatterns.push(res.text()); + }) + .then(() => { + const sortedIndexPatterns = cloneDeep(indexPatterns); + sortedIndexPatterns.sort(); + + console.log(sortedIndexPatterns); + + cy.wrap(indexPatterns).should('deep.equal', sortedIndexPatterns); + }); + }); + }); + + it('check filtering in data source selector ', function () { + cy.get('input[aria-label="Filter options"]') + .click() + .clear() + .type('logstash-sample') + .then(() => { + cy.get('[role="option"]').should('have.length', 2); + }); + }); + + after(() => { + cy.deleteIndexPattern('logstash-sample-1'); + cy.deleteIndexPattern('logstash-sample-2'); + }); +}); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/discover_histogram.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/discover_histogram.spec.js new file mode 100644 index 000000000..831e66a4b --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/discover_histogram.spec.js @@ -0,0 +1,96 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + TestFixtureHandler, + MiscUtils, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../../../utils/commands'; + +const miscUtils = new MiscUtils(cy); +const testFixtureHandler = new TestFixtureHandler( + cy, + Cypress.env('openSearchUrl') +); +const indexSet = [ + 'logstash-2015.09.22', + 'logstash-2015.09.21', + 'logstash-2015.09.20', +]; + +describe('discover histogram', { scrollBehavior: false }, () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + cy.log('load opensearch-dashboards index with default index pattern'); + + // import long window logstash index pattern + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash_index_pattern/data.json.txt' + ); + + // import logstash functional + testFixtureHandler.importJSONDocIfNeeded( + indexSet, + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt', + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt' + ); + + // import long window logstash + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/data.json.txt' + ); + + cy.setAdvancedSetting({ + defaultIndex: 'long-window-logstash-*', + 'dateFormat:tz': 'Europe/Berlin', + }); + + // Go to the Discover page + miscUtils.visitPage('app/data-explorer/discover#/'); + cy.waitForLoaderNewHeader(); + }); + + after(() => { + miscUtils.visitPage('app/management/opensearch-dashboards/settings'); + cy.waitForLoaderNewHeader(); + cy.getElementByTestId('advancedSetting-resetField-dateFormat:tz').click({ + force: true, + }); + cy.getElementByTestId('advancedSetting-saveButton').click({ force: true }); + testFixtureHandler.clearJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/mappings.json.txt' + ); + cy.deleteIndex('long-window-logstash-0'); + cy.deleteSavedObjectByType('index-pattern'); + cy.clearCache(); + }); + + it('should visualize monthly data with different day intervals', () => { + const fromTime = 'Nov 01, 2017 @ 00:00:00.000'; + const toTime = 'Mar 21, 2018 @ 00:00:00.000'; + cy.setDatasource('long-window-logstash-*'); + cy.prepareNewTest(fromTime, toTime, 'Month'); + cy.get('.echChart canvas:last-of-type').should('be.visible'); + }); + it('should visualize weekly data with within DST changes', () => { + const fromTime = 'Mar 01, 2018 @ 00:00:00.000'; + const toTime = 'May 01, 2018 @ 00:00:00.000'; + cy.setDatasource('long-window-logstash-*'); + cy.prepareNewTest(fromTime, toTime, 'Week'); + cy.get('.echChart canvas:last-of-type').should('be.visible'); + }); + it('should visualize monthly data with different years scaled to 30 days', () => { + const fromTime = 'Jan 01, 2010 @ 00:00:00.000'; + const toTime = 'Mar 21, 2019 @ 00:00:00.000'; + cy.setDatasource('long-window-logstash-*'); + cy.prepareNewTest(fromTime, toTime, 'Day'); + cy.get('.echChart canvas:last-of-type').should('be.visible'); + cy.get('.euiToolTipAnchor').should('be.visible'); + }); +}); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/discover_table.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/discover_table.spec.js new file mode 100644 index 000000000..d73af39e3 --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/discover_table.spec.js @@ -0,0 +1,92 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { + MiscUtils, + TestFixtureHandler, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../../../utils/commands'; + +const miscUtils = new MiscUtils(cy); +const testFixtureHandler = new TestFixtureHandler( + cy, + Cypress.env('openSearchUrl') +); + +const indexSet = [ + 'logstash-2015.09.22', + 'logstash-2015.09.21', + 'logstash-2015.09.20', +]; + +// Setting up the page +describe('discover_table', () => { + before(() => { + // import logstash functional + CURRENT_TENANT.newTenant = 'global'; + testFixtureHandler.importJSONDocIfNeeded( + indexSet, + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt', + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt' + ); + + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.json.txt' + ); + + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_with_nested_field/mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_with_nested_field/data.json.txt' + ); + + cy.setAdvancedSetting({ + defaultIndex: 'logstash-*', + }); + + // Go to the Discover page + miscUtils.visitPage( + `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` + ); + cy.setDatasource('logstash-*'); + cy.waitForSearch(); + }); + + describe('auto line wrapping in legacy table', () => { + it('auto line wrapping in legacy table', function () { + // last element is _scrore if there is wrapping this field won't be present + // So we check for the presence of the _score element in the legacy table + + cy.get('.euiDescriptionList__title').should('contain.text', '_score'); + }); + }); + + describe('expand multiple documents in legacy table', () => { + it('checks if multiple documents can be expanded in legacy table', function () { + // expanding a document in the table + cy.get('[data-test-subj="docTableExpandToggleColumn"]') + .find('[type="button"]') + .eq(2) + .click(); + + // expanding a document in the table + cy.get('[data-test-subj="docTableExpandToggleColumn"]') + .find('[type="button"]') + .eq(3) + .click(); + + // checking the number of exapnded documents visible on screen + cy.get('[data-test-subj="tableDocViewRow-_index"]').should( + 'have.length', + 2 + ); + }); + }); +}); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/left_panel.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/left_panel.spec.js new file mode 100644 index 000000000..3fdd3b7e2 --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancement/left_panel.spec.js @@ -0,0 +1,182 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { + MiscUtils, + TestFixtureHandler, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../../../utils/commands'; + +const miscUtils = new MiscUtils(cy); +const testFixtureHandler = new TestFixtureHandler( + cy, + Cypress.env('openSearchUrl') +); + +const indexSet = [ + 'logstash-2015.09.22', + 'logstash-2015.09.21', + 'logstash-2015.09.20', +]; + +// Setting up the page +describe('discover_table', () => { + before(() => { + // import logstash functional + CURRENT_TENANT.newTenant = 'global'; + testFixtureHandler.importJSONDocIfNeeded( + indexSet, + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt', + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt' + ); + + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.json.txt' + ); + + testFixtureHandler.importJSONMapping( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_with_nested_field/mappings.json.txt' + ); + + testFixtureHandler.importJSONDoc( + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_with_nested_field/data.json.txt' + ); + + cy.setAdvancedSetting({ + defaultIndex: 'logstash-*', + }); + + // Go to the Discover page + miscUtils.visitPage( + `app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))` + ); + cy.setDatasource('logstash-*'); + cy.waitForSearch(); + }); + + after(() => { + cy.deleteSavedObjectByType('index-pattern'); + }); + + it('check _source is available as default selected field', function () { + cy.get('[data-test-subj="fieldList-selected"]').should( + 'contain.text', + '_source' + ); + }); + it('check timestamp is not added to selected field when a column is added', function () { + // Click to add fields + cy.get('[data-test-subj="fieldToggle-_id"]').click(); + cy.get('[data-test-subj="fieldToggle-agent"]').click(); + + // Check that the selected field don't contain timestamp + cy.get('[data-test-subj="fieldList-selected"]').should( + 'not.contain.text', + '@timestamp' + ); + }); + it('check timestamp is not added to selected field when a column is removed', function () { + cy.get('[data-test-subj="fieldToggle-_id"]').first().click(); + + // Check that the selected field don't contain timestamp + cy.get('[data-test-subj="fieldList-selected"]').should( + 'not.contain.text', + '@timestamp' + ); + }); + it('check _source gets restored when all selected columns are removed', function () { + cy.get('[data-test-subj="fieldToggle-agent"]').first().click(); // toggle the previously selected fields + + // Now the field selected should get defaulted to _source + cy.get('[data-test-subj="fieldList-selected"]').should('have.length', 1); + cy.get('[data-test-subj="fieldList-selected"]').should( + 'contain.text', + '_source' + ); + }); + it('check field is removed from available fields and added to selected fields when the field is selected', function () { + // Field present in Available Field Section + cy.get('[data-test-subj="fieldList-unpopular"]') + .find('[data-test-subj="field-host"]') + .should('exist'); + + // Toggle to display the field + cy.get('[data-test-subj="fieldList-unpopular"]') + .find('[data-test-subj="fieldToggle-host"]') + .click(); + + // Check to ensure the field is no longer present in Available Field + cy.get('[data-test-subj="fieldList-unpopular"]') + .find('[data-test-subj="field-host"]') + .should('not.exist'); + // Check the field is present in the Selected Field Secition + cy.get('[data-test-subj="fieldList-selected"]').should( + 'contain.text', + 'host' + ); + + // Reseting the toggled Field + cy.get('[data-test-subj="fieldList-selected"]') + .find('[data-test-subj="fieldToggle-host"]') + .click(); + }); + + it('check collapsablity of left navigation display', function () { + cy.get('[data-test-subj="euiResizableButton"]') + .trigger('click') + .then(() => { + cy.get('[aria-label="Press to toggle this panel"]') + .trigger('click') + .then(() => { + cy.get('[data-test-subj="datasetSelectorButton"]').should( + 'not.be.visible' + ); + }); + }); + }); + + it('check nested field are available in left navigation pane', function () { + // Create an Index pattern + cy.createIndexPattern( + 'nestedindex', + { + title: 'nestedindex*', + timeFieldName: 'timestamp', + }, + { + securitytenant: ['global'], + } + ); + cy.reload(); + + cy.get('[data-test-subj="datasetSelectorButton"]').click(); + cy.get('input[aria-label="Filter options"]') + .click() + .type('nestedindex') + .then(() => { + cy.waitForSearch(); + cy.get('[title="nestedindex*"]') + .trigger('click') + .then(() => { + // validate the presence of nested fields in left navigation pane + cy.get('[data-test-subj="fieldList-unpopular"]') + .find('[data-test-subj="field-products.base_price"]') + .should('exist'); + cy.get('[data-test-subj="fieldList-unpopular"]') + .find('[data-test-subj="field-products.quantity"]') + .should('exist'); + cy.get('[data-test-subj="fieldList-unpopular"]') + .find('[data-test-subj="field-products.discount_percentage"]') + .should('exist'); + cy.get('[data-test-subj="fieldList-unpopular"]') + .find('[data-test-subj="field-products.manufacturer"]') + .should('exist'); + }); + }); + }); +}); diff --git a/cypress/utils/dashboards/query_enhancement/commands.js b/cypress/utils/dashboards/query_enhancement/commands.js index 88f852c9b..2212964b0 100644 --- a/cypress/utils/dashboards/query_enhancement/commands.js +++ b/cypress/utils/dashboards/query_enhancement/commands.js @@ -45,3 +45,18 @@ Cypress.Commands.add('setQueryLanguage', (value, submit = true) => { force: true, }); }); + +Cypress.Commands.add('setDatasource', (value) => { + cy.get(`[class~="datasetSelector__button"]`).click(); + cy.get(`[data-test-subj="datasetOption-${value}"]`).click(); +}); + +Cypress.Commands.add('prepareNewTest', (fromTime, toTime, interval) => { + cy.setTopNavDate(fromTime, toTime); + cy.waitForLoaderNewHeader(); + // wait until the search has been finished + cy.waitForSearch(); + cy.get('select').select(`${interval}`); + cy.waitForLoaderNewHeader(); + cy.waitForSearch(); +});