Skip to content

Commit fc490c3

Browse files
authored
test for default data source, added no-auth and basic auth, data source table with multi delete default ds reset, edit default ds (#1338)
Signed-off-by: yujin-emma <[email protected]>
1 parent be92aa0 commit fc490c3

File tree

2 files changed

+205
-0
lines changed

2 files changed

+205
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
7+
8+
const miscUtils = new MiscUtils(cy);
9+
10+
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
11+
describe('Default data sources', () => {
12+
before(() => {
13+
// Clean up before creating new data sources for testing
14+
cy.deleteAllDataSourcesOnUI();
15+
});
16+
17+
describe('The default data source can behave normal when edit data source table', () => {
18+
before(() => {
19+
for (let i = 1; i < 4; i++) {
20+
const title = `ds_${i}`;
21+
cy.createDataSourceNoAuthWithTitle(title);
22+
cy.wait(6000);
23+
}
24+
cy.visitDataSourcesListingPage();
25+
cy.wait(6000);
26+
});
27+
after(() => {
28+
// Clean up after all test are run
29+
cy.deleteAllDataSourcesOnUI();
30+
});
31+
it('The first data source is the default data source', () => {
32+
cy.visitDataSourcesListingPage();
33+
34+
// Use Cypress commands to find the table cell with content "ds_1"
35+
cy.contains('td.euiTableRowCell', 'ds_1').as('ds_1');
36+
37+
// Check if the cell with current ds_1 content exists
38+
cy.get('@ds_1').should('exist');
39+
40+
// Get the parent row of the cell
41+
cy.get('@ds_1').parents('tr').as('row_ds_1');
42+
// Check if the "Default" badge exists in the same row
43+
cy.get('@row_ds_1').contains('span', 'Default').should('exist');
44+
});
45+
it('Delete the default data source, the next one will become default data source', () => {
46+
cy.singleDeleteDataSourceByTitle('ds_1');
47+
48+
// Check that ds_2 now has the Default badge
49+
cy.contains('td.euiTableRowCell', 'ds_2').as('ds_2');
50+
cy.get('@ds_2').parents('tr').as('row_ds_2');
51+
cy.get('@row_ds_2').contains('span', 'Default').should('exist');
52+
});
53+
it('Go the edit data source page of default data source, the set_default button should be disabled', () => {
54+
cy.contains('a', 'ds_2')
55+
.should('exist') // Ensure the anchor tag exists
56+
.invoke('attr', 'href') // Get the href attribute
57+
.then((href) => {
58+
// Extract the unique identifier part from the href
59+
const uniqueId = href.split('/').pop(); // Assumes the unique ID is the last part of the URL
60+
miscUtils.visitPage(
61+
`app/management/opensearch-dashboards/dataSources/${uniqueId}`
62+
);
63+
cy.getElementByTestId('editSetDefaultDataSource')
64+
.should('be.exist')
65+
.should('not.enabled');
66+
cy.wait(1000);
67+
});
68+
});
69+
it('Go the edit data source page of non-default data source, the set_default button should be enabled and can set to default ds', () => {
70+
cy.visitDataSourcesListingPage();
71+
72+
cy.contains('a', 'ds_3')
73+
.should('exist') // Ensure the anchor tag exists
74+
.invoke('attr', 'href') // Get the href attribute
75+
.then((href) => {
76+
// Extract the unique identifier part from the href
77+
const uniqueId = href.split('/').pop(); // Assumes the unique ID is the last part of the URL
78+
miscUtils.visitPage(
79+
`app/management/opensearch-dashboards/dataSources/${uniqueId}`
80+
);
81+
cy.getElementByTestId('editSetDefaultDataSource')
82+
.should('be.exist')
83+
.should('be.enabled')
84+
.click({ force: true });
85+
cy.wait(1000);
86+
});
87+
cy.visitDataSourcesListingPage();
88+
cy.contains('td.euiTableRowCell', 'ds_3').as('ds_3');
89+
cy.get('@ds_3').parents('tr').as('row_ds_3');
90+
cy.get('@row_ds_3').contains('span', 'Default').should('exist');
91+
cy.contains('td.euiTableRowCell', 'ds_2').as('ds_2');
92+
cy.get('@ds_2').parents('tr').as('row_ds_2');
93+
cy.get('@row_ds_2').contains('span', 'Default').should('not.exist');
94+
});
95+
});
96+
});
97+
}

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

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,111 @@ Cypress.Commands.add('createDataSourceNoAuthWithTitle', (title) => {
240240
expect(interception.response.statusCode).to.equal(200);
241241
});
242242
});
243+
244+
Cypress.Commands.add('multiDeleteDataSourceByTitle', (dataSourceTitles) => {
245+
cy.visitDataSourcesListingPage();
246+
cy.wait(1000);
247+
248+
dataSourceTitles.forEach((dataSourceTitle) => {
249+
cy.contains('a', dataSourceTitle)
250+
.should('exist') // Ensure the anchor tag exists
251+
.invoke('attr', 'href') // Get the href attribute
252+
.then((href) => {
253+
// Extract the unique identifier part from the href
254+
const uniqueId = href.split('/').pop(); // Assumes the unique ID is the last part of the URL
255+
if (isValidUUID(uniqueId)) {
256+
const testId = `checkboxSelectRow-${uniqueId}`;
257+
cy.getElementByTestId(testId)
258+
.check({ force: true })
259+
.should('be.checked');
260+
}
261+
});
262+
});
263+
264+
// Wait for the selections to be checked
265+
cy.wait(1000);
266+
267+
cy.getElementByTestId('deleteDataSourceConnections')
268+
.should('exist')
269+
.should('be.enabled')
270+
.click({ force: true });
271+
272+
// Wait for the delete confirmation modal
273+
cy.wait(1000);
274+
275+
cy.get('button[data-test-subj="confirmModalConfirmButton"]')
276+
.should('exist') // Ensure the button exists
277+
.should('be.visible') // Ensure the button is visible
278+
.click({ force: true });
279+
280+
// Wait for the delete action to complete
281+
cy.wait(1000);
282+
cy.visitDataSourcesListingPage();
283+
});
284+
285+
Cypress.Commands.add('singleDeleteDataSourceByTitle', (dataSourceTitle) => {
286+
cy.visitDataSourcesListingPage();
287+
cy.wait(1000);
288+
cy.contains('a', dataSourceTitle)
289+
.should('exist') // Ensure the anchor tag exists
290+
.invoke('attr', 'href') // Get the href attribute
291+
.then((href) => {
292+
// Extract the unique identifier part from the href
293+
const uniqueId = href.split('/').pop(); // Assumes the unique ID is the last part of the URL
294+
miscUtils.visitPage(
295+
`app/management/opensearch-dashboards/dataSources/${uniqueId}`
296+
);
297+
cy.wait(1000);
298+
cy.getElementByTestId('editDatasourceDeleteIcon').click({ force: true });
299+
});
300+
cy.wait(1000);
301+
cy.get('button[data-test-subj="confirmModalConfirmButton"]')
302+
.should('exist') // Ensure the button exists
303+
.should('be.visible') // Ensure the button is visible
304+
.click({ force: true }); // Click the button
305+
cy.wait(1000);
306+
cy.visitDataSourcesListingPage();
307+
});
308+
309+
Cypress.Commands.add('deleteAllDataSourcesOnUI', () => {
310+
cy.visitDataSourcesListingPage();
311+
cy.wait(1000);
312+
313+
// Clean all data sources
314+
// check if checkboxSelectAll input exist
315+
// if exist, check it and delete all
316+
// for test purpose, no need to consider pagination
317+
// we can use both deleteAll on UI and request part
318+
cy.ifElementExists('[data-test-subj="checkboxSelectAll"]', () => {
319+
// Your logic when the element exists
320+
cy.getElementByTestId('checkboxSelectAll')
321+
.should('exist')
322+
.check({ force: true });
323+
// Add any additional actions you want to perform
324+
cy.getElementByTestId('deleteDataSourceConnections')
325+
.should('exist')
326+
.should('be.enabled')
327+
.click({ force: true });
328+
cy.getElementByTestId('confirmModalConfirmButton')
329+
.should('exist') // Ensure the button exists
330+
.should('be.visible') // Ensure the button is visible
331+
.click({ force: true });
332+
});
333+
// after delete all data sources, the selectAll input should not exist
334+
cy.getElementByTestId('checkboxSelectAll').should('not.exist');
335+
});
336+
337+
const isValidUUID = (str) => {
338+
const uuidRegex =
339+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
340+
return uuidRegex.test(str);
341+
};
342+
343+
Cypress.Commands.add('ifElementExists', (selector, callback) => {
344+
cy.get('body').then(($body) => {
345+
if ($body.find(selector).length) {
346+
// Element exists, call the callback
347+
callback();
348+
}
349+
});
350+
});

0 commit comments

Comments
 (0)