|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { |
| 7 | + TestFixtureHandler, |
| 8 | + MiscUtils, |
| 9 | +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; |
| 10 | +import { CURRENT_TENANT } from '../../../../../utils/commands'; |
| 11 | +import { |
| 12 | + DE_DEFAULT_END_TIME, |
| 13 | + DE_DEFAULT_START_TIME, |
| 14 | +} from '../../../../../utils/constants'; |
| 15 | + |
| 16 | +const miscUtils = new MiscUtils(cy); |
| 17 | +const testFixtureHandler = new TestFixtureHandler( |
| 18 | + cy, |
| 19 | + Cypress.env('openSearchUrl') |
| 20 | +); |
| 21 | +const indexSet = [ |
| 22 | + 'logstash-2015.09.22', |
| 23 | + 'logstash-2015.09.21', |
| 24 | + 'logstash-2015.09.20', |
| 25 | +]; |
| 26 | + |
| 27 | +describe( |
| 28 | + 'discover query enhancement basic functions', |
| 29 | + { scrollBehavior: false }, |
| 30 | + () => { |
| 31 | + const isEnhancement = true; |
| 32 | + before(() => { |
| 33 | + CURRENT_TENANT.newTenant = 'global'; |
| 34 | + cy.log('load opensearch-dashboards index with default index pattern'); |
| 35 | + |
| 36 | + // import long window logstash index pattern |
| 37 | + testFixtureHandler.importJSONDoc( |
| 38 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash_index_pattern/data.json.txt' |
| 39 | + ); |
| 40 | + |
| 41 | + // import logstash functional |
| 42 | + testFixtureHandler.importJSONDocIfNeeded( |
| 43 | + indexSet, |
| 44 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt', |
| 45 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt' |
| 46 | + ); |
| 47 | + |
| 48 | + // import long window logstash |
| 49 | + testFixtureHandler.importJSONMapping( |
| 50 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/mappings.json.txt' |
| 51 | + ); |
| 52 | + |
| 53 | + testFixtureHandler.importJSONDoc( |
| 54 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/data.json.txt' |
| 55 | + ); |
| 56 | + |
| 57 | + cy.setAdvancedSetting({ |
| 58 | + defaultIndex: 'long-window-logstash-*', |
| 59 | + 'dateFormat:tz': 'Europe/Berlin', |
| 60 | + 'query:enhancements:enabled': true, |
| 61 | + 'home:useNewHomePage': true, |
| 62 | + }); |
| 63 | + |
| 64 | + cy.reload(); |
| 65 | + |
| 66 | + // Go to the Discover page |
| 67 | + miscUtils.visitPage('app/data-explorer/discover#/'); |
| 68 | + }); |
| 69 | + |
| 70 | + after(() => { |
| 71 | + miscUtils.visitPage('app/management/opensearch-dashboards/settings'); |
| 72 | + cy.waitForLoader(isEnhancement); |
| 73 | + cy.getElementByTestId('advancedSetting-resetField-dateFormat:tz').click({ |
| 74 | + force: true, |
| 75 | + }); |
| 76 | + cy.getElementByTestId('advancedSetting-saveButton').click({ |
| 77 | + force: true, |
| 78 | + }); |
| 79 | + testFixtureHandler.clearJSONMapping( |
| 80 | + 'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/mappings.json.txt' |
| 81 | + ); |
| 82 | + cy.deleteIndex('long-window-logstash-0'); |
| 83 | + cy.deleteSavedObjectByType('index-pattern'); |
| 84 | + cy.setAdvancedSetting({ |
| 85 | + defaultIndex: '', |
| 86 | + 'dateFormat:tz': 'Browser', |
| 87 | + 'query:enhancements:enabled': false, |
| 88 | + 'home:useNewHomePage': false, |
| 89 | + }); |
| 90 | + |
| 91 | + cy.reload(); |
| 92 | + cy.clearCache(); |
| 93 | + }); |
| 94 | + |
| 95 | + describe('no result panel', () => { |
| 96 | + before(() => { |
| 97 | + cy.selectDatasetForEnhancement('long-window-logstash-*'); |
| 98 | + // Set a time range where we know there will be no data |
| 99 | + const fromTime = 'Jan 1, 2024 @ 00:00:00.000'; |
| 100 | + const toTime = 'Jan 2, 2024 @ 00:00:00.000'; |
| 101 | + cy.setTopNavDateWithRetry(fromTime, toTime, isEnhancement); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should show no results', () => { |
| 105 | + // Check for the presence of the no results component |
| 106 | + cy.getElementByTestId('discoverNoResults').should('be.visible'); |
| 107 | + cy.getElementByTestId('discoverNoResultsTimefilter') |
| 108 | + .should('be.visible') |
| 109 | + .should( |
| 110 | + 'contain.text', |
| 111 | + 'Try selecting a different data source, expanding your time range or modifying the query & filters.' |
| 112 | + ); |
| 113 | + }); |
| 114 | + }); |
| 115 | + |
| 116 | + describe('render discover with side bar, top nav and canvas', () => { |
| 117 | + before(() => { |
| 118 | + // Set a time range where we know there will be no data |
| 119 | + const fromTime = 'Nov 01, 2017 @ 00:00:00.000'; |
| 120 | + const toTime = 'Mar 21, 2018 @ 00:00:00.000'; |
| 121 | + cy.setTopNavDateWithRetry(fromTime, toTime, isEnhancement); |
| 122 | + }); |
| 123 | + |
| 124 | + it('should show side bar with DatasetSelector', () => { |
| 125 | + // Test dataset selector exist |
| 126 | + cy.getElementByTestId(`datasetSelectorButton`).should('exist'); |
| 127 | + |
| 128 | + // Also verify the sidebar has the field list sections |
| 129 | + cy.getElementByTestId('fieldList-selected').should('exist'); |
| 130 | + cy.getElementByTestId('fieldList-unpopular').should('exist'); |
| 131 | + }); |
| 132 | + |
| 133 | + it('should show top nav header', () => { |
| 134 | + // Test main header container |
| 135 | + cy.get('.headerAppActionMenuSection').should('exist'); |
| 136 | + cy.getElementByTestId('headerAppActionMenu').should('exist'); |
| 137 | + |
| 138 | + // Test navigation menu |
| 139 | + cy.getElementByTestId('top-nav').should('exist'); |
| 140 | + |
| 141 | + // Test all action buttons exist |
| 142 | + cy.getElementByTestId('discoverSaveButton').should('exist'); |
| 143 | + cy.getElementByTestId('discoverOpenButton').should('exist'); |
| 144 | + cy.getElementByTestId('discoverNewButton').should('exist'); |
| 145 | + cy.getElementByTestId('openInspectorButton').should('exist'); |
| 146 | + cy.getElementByTestId('shareTopNavButton').should('exist'); |
| 147 | + |
| 148 | + // Test date picker exists |
| 149 | + cy.getElementByTestId('superDatePickerToggleQuickMenuButton').should( |
| 150 | + 'exist' |
| 151 | + ); |
| 152 | + }); |
| 153 | + |
| 154 | + it('should show globalQueryEditor', () => { |
| 155 | + // Test the query editor and the query language selector components exist |
| 156 | + cy.getElementByTestId('globalQueryEditor').should('exist'); |
| 157 | + cy.getElementByTestId('queryEditorLanguageSelector').should('exist'); |
| 158 | + }); |
| 159 | + |
| 160 | + it('should show discoverTable', () => { |
| 161 | + // Test main discover table container exists |
| 162 | + cy.getElementByTestId('discoverTable').should('exist'); |
| 163 | + |
| 164 | + // Test table exists and has correct structure |
| 165 | + cy.getElementByTestId('docTable').should('exist'); |
| 166 | + |
| 167 | + // Test header cells exist |
| 168 | + cy.getElementByTestId('docTableHeader').should('exist'); |
| 169 | + cy.getElementByTestId('docTableHeaderField').should('exist'); |
| 170 | + cy.getElementByTestId(`docTableHeader-@timestamp`).should('exist'); |
| 171 | + cy.getElementByTestId(`docTableHeader-_source`).should('exist'); |
| 172 | + |
| 173 | + // Test table toggle and body exists |
| 174 | + cy.getElementByTestId('docTableExpandToggleColumn').should('exist'); |
| 175 | + cy.getElementByTestId('docTableField').should('exist'); |
| 176 | + }); |
| 177 | + }); |
| 178 | + |
| 179 | + describe('filters and queries', () => { |
| 180 | + before(() => { |
| 181 | + // Set a time range where we know there will be no data |
| 182 | + const fromTime = 'Nov 01, 2017 @ 00:00:00.000'; |
| 183 | + const toTime = 'Mar 21, 2018 @ 00:00:00.000'; |
| 184 | + cy.setTopNavDateWithRetry(fromTime, toTime, isEnhancement); |
| 185 | + }); |
| 186 | + |
| 187 | + it('should persist across refresh', function () { |
| 188 | + // Set up query and filter |
| 189 | + cy.setTopNavQuery('response:200', true, isEnhancement); |
| 190 | + cy.getElementByTestId('showFilterActions').click(); |
| 191 | + cy.submitFilterFromDropDown( |
| 192 | + 'extension.keyword', |
| 193 | + 'is one of', |
| 194 | + 'jpg', |
| 195 | + isEnhancement |
| 196 | + ); |
| 197 | + cy.reload(); |
| 198 | + cy.get('.osdQueryEditor__input .monaco-editor .view-lines').should( |
| 199 | + 'contain.text', |
| 200 | + 'response:200' |
| 201 | + ); |
| 202 | + cy.get('[data-test-subj~="filter-key-extension.keyword"]') |
| 203 | + .should('be.visible') |
| 204 | + .click(); |
| 205 | + cy.get('button[aria-label="Delete"]').click(); |
| 206 | + }); |
| 207 | + }); |
| 208 | + |
| 209 | + describe('save search', () => { |
| 210 | + const saveSearch1 = 'Save Search # 1'; |
| 211 | + const saveSearch2 = 'Modified Save Search # 1'; |
| 212 | + |
| 213 | + it('should show correct time range string by timepicker', function () { |
| 214 | + cy.setTopNavDateWithRetry( |
| 215 | + DE_DEFAULT_START_TIME, |
| 216 | + DE_DEFAULT_END_TIME, |
| 217 | + isEnhancement |
| 218 | + ); |
| 219 | + cy.verifyTimeConfig(DE_DEFAULT_START_TIME, DE_DEFAULT_END_TIME); |
| 220 | + }); |
| 221 | + |
| 222 | + it('save search should display save search name in breadcrumb', function () { |
| 223 | + cy.saveSearch(saveSearch1, isEnhancement); |
| 224 | + cy.getElementByTestId('headerAppActionMenu') |
| 225 | + .should('be.visible') |
| 226 | + .should('contain', saveSearch1); |
| 227 | + }); |
| 228 | + |
| 229 | + it('load save search should show save search name in breadcrumb', function () { |
| 230 | + cy.loadSaveSearch(saveSearch1, isEnhancement); |
| 231 | + |
| 232 | + cy.getElementByTestId('headerAppActionMenu') |
| 233 | + .should('be.visible') |
| 234 | + .should('contain', saveSearch1); |
| 235 | + }); |
| 236 | + |
| 237 | + it('renaming a save search should modify name in breadcrumb', function () { |
| 238 | + cy.loadSaveSearch(saveSearch1, isEnhancement); |
| 239 | + cy.saveSearch(saveSearch2, isEnhancement); |
| 240 | + |
| 241 | + cy.getElementByTestId('headerAppActionMenu') |
| 242 | + .should('be.visible') |
| 243 | + .should('contain', saveSearch2); |
| 244 | + }); |
| 245 | + |
| 246 | + it('should show the correct hit count', function () { |
| 247 | + cy.loadSaveSearch(saveSearch2, isEnhancement); |
| 248 | + cy.setTopNavDateWithRetry( |
| 249 | + DE_DEFAULT_START_TIME, |
| 250 | + DE_DEFAULT_END_TIME, |
| 251 | + isEnhancement |
| 252 | + ); |
| 253 | + const expectedHitCount = '31'; |
| 254 | + cy.verifyHitCount(expectedHitCount); |
| 255 | + }); |
| 256 | + |
| 257 | + it('should show correct time range string in chart', function () { |
| 258 | + cy.getElementByTestId('discoverIntervalDateRange').should( |
| 259 | + 'have.text', |
| 260 | + `${DE_DEFAULT_START_TIME} - ${DE_DEFAULT_END_TIME} per` |
| 261 | + ); |
| 262 | + }); |
| 263 | + |
| 264 | + it('should show correct initial chart interval of Auto', function () { |
| 265 | + cy.getElementByTestId('discoverIntervalSelect') |
| 266 | + .get('option') |
| 267 | + .first() |
| 268 | + .should('have.text', 'Auto'); |
| 269 | + }); |
| 270 | + |
| 271 | + it('should not show "no results"', () => { |
| 272 | + cy.getElementByTestId('discoverNoResults').should('not.exist'); |
| 273 | + }); |
| 274 | + |
| 275 | + it('should reload the saved search with persisted query to show the initial hit count', function () { |
| 276 | + // apply query some changes |
| 277 | + cy.setTopNavQuery('DE', true, isEnhancement); |
| 278 | + cy.verifyHitCount('3'); |
| 279 | + |
| 280 | + // reset to persisted state |
| 281 | + cy.getElementByTestId('resetSavedSearch').click(); |
| 282 | + const expectedHitCount = '31'; |
| 283 | + cy.verifyHitCount(expectedHitCount); |
| 284 | + }); |
| 285 | + }); |
| 286 | + } |
| 287 | +); |
0 commit comments