Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

MozMill Testing

For general Mozmill knowledge see en/Mozmill_Tests first.

Event creation test using CalendarUtils

Before you go on to read CalendarUtils reference you can try it out with the following example test. In order to do that save the code next to shared-modules folder in calendar/test/mozmill in your local comm-central repository.

var RELATIVE_ROOT = './shared-modules';
var MODULE_REQUIRES = ['CalendarUtils'];

var sleep = 500;

var setupModule = function(module) {
  controller = mozmill.getMail3PaneController();
}

var testCreateEvent = function () {
  // making sure day view is active
  CalendarUtils.switchToView("day", controller);
 
  // click at 10 am
  controller.doubleClick(new elementslib.Lookup(controller.window.document,
    CalendarUtils.getEventBoxPath("day", CalendarUtils.CANVAS_BOX, undefined, 1, 10, controller)));
  controller.waitForEval('utils.getWindows("Calendar:EventDialog").length > 0', sleep);
  let event = new mozmill.controller.MozMillController(mozmill.utils
    .getWindows("Calendar:EventDialog")[0]);
  // waiting for event dialog
  event.sleep(sleep);
 
  // give it title
  CalendarUtils.setData({title: "Mozmill event", reminder: 0}, event);
 
  // save it
  event.click(new elementslib.ID(event.window.document, "button-save"));
  controller.sleep(sleep);
 
  let box = CalendarUtils.getEventBoxPath("day", CalendarUtils.EVENT_BOX, undefined, 1, 10, controller)
    + '/{"tooltip":"itemTooltip"}';
 
  // make sure it was added to view
  controller.assertNode(new elementslib.Lookup(controller.window.document, box));
 
  // delete event
  controller.click(new elementslib.Lookup(controller.window.document, box));
  controller.keypress(new elementslib.ID(controller.window.document, "day-view"), "VK_DELETE", {});
  controller.sleep(sleep);
 
  // verify that it was deleted
  controller.assertNodeNotExist(new elementslib.Lookup(controller.window.document, box));
}

Then load it into Mozmill IDE and run!

Note that this test only depends on CalendarUtils module, whenever you need to interact with modal dialogs (the ones that steal focus from every other Thunderbird window you have open) you need ModalDialogAPI from QA test repository. Just copy it from there into calendar shared-modules folder and add a reference to MODULE_REQUIRES. You may also find other modules in there useful for your calendar tests.

Utility functions

acceptSendingNotificationMail

CalendarUtils.acceptNotificationMail();

Sets Mozmill up to click OK in the dialog asking if you want to notify attendees of a new or changed event. Call before saving an event with attendees.

handleAddingAttachment

CalendarUtils.handleAddingAttachment(url);

Example:
CalendarUtils.handleAddingAttachment("https://mozilla.org");

Sets Mozmill up to enter an url in attachment dialog. Triggering the dialog itself either using a button or a menu option is needed afterwards.

handleOccurrenceDeletion

CalendarUtils.handleOccurrenceDeletion(attendees);

Example:
CalendarUtils.handleOccurrenceDeletion(true); 

Sets Mozmill up to handle event deletion. Chooses to delete a specific occurrence of a repeating event and depending on argument value either notifies attendees or not if there are attendees. You only need this if you're interacting with a repeating event. To trigger event deletion dialog you can send VK_DELETE to event.

handleParentDeletion

CalendarUtils.handleParentDeletion(attendees);

Example:
CalendarUtils.handleParentDeletion(true);

Sets Mozmill up to handle event deletion. Chooses to delete all occurrences of a repeating event and depending on argument value either notifies attendees or not if there are attendees. You only need this if you're interacting with a repeating event. To trigger event deletion dialog you can send VK_DELETE to event.

handleOccurrenceModification

CalendarUtils.handleOccurrenceModification(attendees);

Example:
CalendarUtils.handleOccurrenceModification(true);

Sets Mozmill up to handle event modification. Chooses to modify a specific occurrence of a repeating event and depending on argument value either notifies attendees or not if there are attendees. You only need this if you're interacting with a repeating event. To trigger event modification dialog you need to open repeating event using doubleclick.

handleParentModification

CalendarUtils.handleParentModification(attendees);

Example:
CalendarUtils.handleParentModification(true);

Sets Mozmill up to handle event modification. Chooses to modify all occurrences of a repeating event and depending on argument value either notifies attendees or not if there are attendees. You only need this if you're interacting with a repeating event. To trigger event modification dialog you need to open repeating event using doubleclick.

switchToView

CalendarUtils.switchToView(view, controller);

Example:
CalendarUtils.switchToView("day", controller);  // other valid options: week, multiweek, month

Switches main calendar view to a single day, week, multiple weeks or month.

goToDate

CalendarUtils.goToDate(year, month, day, controller);

Example:
CalendarUtils.goToDate(2010, 1, 1, controller); // 1st January 2010

Changes active day using minimonth calendar.

getEventBoxPath

CalendarUtils.getEventBoxPath(view, option, row, column, hour, controller);

Examples:
// to edit an event at 8am in day view
CalendarUtils.getEventBoxPath("day", CalendarUtils.EVENT_BOX, undefined, 1, 8, controller);
// the create/edit allday event on third day of the week in week view
CalendarUtils.getEventBoxPath("week", CalendarUtils.ALLDAY, undefined, 3, undefined, controller);
// to create event on third day in the second row in month view
CalendarUtils.getEventBoxPath("month", CalendarUtils.CANVAS_BOX, 2, 3, undefined, controller);

Lookup expressions for events in view aren't pretty, this is a helper function to get most of the needed path. You need to add the last level yourself, for example to get a full lookup string for event in calendar named Mozmill you'd use

CalendarUtils.getEventBoxPath("month", CalendarUtils.EVENT_BOX, 2, 3, undefined, controller)
  + '/{"tooltip":"itemTooltip","calendar":"Mozmill"}';

It will work for events that are the only events on a given hour (day and week views) or day (multiweek and month views). In cases when view layout is more complicated there's no good way to abstract expressions as it depends on the exact timing of events. For creating a new event you need canvas box, for editing an existing one you need event box. Allday only applies to day and week views where there's a special area at the top for such events.

forward

CalendarUtils.forward(n);

Example:
CalendarUtils.forward(2); // go forward 2 days, 2 weeks or 2 months depending on active view

back

CalendarUtils.back(n);

Example:
CalendarUtils.back(3); // go back 3 days, 3 weeks or 3 months depending on active view

deleteCalendars

CalendarUtils.deleteCalendars(calendar);

Example:
CalendarUtils.deleteCalendars("Mozmill");

Deletes all calendars with given name. Useful for cleanup at the end of test.

createCalendar

CalendarUtils.createCalendar(calendar);

Example:
CalendarUtils.createCalendar("Mozmill");

Creates new local calendar with given name and selects it in calendar list. Useful for test setup.

setData

setData(data, event);

Example:
setData({title: "title", location: "location", description: "description"}, eventDialogController);

Other attributes you can specify:

  • category (string) - category label
  • allday (boolean)
  • startdate, starttime, enddate, enddate (Date objects)
  • repeat (one of none/daily/weekly/every.weekday/bi.weekly/monthly/yearly/custom)
  • timezone (boolean, true for calendar default timezone, false for local time)
  • reminder (integer) - option index
  • priority (one of none/low/normal/high)
  • privacy (one of public/confidential/private
  • status (one of none/tentative/confirmed/cancelled
  • freebusy (one of free/busy
  • attachment.add (string)
  • attachment.remove (string)

Note that while most replace previous values, attachment.add and attachment.remove modify attachment list, so that after two attachment.add's you'll have two attachments.

findEventsInNode

 CalendarUtils.findEventsInNode(node, eventNodes);

Retrieve all xul nodes named calendar-event-box inside parent node.

  • node - parent xul node, you can get it from an elementslib object using getNode()
  • eventNodes - xul nodes found are saved as an array into variable passed in

Useful when you want to do more complex assertions regarding events' positions (for example verify that no overlapping eventboxes are present) and need to retrieve all events in view.

Document Tags and Contributors

Tags: 
 Contributors to this page: fscholz, Sheppy, merike
 Last updated by: fscholz,