What is the best way to make cypress.io swipe an ionic ion-item-sliding component to the left?

I am currently working on a small ionic 4 (vue) app that includes an ion-list with ion-item-sliding. Here is a snippet of the code:

HTML

<ion-item-sliding v-for="day in month.days" v-bind:key="day.day">
    <ion-item
      :id="'times-item-'+day.day+'-'+month.name.toLowerCase()+'-'+month.year"
      @click="openAddEditModal(day)"
    >
      <ion-grid>
        <ion-row>
          <ion-col size="4">
            <ion-label :color="switchLabelColor(day)">
              <div id="times-item-day-weekday">{{ day.weekday }}.</div>
              <div id="times-item-day-day" class="bigger">
                {{ day.day }}
              </div>
            </ion-label>
          </ion-col>

          <ion-col size="4" v-if="getDayEntry(day)">
            <ion-text
              id="times-item-start-end-time"
              v-if="isWork(getDayEntry(day).type)"
            >
              {{ formatTime(getDayEntry(day).start) }} -
              {{ formatTime(getDayEntry(day).end) }}
            </ion-text>
          </ion-col>

          <ion-col
            id="times-item-stats"
            size="4"
            class="ion-text-end"
            v-if="getDayEntry(day)"
          >
            {{ formatDuration(getDayEntry(day).worktime) }}<br />
            <ion-text
              id="times-item-overtime"
              :color="switchOvertimeColor(getDayEntry(day).overtime)"
              >{{ getDayEntry(day).overtime.toString() }}</ion-text
            >
          </ion-col>
        </ion-row>
      </ion-grid>
    </ion-item>
    <ion-item-options side="end">
      <ion-item-option
        id="times-item-delete-button"
        v-if="day.entry"
        ion-item-option
        color="danger"
        expandable
        @click="deleteEntryForDay(day)"
        >Delete</ion-item-option
      >
    </ion-item-options>
  </ion-item-sliding>

While testing the app with cypress.io, I encountered difficulties trying to swipe the ion-item-sliding component to the left side.

I experimented with various mouse events such as down, move, up, and pointer on both the ion-item-sliding and ion-item. I also tried touch events but none of them worked.

The last test script I attempted was this:

test typescript

it("Delete today entry", () => {
    //GIVEN
    const today = new Date();
    const todayString: string = createItemSelectorTextForDate(today);

    //WHEN
    cy.get("#times-item-"+todayString)
    .trigger('mousedown', {force: true})
    .trigger('mousemove', {clientX: -80, force: true})
    .trigger('mouseup', {force: true});
})

If anyone knows how to make cypress.io work with Ionic components, please share your insights!

Answer №1

I encountered a similar issue with ion-item-sliding, and despite experimenting with various mouse, pointer, and touch events, I couldn't find a solution. However, I eventually discovered two methods to successfully click the hidden button.

First Approach

The quicker option is to directly click the concealed button:

 cy.get('ion-item-sliding.item-wrapper')
    .find('button[color="danger"]')
    .click({force:true});

This action bypasses the animation, rendering the slider and button invisible but still triggering the button's function.

Second Method

Create the animation manually. When swiping in ion-item-sliding, certain classes and styles are added dynamically. Implement this using Cypress:

cy.get('ion-item-sliding.item-wrapper')
   .invoke('addClass', 'active-slide active-options-right')
   .find('.item')
   .invoke('attr', 'style', 'transform: translate3d(-184px, 0px, 0px);')

The provided code pertains to Ionic 3; for newer versions, simply adjust the classes accordingly.

Latest Ionic Version

Tested using the most recent sample code available

cy.get('ion-item-sliding')
    .invoke('addClass', 'item-sliding-active-slide item-sliding-active-options-end')
    .find('.item')
    .invoke('attr', 'style', 'transform: translate3d(-72px, 0px, 0px);')

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

Struggling to retrieve cookie information within a Vue.js and Laravel project

As I develop an API for a Laravel 6 application located at example.com/api, alongside a Vue frontend situated at example.com, I encounter an issue with accessing the authentication cookie in my vue.js app. Despite successfully setting the cookie on user au ...

Issue encountered during Nuxt installation: A rule can only contain one resource source, which consists of the provided resource and the test + include + exclude

After successfully installing Vue.js and Node.js, I encountered an issue while trying to install Nuxt.js. Here is the error message that I received. Despite asking for help from friends, the problem still persists. Any assistance would be greatly appreciat ...

Utilize ES6 lodash to map the keys of an object fetched from an API

Currently, I am utilizing Vue 3 to send POST data to my API. The structure of the objects is as follows: const externalResults: ref(null) const resource = ref({ id: null, name: null, state: {} }) Prior to sending the data to the API, I am modifying ...

Deactivating the drag feature when setting the duration of a new event in FullCalendar

Hello there! I've integrated full calendar into my Angular project and I'm facing a challenge. I want to restrict users from defining the duration of an event by holding click on an empty schedule in the weekly calendar, where each date interval ...

The parameter type 'typeof LogoAvatar' cannot be assigned to the argument type 'ComponentType<LogoProps & Partial<WithTheme>'

Why is the argument of type typeof LogoAvatar not assignable to a parameter of type ComponentType<LogoProps & Partial<WithTheme>? Here is the code snippet: import * as React from "react"; import { withStyles } from "@material-ui/core/style ...

Ensure to trigger the Ajax function prior to the tab change event in a Vue form wizard

I'm currently utilizing the Vue wizard from https://www.npmjs.com/package/vue-form-wizard and I need to trigger an AJAX function before the tab change event like so: beforeTabSwitch: function(tab){ if(tab===2) { this.formData .post(APP_URL ...

Grouping items by a key in Vue and creating a chart to visualize similarities among those keys

I am working with an object that has the following structure; { SensorA: [ { id: 122, valueA: 345, "x-axis": 123344 }, { id: 123, valueA: 125, "x-axis": 123344 }, { id: 123, valueA: 185, "x-axis": 123344 }, { ...

Please anticipate the reply from the AngularJS 2 API

I want to insert a token into a cookie, but the issue is that the cookie is created before receiving the API response. How can I make sure to wait for the response before creating the cookie? My Implementation: getLogin() { this._symfonyService.logi ...

Obtaining the value of dynamic checkboxes in Ionic 2

My goal is to populate checkboxes from a database and allow users to complete the checkbox form before submitting it back to the database. However, I am struggling to capture the values of dynamically populated checkboxes in my code snippet below. expor ...

The checkbox column in vuetify does not have sorting implemented

I need assistance with creating a row of check-boxes within a vuetify data table. Although I successfully implemented this feature, the sorting functionality does not seem to work for this specific column. Feel free to view this demo showcasing the issue: ...

Tips on dynamically translating resources using ngx-translate

Can anyone help me with ngx-translate? I'm struggling to figure out how to dynamically translate resources in HTML. Here's an example: "agreement.status.0": "New", "agreement.status.1": "Rejected", ...

Setting a default value for a null Select Option in React: a guide

I am currently working with an array of values and looping through them to display in a Select Option. <Form.Item label="Status"> <Select value={user.status} onChange={handleStatusChange} > ...

Trouble arises when trying to use Kendo-UI's Edit template alongside Vue's Single File Component

Utilizing the Kendoui grid Vue wrapper, I discovered in the Kendoui Vue documentation that a single file Component can be used for Kendo templates. Currently, I am working on an editable grid with a popup editor. In my attempt to set the "editable" propert ...

Is there a way to refresh my list following a POST request when utilizing a separate endpoint?

I'm struggling with updating my list after a POST request. I haven't been able to find any solutions online. Typically, I would just push an object into an array, but it seems different in this case. This function utilizes 2 API endpoints. The f ...

There are several InputBase elements nested within a FormControl

There seems to be an issue: Material-UI: It appears that there are multiple InputBase components within a FormControl, which is not supported. This could potentially lead to infinite rendering loops. Please only use one InputBase component. I understand ...

Having trouble with `npm run watch` stopping after compiling once on Laravel 8 Homestead with Vue integration?

Every time I use npm run watch, it successfully compiles my changes and updates the pages. However, after making subsequent edits, it stops updating the page without any errors showing up. Restarting npm run watch resolves this issue, indicating that it ma ...

Is it possible to dynamically close the parent modal based on input from the child component?

As I follow a tutorial, I am working on importing the stripe function from two js files. The goal is to display my stripe payment in a modal. However, I am unsure how to close the modal once I receive a successful payment message in the child. Below are s ...

Receiving a 500 (Internal Server Error) in AngularJS when making a $http POST request

Being a novice in the world of Ionic and Angular, I am currently working on a project using the Ionic framework with Angular.js. My goal is to make a WebApi call using the $http post method. I have referred to the solution provided in this ionic-proxy-exam ...

Having trouble with the active class in vue-router when the route path includes "employees/add"?

I'm currently developing a project using Vue and implementing vue-router for navigation. A peculiar behavior occurs when the route changes to /employees - only the Employees menu item is activated. However, when the route switches to /employees/add, b ...

How can we programmatically add click handlers in Vue.js?

Currently attempting to add some computed methods to an element based on mobile viewports exclusively. Here is a simplified version of my current project: <a class="nav-link float-left p-x-y-16" v-bind:class={active:isCurrentTopicId(t.id)} @click="onTo ...