Skip to content

Commit be92aa0

Browse files
[MDS]add commands to for seletable and aggregated view (#1339)
* add commands to for seletable and aggregated view, also add default data source part Signed-off-by: yujin-emma <[email protected]> * remove unnecessary mock test file Signed-off-by: yujin-emma <[email protected]> * Update cypress/utils/dashboards/datasource-management-dashboards-plugin/commands.js Co-authored-by: Zhongnan Su <[email protected]> Signed-off-by: Yu Jin <[email protected]> * Update commands.js --------- Signed-off-by: yujin-emma <[email protected]> Signed-off-by: Yu Jin <[email protected]> Co-authored-by: Zhongnan Su <[email protected]>
1 parent ab7c3e3 commit be92aa0

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

cypress/utils/commands.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import { BASE_PATH, IM_API, BACKEND_BASE_PATH } from './constants';
77

8+
export const DisableLocalCluster = !!Cypress.env('DISABLE_LOCAL_CLUSTER'); // = hideLocalCluster
9+
810
export const ADMIN_AUTH = {
911
username: Cypress.env('username'),
1012
password: Cypress.env('password'),

cypress/utils/dashboards/datasource-management-dashboards-plugin/commands.js

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
*/
55

66
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';
813
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
914

1015
const miscUtils = new MiscUtils(cy);
16+
export const DisableLocalCluster = !!Cypress.env('DISABLE_LOCAL_CLUSTER'); // = hideLocalCluster
1117

1218
Cypress.Commands.add('deleteAllDataSources', () => {
1319
// Clean all data sources
@@ -155,3 +161,82 @@ Cypress.Commands.add(
155161
});
156162
}
157163
);
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+
});

cypress/utils/dashboards/datasource-management-dashboards-plugin/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const DS_API = {
2222
};
2323
export const DS_NO_AUTH_LABEL = 'RemoteDataSourceNoAuth';
2424

25+
export const DEFAULT_DS_TITLE = 'DefaultDataSource';
26+
2527
export const TIMEOUT_OPTS = { timeout: 60000 };
2628
export const FORCE_CLICK_OPTS = { force: true };
2729
export const DATASOURCE_DELAY = 1000;

0 commit comments

Comments
 (0)