Unable to minimize or hide the ace editor widget with Cypress

Today marks the beginning of my journey into posting on this platform, and I am eager to get it right.

In my current project using Cypress for writing integration tests, I encountered a challenge while attempting to click on an Ace editor widget within a React application. The widget is nested inside a span element with a class attribute like "ace_fold-widget ace_start ace_open". Manually clicking on the widget changes the class to "ace_fold-widget ace_start ace_closed".

Despite multiple attempts to interact with the element in different ways, I have not been able to trigger the desired response from it. This issue seems unique as I couldn't find any helpful solutions online.

Various methods were tried:

cy.get('Ace widget element').click() (force option tested as well)

 cy.get('Ace widget element').invoke('have.class', 'ace_fold-widget ace_start ace_closed').trigger('change')

 cy.get('Ace widget element').trigger('mousedown')

 cy.get('Ace widget element').trigger('click')

 cy.get('Ace widget element').trigger('changeFold') (identified changeFold as the relevant event)

Additionally, plain JS was also utilized:

cy.get('Ace widget element').then(function($input) {
    $input[0].setAttribute('test', 'my new value')
  })
  .should('have.attr', 'test', 'my new value')

Please note that 'Ace widget element' is merely an example placeholder. The correct locator is used in practice.

The observed behavior included the element visually appearing folded with the arrow image, along with the alteration in class attributes; however, the rows did not actually fold. Even after trying to chain various triggers, no successful outcome was achieved. Subsequently, the element reverted back to its initial state.

Attempts to interact with the parent element or trigger its 'changeFold' event had equally futile results.

The structure of the DOM is depicted below:

Your assistance in resolving this matter would be greatly appreciated.

Answer №1

Utilizing the class names enables the selection of various sections of the widget, such as clicking on the top fold button.

As a result, the folded text is removed from the DOM, indicating that one of the code lines is initially visible and then missing after the click event.

// this line inside the fold button should disappear

cy.contains('.ace_line', 'for (var i=0; i<items.length; i++) {')
  .should('be.visible')                                            

// This method may not be refined, but it correctly locates the first fold button in the hierarchy of the gutter control

cy.get('.ace_gutter')
  .find('.ace_layer.ace_gutter-layer.ace_folding-enabled')
  .find('.ace_gutter-cell')
  .find('.ace_fold-widget')
  .eq(0)
  .click()

// confirm that the code line has disappeared

cy.contains('.ace_line', 'for (var i=0; i<items.length; i++) {')
  .should('not.exist')

Inner fold buttons

Clicking the inner fold (located on line #2) can be slightly challenging due to the impact of scrollBehavior on its functionality.

It's important to note that I'm conducting tests with visible gutter indexes.

// disabling scrollBehavior to click the inner fold button
Cypress.config('scrollBehavior', false)

// checking if the target line is visible
cy.contains('.ace_line', 'alert(items[i]').should('be.visible')

// clicking on the 2nd fold button
cy.contains('.ace_gutter-cell', '2')           // indicates the gutter index
  .find('.ace_fold-widget')
  .click()

// confirming that the target line has vanished
cy.contains('.ace_line', 'alert(items[i]').should('not.exist')

// ensuring that the for-loop line still exists and is visible
cy.contains('.ace_line', 'for (var i=0; i<items.length; i++) {')
  .should('exist')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React: Component rendering unsuccessful

Hey everyone, I’m a beginner in React and having trouble trying to render my component into the app component. Here is the code: conditionalView.js: import React, { Component } from 'react' export class conditionalView extends Component { ...

What is the method for reverting style properties back to their CSS defaults using Javascript?

The php-generated page contains multiple elements structured like this: <td class="defaultTDStyle" style="color:userDefinedCustomColor" id="myTDId"></td> There is a default style in place with additional styles ap ...

Add a npm module without type definitions

I am currently utilizing Typescript version 2.1 and facing an issue with installing an npm package called 'reactable' that lacks typings. When attempting to import the package using import * as Reactable from 'reactable', Typescript di ...

Using Javascript closures for managing asynchronous Ajax requests within for loops

Let's consider the arrays provided below. var clients = ['a','b']; var reports = ['x','y','z']; var finalData = []; Now, I aim to iterate through them in a specific manner as shown. for(var i=0;i< ...

What is the best way to pass a generic interface to the zustand create function in a TypeScript environment

Having trouble figuring out the right syntax to pass a generic interface when calling a function that accepts a generic type. My goal is to use: const data = itemStore<T>(state => state.data) import { create } from "zustand"; interface ...

Is there a significant distinction between value and defaultValue in React JS?

React's homepage features the final illustration (A Component Using External Plugins) with a textarea: <textarea id="markdown-content" onChange={this.handleChange} defaultValue={this.state.value} /> While typing, the ...

Node.js server experiences a crash after attempting to send a large string using res.send()

I've recently started learning JavaScript and NodeJs. I'm facing an issue with my Nodejs application crashing when a get request is made, specifically when trying to return a large string. app.mjs app.get('/log', function (req, res) { ...

Tips on eliminating overlapping strokes

I'm having trouble with drawing an array of circles that are meant to intersect a series of lines. The issue I face is that if the circles overlap, a stroke appears underneath them which I want to remove. Does anyone have any suggestions on how to el ...

Modify the class name of the clicked button and another button when a button is clicked in ReactJs

I have a React component that displays two buttons. When the user clicks on the left button, it should change the class of both buttons and render the ListView component. Similarly, when the user clicks on the right button, it should change the class of bo ...

Acquiring images from an external source and storing them in either the $lib directory or the static folder during the

Currently, I have a Sveltekit project set up with adapter-static. The content for my pages is being pulled from Directus, and my images are hosted in S3, connected to Directus for easy access. I am also managing audio samples in a similar manner. During b ...

Incorporate Vuetify's v-stepper seamlessly with Vue router for dynamic functionality

Seeking assistance in integrating vuetify's v-stepper with vue router. Specific requirements include: Assigning each step its own route (e.g. /myform/step1, /myform/step2, /myform/step3, etc) Creating components for each step that are dynamically lo ...

Navigating with React-router can sometimes cause confusion when trying

I'm having trouble with my outlet not working in react-router-dom. Everything was fine with my components until I added the Outlet, and now my navigation component isn't showing even though other components are rendering. import Home from ". ...

Utilizing variables in Angular service to make API calls

Currently, I am working on accessing the Google Books API. Initially, I was able to directly access it in my controller but now I want to follow best practices by moving the business logic into a directive. HTML <form ng-submit="search(data)"> < ...

What is causing the issue preventing me from running npm run dev on CentOS 7?

Currently facing an issue while trying to install my application on a new server after migrating from centos6 to centos7. When attempting to install a Laravel app, everything goes smoothly as it did on centos6, except for when I run npm run dev [root@v6-a ...

Increase the bottom padding or add some extra space to the Bootstrap form or page

I am currently working on enhancing a Bootstrap Form that includes reset/submit buttons positioned at the bottom. A common issue is when iPhone users attempt to click the Submit button, which initially displays Safari icons before requiring an extra tap to ...

Verify whether the document includes a class that closely matches the provided string using Javascript

I need help identifying elements that include the letters 'ad'. For example: <iframe class="container" /> <!-- Not relevant --> <a class="adp" /> <!-- Relevant --> <a class="adleft" /> ...

The utility of commander.js demonstrated in a straightforward example: utilizing a single file argument

Many developers rely on the commander npm package for command-line parsing. I am considering using it as well due to its advanced functionality, such as commands, help, and option flags. For my initial program version, I only require commander to parse ar ...

When the Drawer Component Backdrop is open, users will be blocked from interacting with the page

Is there a way to make the Drawer Component anchored at the bottom still interact with the content above it? I've tried using the persistent and permanent variants, but neither of them worked as they prevented any action when clicking outside the draw ...

An error occurred while trying to serialize the `.res` response received from the `getServerSideProps` function in

I encountered the following issue while utilizing the getServerSideProps function to fetch data from Binance API. import binance from "../config/binance-config"; export async function getServerSideProps() { const res = await binance.balance(( ...

Is there a way to modify the style when a different rarity is selected in Next.JS?

Is there a way to change the style depending on the rarity selected? I am currently developing a game that assigns a random rarity upon website loading, and I am looking to customize the color of each rarity. Here is how it appears at the moment: https:/ ...