Bug 1328219 - (Part 1) Add element ID and events for testing draft
authorScott Wu <scottcwwu@gmail.com>
Thu, 26 Jan 2017 14:51:11 +0800
changeset 466625 056c82cde3a0365ae2ad5e33d64da8d956a7b096
parent 464862 d5e37c0a776f1f2c21ddac4612529f819e13733b
child 466626 f9862cad3ec2201f0589fe99a7c0395a56f1e1dc
push id42943
push userbmo:scwwu@mozilla.com
push dateThu, 26 Jan 2017 06:53:39 +0000
bugs1328219
milestone53.0a1
Bug 1328219 - (Part 1) Add element ID and events for testing MozReview-Commit-ID: LER4YBOI9RX
toolkit/content/widgets/datepicker.js
toolkit/content/widgets/spinner.js
--- a/toolkit/content/widgets/datepicker.js
+++ b/toolkit/content/widgets/datepicker.js
@@ -232,16 +232,17 @@ function DatePicker(context) {
     handleMessage(event) {
       switch (event.data.name) {
         case "PickerSetValue": {
           this.set(event.data.detail);
           break;
         }
         case "PickerInit": {
           this.init(event.data.detail);
+          document.dispatchEvent(new CustomEvent("PickerReady"));
           break;
         }
       }
     },
 
     /**
      * Set the date state and update the components with the new state.
      *
@@ -289,24 +290,26 @@ function DatePicker(context) {
     const yearFormat = new Intl.DateTimeFormat(options.locale, { year: "numeric" }).format;
     const dateFormat = new Intl.DateTimeFormat(options.locale, { year: "numeric", month: "long" }).format;
 
     this.context = context;
     this.state = { dateFormat };
     this.props = {};
     this.components = {
       month: new Spinner({
+        id: "month",
         setValue: month => {
           this.state.isMonthSet = true;
           options.setMonth(month);
         },
         getDisplayString: month => monthFormat(new Date(0, month)),
         viewportSize: spinnerSize
       }, context.monthYearView),
       year: new Spinner({
+        id: "year",
         setValue: year => {
           this.state.isYearSet = true;
           options.setYear(year);
         },
         getDisplayString: year => yearFormat(new Date(new Date(0).setFullYear(year))),
         viewportSize: spinnerSize
       }, context.monthYearView)
     };
--- a/toolkit/content/widgets/spinner.js
+++ b/toolkit/content/widgets/spinner.js
@@ -37,17 +37,17 @@ function Spinner(props, context) {
      *             as localized strings.
      *           {Number} viewportSize [optional]: Number of items in a
      *             viewport.
      *           {Boolean} hideButtons [optional]: Hide up & down buttons
      *           {Number} rootFontSize [optional]: Used to support zoom in/out
      *         }
      */
     _init(props) {
-      const { setValue, getDisplayString, hideButtons, rootFontSize = 10 } = props;
+      const { id, setValue, getDisplayString, hideButtons, rootFontSize = 10 } = props;
 
       const spinnerTemplate = document.getElementById("spinner-template");
       const spinnerElement = document.importNode(spinnerTemplate.content, true);
 
       // Make sure viewportSize is an odd number because we want to have the selected
       // item in the center. If it's an even number, use the default size instead.
       const viewportSize = props.viewportSize % 2 ? props.viewportSize : VIEWPORT_SIZE;
 
@@ -70,16 +70,17 @@ function Spinner(props, context) {
         itemsViewElements: []
       };
 
       this.elements.spinner.style.height = (ITEM_HEIGHT * viewportSize) + "rem";
 
       if (hideButtons) {
         this.elements.container.classList.add("hide-buttons");
       }
+      this.elements.container.id = id;
 
       this.context.appendChild(spinnerElement);
       this._attachEventListeners();
     },
 
     /**
      * Only the parent component calls setState on the spinner.
      * It checks if the items have changed and updates the spinner.