@@ -242,52 +242,66 @@ describe('Transforms', () => {
242242 // Confirm we have our initial transform
243243 cy . contains ( TRANSFORM_ID ) ;
244244
245- // Intercept different transform requests endpoints to wait before clicking disable and enable buttons
246- cy . intercept ( `/api/ism/transforms/${ TRANSFORM_ID } ` ) . as ( 'getTransform' ) ;
247- cy . intercept ( `/api/ism/transforms/${ TRANSFORM_ID } /_stop` ) . as (
248- 'stopTransform'
249- ) ;
250-
251245 // Click into transform job details page
252246 cy . get ( `[data-test-subj="transformLink_${ TRANSFORM_ID } "]` ) . click ( {
253247 force : true ,
254248 } ) ;
255249
256250 cy . contains ( `${ TRANSFORM_ID } ` ) ;
257251
258- /* Wait required for page data to load, otherwise "Disable" button will
259- * appear greyed out and unavailable. Cypress automatically retries,
260- * but only after menu is open, doesn't re-render.
261- */
262- cy . wait ( '@getTransform' ) . wait ( 2000 ) ;
252+ /* Wait required for page data to load */
253+ cy . wait ( 1000 ) ;
263254
264255 // Click into Actions menu
265256 cy . get ( `[data-test-subj="actionButton"]` ) . click ( { force : true } ) ;
266257
267- // Click Disable button
268- cy . get ( `[data-test-subj="disableButton"]` )
269- . should ( 'not.be.disabled' )
270- . click ( ) ;
271-
272- cy . wait ( '@stopTransform' ) ;
273- cy . wait ( '@getTransform' ) ;
274-
275- // Confirm we get toaster saying transform job is disabled
276- cy . contains ( `"${ TRANSFORM_ID } " is disabled` ) ;
277-
278- // Extra wait required for page data to load, otherwise "Enable" button will be disabled
279- cy . wait ( 2000 ) ;
280-
281- // Click into Actions menu
282- cy . get ( `[data-test-subj="actionButton"]` ) . click ( { force : true } ) ;
283-
284- // Click Enable button
285- cy . get ( `[data-test-subj="enableButton"]` )
286- . should ( 'not.be.disabled' )
287- . click ( { force : true } ) ;
288-
289- // Confirm we get toaster saying transform job is enabled
290- cy . contains ( `"${ TRANSFORM_ID } " is enabled` ) ;
258+ // Check which action is available (enable or disable)
259+ cy . get (
260+ '[data-test-subj="enableButton"], [data-test-subj="disableButton"]'
261+ ) . then ( ( $buttons ) => {
262+ const enableButton = $buttons . filter (
263+ '[data-test-subj="enableButton"]:not([disabled])'
264+ ) ;
265+ const disableButton = $buttons . filter (
266+ '[data-test-subj="disableButton"]:not([disabled])'
267+ ) ;
268+
269+ if ( disableButton . length ) {
270+ // If disable button is enabled, means transform is currently enabled
271+ cy . get ( '[data-test-subj="disableButton"]' )
272+ . should ( 'not.be.disabled' )
273+ . click ( ) ;
274+ cy . contains ( `"${ TRANSFORM_ID } " is disabled` ) ;
275+
276+ cy . wait ( 1000 ) ;
277+
278+ // Click into Actions menu again
279+ cy . get ( `[data-test-subj="actionButton"]` ) . click ( { force : true } ) ;
280+
281+ // Then enable it
282+ cy . get ( '[data-test-subj="enableButton"]' )
283+ . should ( 'not.be.disabled' )
284+ . click ( { force : true } ) ;
285+ cy . contains ( `"${ TRANSFORM_ID } " is enabled` ) ;
286+ } else if ( enableButton . length ) {
287+ // If enable button is enabled, means transform is currently disabled
288+ cy . get ( '[data-test-subj="enableButton"]' )
289+ . should ( 'not.be.disabled' )
290+ . click ( { force : true } ) ;
291+ cy . contains ( `"${ TRANSFORM_ID } " is enabled` ) ;
292+
293+ cy . wait ( 1000 ) ;
294+
295+ // Click into Actions menu again
296+ cy . get ( `[data-test-subj="actionButton"]` ) . click ( { force : true } ) ;
297+
298+ // Then disable it
299+ cy . get ( '[data-test-subj="disableButton"]' )
300+ . should ( 'not.be.disabled' )
301+ . click ( ) ;
302+ cy . contains ( `"${ TRANSFORM_ID } " is disabled` ) ;
303+ }
304+ } ) ;
291305 } ) ;
292306 } ) ;
293307} ) ;
0 commit comments