|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { |
| 7 | + MiscUtils, |
| 8 | + TestFixtureHandler, |
| 9 | +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; |
| 10 | +import { CURRENT_TENANT } from '../../../../../utils/commands'; |
| 11 | + |
| 12 | +const miscUtils = new MiscUtils(cy); |
| 13 | +const testFixtureHandler = new TestFixtureHandler( |
| 14 | + cy, |
| 15 | + Cypress.env('openSearchUrl') |
| 16 | +); |
| 17 | + |
| 18 | +describe('Data source selector', () => { |
| 19 | + before(() => { |
| 20 | + CURRENT_TENANT.newTenant = 'global'; |
| 21 | + testFixtureHandler.importJSONMapping( |
| 22 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_pattern_without_timefield/mappings.json.txt' |
| 23 | + ); |
| 24 | + testFixtureHandler.importJSONDoc( |
| 25 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_pattern_without_timefield/data.json.txt' |
| 26 | + ); |
| 27 | + |
| 28 | + miscUtils.visitPage('app/data-explorer/discover#/'); |
| 29 | + cy.waitForLoader(); |
| 30 | + }); |
| 31 | + |
| 32 | + after(() => { |
| 33 | + testFixtureHandler.clearJSONMapping( |
| 34 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/index_pattern_without_timefield/mappings.json.txt' |
| 35 | + ); |
| 36 | + cy.deleteSavedObjectByType('index-pattern'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('displays all data sources by default', () => { |
| 40 | + cy.get('[data-test-subj="dataExplorerDSSelect"]').click(); |
| 41 | + cy.get('.euiComboBoxOptionsList').should('exist'); |
| 42 | + cy.get('.euiComboBoxOption__content').should('have.length', 2); |
| 43 | + }); |
| 44 | + |
| 45 | + it('filters options based on user input', () => { |
| 46 | + cy.get('[data-test-subj="dataExplorerDSSelect"] input').type('without', { |
| 47 | + force: true, |
| 48 | + }); |
| 49 | + cy.get('.euiComboBoxOption__content').should('have.length', 1); |
| 50 | + cy.get('.euiComboBoxOption__content') |
| 51 | + .first() |
| 52 | + .should('contain', 'without-timefield'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('updates the visual length of the dropdown based on filtered results', () => { |
| 56 | + cy.get('[data-test-subj="dataExplorerDSSelect"] input').clear({ |
| 57 | + force: true, |
| 58 | + }); |
| 59 | + cy.get('[data-test-subj="dataExplorerDSSelect"] input').type( |
| 60 | + 'without-timefield', |
| 61 | + { |
| 62 | + force: true, |
| 63 | + } |
| 64 | + ); |
| 65 | + cy.get('.euiComboBoxOptionsList').then(($listAfterFilter) => { |
| 66 | + const heightAfterFilter = $listAfterFilter.height(); |
| 67 | + cy.get('[data-test-subj="dataExplorerDSSelect"] input').clear({ |
| 68 | + force: true, |
| 69 | + }); |
| 70 | + cy.get('.euiComboBoxOptionsList').should(($listAll) => { |
| 71 | + expect($listAll.height()).to.be.greaterThan(heightAfterFilter); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + it('selects the correct option when clicked', () => { |
| 77 | + cy.get('[data-test-subj="dataExplorerDSSelect"] input').type( |
| 78 | + 'with-timefield', |
| 79 | + { |
| 80 | + force: true, |
| 81 | + } |
| 82 | + ); |
| 83 | + |
| 84 | + cy.contains('.euiComboBoxOption__content', 'with-timefield').click(); |
| 85 | + cy.get('[data-test-subj="dataExplorerDSSelect"] .euiComboBoxPill').should( |
| 86 | + 'contain', |
| 87 | + 'with-timefield' |
| 88 | + ); |
| 89 | + }); |
| 90 | +}); |
0 commit comments