|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import { BASE_PATH } from '../../base_constants'; |
7 | | -import { DS_API } from './constants'; |
| 7 | +import { |
| 8 | + DS_API, |
| 9 | + DEFAULT_DS_TITLE, |
| 10 | + OSD_TEST_DATA_SOURCE_ENDPOINT_NO_AUTH, |
| 11 | + AUTH_TYPE_NO_AUTH, |
| 12 | +} from './constants'; |
8 | 13 | import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; |
9 | 14 |
|
10 | 15 | const miscUtils = new MiscUtils(cy); |
| 16 | +export const DisableLocalCluster = !!Cypress.env('DISABLE_LOCAL_CLUSTER'); // = hideLocalCluster |
11 | 17 |
|
12 | 18 | Cypress.Commands.add('deleteAllDataSources', () => { |
13 | 19 | // Clean all data sources |
@@ -155,3 +161,82 @@ Cypress.Commands.add( |
155 | 161 | }); |
156 | 162 | } |
157 | 163 | ); |
| 164 | + |
| 165 | +Cypress.Commands.add( |
| 166 | + 'selectFromDataSourceSelectable', |
| 167 | + (dataSourceTitle, dataSourceId) => { |
| 168 | + cy.get('#dataSourceSelectableContextMenuPopover').click(); |
| 169 | + cy.getElementByTestId('dataSourceSelectable') |
| 170 | + .find('input') |
| 171 | + .clear() |
| 172 | + .type(dataSourceTitle); |
| 173 | + cy.wait(1000); |
| 174 | + let dataSourceElement; |
| 175 | + if (dataSourceId) { |
| 176 | + dataSourceElement = cy.get(`#${dataSourceId}`); |
| 177 | + } else if (dataSourceTitle) { |
| 178 | + dataSourceElement = cy |
| 179 | + .get('.euiSelectableListItem') |
| 180 | + .contains(dataSourceTitle) |
| 181 | + .closest('.euiSelectableListItem'); |
| 182 | + } |
| 183 | + dataSourceElement.click(); |
| 184 | + // Close data source selectable manually if no data source element need to be clicked |
| 185 | + if (!dataSourceElement) { |
| 186 | + cy.getElementByTestId('dataSourceSelectable').last('button').click(); |
| 187 | + } |
| 188 | + } |
| 189 | +); |
| 190 | + |
| 191 | +Cypress.Commands.add('checkDataSourceExist', (dataSourceTitle) => { |
| 192 | + cy.contains('li.euiSelectableListItem', dataSourceTitle) |
| 193 | + .should('exist') // Ensure the list item exists |
| 194 | + .within(() => { |
| 195 | + // Verify the 'Default' badge exists within the same list item |
| 196 | + if (dataSourceTitle === DEFAULT_DS_TITLE) { |
| 197 | + cy.get('span.euiBadge__text').should('exist').and('contain', 'Default'); // Ensure the badge contains the text 'Default' |
| 198 | + } |
| 199 | + }); |
| 200 | +}); |
| 201 | + |
| 202 | +Cypress.Commands.add('viewDataSourceAggregatedView', (dataSourceTitle) => { |
| 203 | + cy.get('#dataSourceSViewContextMenuPopover').click(); |
| 204 | + cy.wait(1000); |
| 205 | + |
| 206 | + cy.get('.dataSourceAggregatedViewOuiPanel').within(() => { |
| 207 | + // Check if the Local cluster is selected |
| 208 | + |
| 209 | + cy.contains(dataSourceTitle).should('be.visible'); |
| 210 | + cy.get('.dataSourceAggregatedViewOuiSwitch').should('not.checked'); |
| 211 | + if (!DisableLocalCluster) { |
| 212 | + cy.contains('Local cluster').should('be.visible'); |
| 213 | + cy.get('.dataSourceAggregatedViewOuiSwitch').click(); |
| 214 | + cy.contains(dataSourceTitle).should('not.exist'); |
| 215 | + } |
| 216 | + }); |
| 217 | +}); |
| 218 | + |
| 219 | +Cypress.Commands.add('createDataSourceNoAuthWithTitle', (title) => { |
| 220 | + miscUtils.visitPage( |
| 221 | + 'app/management/opensearch-dashboards/dataSources/create' |
| 222 | + ); |
| 223 | + |
| 224 | + cy.intercept('POST', '/api/saved_objects/data-source').as( |
| 225 | + 'createDataSourceRequest' |
| 226 | + ); |
| 227 | + cy.getElementByTestId('createDataSourceButton').should('be.disabled'); |
| 228 | + cy.get('[name="dataSourceTitle"]').type(title); |
| 229 | + cy.get('[name="endpoint"]').type(OSD_TEST_DATA_SOURCE_ENDPOINT_NO_AUTH); |
| 230 | + cy.getElementByTestId('createDataSourceFormAuthTypeSelect').click(); |
| 231 | + cy.get(`button[id=${AUTH_TYPE_NO_AUTH}]`).click(); |
| 232 | + |
| 233 | + cy.getElementByTestId('createDataSourceButton').should('be.enabled'); |
| 234 | + cy.get('[name="dataSourceDescription"]').type( |
| 235 | + 'cypress test no auth data source' |
| 236 | + ); |
| 237 | + cy.wait(1000); |
| 238 | + cy.getElementByTestId('createDataSourceButton').click(); |
| 239 | + cy.wait('@createDataSourceRequest').then((interception) => { |
| 240 | + expect(interception.response.statusCode).to.equal(200); |
| 241 | + }); |
| 242 | +}); |
0 commit comments