@@ -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 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - 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