|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { BASE_PATH } from '../../../base_constants'; |
| 7 | + |
| 8 | +export const UiSettingsTestCases = () => { |
| 9 | + let ownerWorkspaceName = 'owner_workspace'; |
| 10 | + |
| 11 | + let ownerWorkspaceId = ''; |
| 12 | + let datasourceId1 = ''; |
| 13 | + let datasourceId2 = ''; |
| 14 | + |
| 15 | + const setupWorkspace = (workspaceName, datasourceId) => { |
| 16 | + return cy |
| 17 | + .createWorkspace({ |
| 18 | + name: workspaceName, |
| 19 | + features: ['use-case-observability'], |
| 20 | + settings: { |
| 21 | + permissions: { |
| 22 | + library_write: { users: ['%me%'] }, |
| 23 | + write: { users: ['%me%'] }, |
| 24 | + }, |
| 25 | + ...(datasourceId ? { dataSources: [datasourceId] } : {}), |
| 26 | + }, |
| 27 | + }) |
| 28 | + .then((value) => { |
| 29 | + cy.loadSampleDataForWorkspace('logs', value, datasourceId); |
| 30 | + cy.wrap(value); |
| 31 | + }); |
| 32 | + }; |
| 33 | + |
| 34 | + if ( |
| 35 | + Cypress.env('WORKSPACE_ENABLED') && |
| 36 | + Cypress.env('DATASOURCE_MANAGEMENT_ENABLED') |
| 37 | + ) { |
| 38 | + describe('Workspace UI Settings', () => { |
| 39 | + before(() => { |
| 40 | + cy.deleteWorkspaceByName(ownerWorkspaceName); |
| 41 | + cy.deleteAllDataSources(); |
| 42 | + cy.setAdvancedSetting({ |
| 43 | + defaultDataSource: '', |
| 44 | + }); |
| 45 | + |
| 46 | + cy.createDataSourceNoAuth().then((result) => { |
| 47 | + datasourceId1 = result[0]; |
| 48 | + expect(datasourceId1).to.be.a('string').that.is.not.empty; |
| 49 | + setupWorkspace(ownerWorkspaceName, datasourceId1).then( |
| 50 | + (value) => (ownerWorkspaceId = value) |
| 51 | + ); |
| 52 | + }); |
| 53 | + cy.createDataSourceNoAuth().then((result) => { |
| 54 | + datasourceId2 = result[0]; |
| 55 | + expect(datasourceId2).to.be.a('string').that.is.not.empty; |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + after(() => { |
| 60 | + cy.removeSampleDataForWorkspace( |
| 61 | + 'logs', |
| 62 | + ownerWorkspaceId, |
| 63 | + datasourceId1 |
| 64 | + ); |
| 65 | + cy.deleteWorkspaceByName(ownerWorkspaceName); |
| 66 | + cy.deleteAllDataSources(); |
| 67 | + cy.setAdvancedSetting({ |
| 68 | + defaultDataSource: '', |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('Default data source', () => { |
| 73 | + it('Default data source setting inside data source management page should work as expected', () => { |
| 74 | + cy.visit(`${BASE_PATH}/app/dataSources/${datasourceId1}`); |
| 75 | + cy.getElementByTestId('editSetDefaultDataSource') |
| 76 | + .should('be.exist') |
| 77 | + .should('be.enabled') |
| 78 | + .click({ force: true }); |
| 79 | + cy.wait(1000); |
| 80 | + cy.getElementByTestId('editSetDefaultDataSource') |
| 81 | + .should('be.exist') |
| 82 | + .should('be.disabled'); |
| 83 | + |
| 84 | + cy.visit(`${BASE_PATH}/app/dataSources/${datasourceId2}`); |
| 85 | + |
| 86 | + cy.getElementByTestId('editSetDefaultDataSource') |
| 87 | + .should('be.exist') |
| 88 | + .should('be.enabled') |
| 89 | + .click({ force: true }); |
| 90 | + cy.wait(1000); |
| 91 | + cy.getElementByTestId('editSetDefaultDataSource') |
| 92 | + .should('be.exist') |
| 93 | + .should('be.disabled'); |
| 94 | + |
| 95 | + cy.visit(`${BASE_PATH}/app/dataSources/${datasourceId1}`); |
| 96 | + cy.getElementByTestId('editSetDefaultDataSource') |
| 97 | + .should('be.exist') |
| 98 | + .should('be.enabled'); |
| 99 | + }); |
| 100 | + |
| 101 | + it('Default data source setting inside application pages should work as expected', () => { |
| 102 | + cy.visit(`${BASE_PATH}/app/settings`); |
| 103 | + cy.get( |
| 104 | + '[data-test-subj="advancedSetting-editField-defaultDataSource"]' |
| 105 | + ).then(($input) => { |
| 106 | + if ($input.prop('disabled')) { |
| 107 | + cy.log('Input field is disabled and cannot be changed.'); |
| 108 | + } else { |
| 109 | + cy.wrap($input).clear().type(datasourceId1); |
| 110 | + cy.get('[data-test-subj="advancedSetting-saveButton"]').click(); |
| 111 | + cy.wrap($input).should('have.value', datasourceId1); |
| 112 | + } |
| 113 | + }); |
| 114 | + }); |
| 115 | + }); |
| 116 | + |
| 117 | + describe('Application settings', () => { |
| 118 | + it('CRUD operations inside application settings should work as expected', () => { |
| 119 | + cy.visit(`${BASE_PATH}/app/settings`); |
| 120 | + |
| 121 | + cy.get( |
| 122 | + '[data-test-subj="advancedSetting-editField-csv:quoteValues"]' |
| 123 | + ).then(($switch) => { |
| 124 | + if ($switch.prop('disabled')) { |
| 125 | + cy.log('Switch is disabled and cannot be changed.'); |
| 126 | + } else if ($switch.attr('aria-checked') === 'true') { |
| 127 | + cy.wrap($switch).click(); |
| 128 | + cy.get('[data-test-subj="advancedSetting-saveButton"]').click(); |
| 129 | + cy.get($switch).should('have.attr', 'aria-checked', 'false'); |
| 130 | + } else { |
| 131 | + cy.log('The switch is already on.'); |
| 132 | + } |
| 133 | + }); |
| 134 | + }); |
| 135 | + }); |
| 136 | + |
| 137 | + describe('Default data source', () => { |
| 138 | + it('Default data source setting inside application pages should work as expected', () => { |
| 139 | + cy.visit(`${BASE_PATH}/app/settings`); |
| 140 | + cy.get( |
| 141 | + '[data-test-subj="advancedSetting-editField-defaultDataSource"]' |
| 142 | + ).then(($input) => { |
| 143 | + if ($input.prop('disabled')) { |
| 144 | + cy.log('Input field is disabled and cannot be changed.'); |
| 145 | + } else { |
| 146 | + cy.wrap($input).clear().type('newDataSource'); |
| 147 | + cy.get('[data-test-subj="advancedSetting-saveButton"]').click(); |
| 148 | + cy.wrap($input).should('have.value', 'newDataSource'); |
| 149 | + } |
| 150 | + }); |
| 151 | + }); |
| 152 | + }); |
| 153 | + |
| 154 | + describe('Default index pattern', () => { |
| 155 | + it('Default index pattern in index pattern list page should work as expected', () => { |
| 156 | + cy.visit(`${BASE_PATH}/w/${ownerWorkspaceId}/app/indexPatterns`); |
| 157 | + cy.contains('opensearch_dashboards_sample_data_logs').click(); |
| 158 | + cy.getElementByTestId('setDefaultIndexPatternButton') |
| 159 | + .should('be.exist') |
| 160 | + .should('be.enabled') |
| 161 | + .click(); |
| 162 | + cy.get('div[data-test-subj="headerBadgeControl"]') |
| 163 | + .contains('span', 'Default') |
| 164 | + .should('exist'); |
| 165 | + }); |
| 166 | + |
| 167 | + it('Default index pattern in discover page should work as expected', () => { |
| 168 | + cy.visit(`${BASE_PATH}/w/${ownerWorkspaceId}/app/discover`); |
| 169 | + cy.get('div[data-test-subj="comboBoxInput"] span').should( |
| 170 | + 'include.text', |
| 171 | + 'opensearch_dashboards_sample_data_logs' |
| 172 | + ); |
| 173 | + }); |
| 174 | + }); |
| 175 | + |
| 176 | + describe('Dismiss Get started', () => { |
| 177 | + it('Dismiss get started button in the top of each overview page should work as expected', () => { |
| 178 | + cy.visit( |
| 179 | + `${BASE_PATH}/w/${ownerWorkspaceId}/app/observability-overview/` |
| 180 | + ); |
| 181 | + cy.get('div[data-test-subj="headerRightControl"]').should('exist'); |
| 182 | + cy.get('div[data-test-subj="headerRightControl"]') |
| 183 | + .contains('button', 'Dismiss Get started') |
| 184 | + .click(); |
| 185 | + cy.get('div[data-test-subj="headerRightControl"]') |
| 186 | + .contains('button', 'Dismiss Get started') |
| 187 | + .should('not.exist'); |
| 188 | + }); |
| 189 | + }); |
| 190 | + }); |
| 191 | + } |
| 192 | +}; |
0 commit comments