search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Drag n drop using cypress for e2e tests

Asked by Yiannis
2 years ago.

I want to write e2e tests in cypress but I can't simulate the drag n drop function in daypilot. This is because the entire calendar is covered in a div that does not let the rest of the elements to be used.

I tried with {force:true} in cypress but nothing happens.

Answer posted by Dan Letecky [DayPilot]
2 years ago.

Cypress isn't particularly good at detecting the layers correctly and this error message ("trigger failed because this element is covered by another element") is often misleading. Adding {force: true} helps to overcome this.

Try this test - I guess you might be missing the "{button: 0}" param when trigerring the "mousedown" event.

/// <reference types="cypress" />

describe('event drag and drop test', () => {
  beforeEach(() => {
    cy.visit('https://javascript.daypilot.org/demo/scheduler/index.html')
  });

  it('moves event', () => {
    cy.window().then((win) => {
      
      var dp = win.dp;
      
      dp.scrollTo("2021-01-01");
      dp.events.add({
        id: 123,
        text: "My Event",
        start: "2021-01-01",
        end: "2021-01-10",
        resource: "A",
        cssClass: "myevent"
      });
      
      cy.get('.myevent').first().should('have.text', 'My Event');
      
      const ev = cy.get(".myevent").first();
      
      ev.trigger('mousemove', 15, 15);
      ev.trigger('mousedown', 15, 15, {button: 0});
      ev.trigger('mousemove', 440, 80, {force: true});
      ev.trigger('mouseup');
     
    });

  });

});
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.