Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Fullcalendar: trigger a "create" event using Capybara

I want to trigger a "create" event in jQuery Fullcalendar using Capybara, but I don't know which element to click. I'm not sure whether this is possible with Capybara anyway...

like image 206
Joshua Muheim Avatar asked Sep 11 '26 20:09

Joshua Muheim


1 Answers

I've created a demo where if a user clicks on a calendar day a new calendar event is created.

See the dayclick callback code:

dayClick: function(date, allDay, jsEvent, view) {
    if (allDay) {
        alert('Clicked on the entire day: ' + date);
    }else{
        alert('Clicked on the slot: ' + date);
    }

    // change the day's background to highlight the fact that its been clicked
    $(this).css('background-color', 'red');

    // Create a new event for the day that was clicked
    var myEvent = {
      title:"my new event",
      allDay: true,
      start: date,
      end: date
    };
    cal.fullCalendar( 'renderEvent', myEvent );
}

You can then click on a date in jQuery Fullcalendar (which will trigger the creation of a new event when the above code is in place) using Capybara as follows:

page.find(:css, "td[data-date='2013-11-06']").click()

Note that you'll need to tailor the CSS to choose exactly which FullCalendar day (i.e. TD element) to click, but this is just an example.

See the Caybara documentation here for how to do this.

like image 77
Ben Smith Avatar answered Sep 17 '26 07:09

Ben Smith