Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/spec/ui/action-target-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('mod/ui/action-target.mod/spec/action-target-spec');
153 changes: 14 additions & 139 deletions test/spec/ui/button-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,6 @@ describe("test/ui/button-spec", function () {
expect(aButton.label).toEqual("");
});
});
describe("draw", function () {
var aButton;
beforeEach(function () {
aButton = new Button();
aButton.element = MockDOM.element();
});

it("should be requested after enabled state is changed", function () {
aButton.enabled = ! aButton.enabled;
expect(aButton.needsDraw).toBeTruthy();
});
it("should be requested after label is changed", function () {
aButton.label = "random";
expect(aButton.needsDraw).toBeTruthy();
});
it("should be requested after label is changed", function () {
aButton.active = true;
expect(aButton.needsDraw).toBeTruthy();
});
it("should be requested after label is changed", function () {
aButton.preventFocus = true;
expect(aButton.needsDraw).toBeTruthy();
});
});
describe("disabled property", function () {
var aButton;
beforeEach(function () {
aButton = new Button();
aButton.element = MockDOM.element();
aButton.originalElement = aButton.element;
});
it("should be enabled after the corresponding property change", function () {
aButton.enabled = true;
aButton.enterDocument(true);
aButton._draw();
aButton.draw();
expect(aButton.element.disabled).toBeFalsy();
});
it("should be disabled after the corresponding property change", function () {
aButton.enabled = false;
aButton.enterDocument(true);
aButton._draw();
aButton.draw();
expect(aButton.element.disabled).toBeTruthy();
});
});
describe("active target", function () {
var aButton, anElement;
beforeEach(function () {
Expand Down Expand Up @@ -104,108 +58,29 @@ describe("test/ui/button-spec", function () {
expect(anElement.setAttribute).not.toHaveBeenCalledWith("tabindex", "-1");
});
});

describe("converter", function () {
describe("draw", function () {
var aButton;
beforeEach(function () {
aButton = new Button();
aButton.element = MockDOM.element();
aButton.originalElement = aButton.element;
aButton.element.firstChild = MockDOM.element();
aButton.converter = {
convert: function (v) {
return v.replace(/fail/gi, "pass");
}
};
});
it("shouldn't go into infinite loop", function () {
aButton.label = "fail";
aButton.enterDocument(true);
aButton.draw();
aButton.label = "FAIL";
expect(aButton.label).toEqual("pass");
});
});

describe("events", function () {
var aButton, anElement, listener;
beforeEach(function () {
aButton = new Button();
anElement = MockDOM.element();
listener = {
handleEvent: function () {}
}
it("should be requested after enabled state is changed", function () {
aButton.enabled = ! aButton.enabled;
expect(aButton.needsDraw).toBeTruthy();
});
it("should listen for pressStart only after prepareForActivationEvents", function () {
var listeners,
em = aButton.eventManager;

listeners = em.registeredEventListenersForEventType_onTarget_("pressStart", aButton._pressComposer);
expect(listeners).toBeNull();

aButton.prepareForActivationEvents();

listeners = em.registeredEventListenersForEventType_onTarget_("pressStart", aButton._pressComposer);
expect(listeners).toEqual(aButton);
it("should be requested after label is changed", function () {
aButton.label = "random";
expect(aButton.needsDraw).toBeTruthy();
});
it("should listen for longPress on PressComposer on demand", function () {
var listeners,
em = aButton.eventManager;

listeners = em.registeredEventListenersForEventType_onTarget_("longPress", aButton._pressComposer);
expect(listeners).toBeNull();

aButton.addEventListener("longAction", listener, false);

listeners = em.registeredEventListenersForEventType_onTarget_("longPress", aButton._pressComposer);
expect(listeners).toEqual(aButton);
it("should be requested after label is changed", function () {
aButton.active = true;
expect(aButton.needsDraw).toBeTruthy();
});
it("should fires a 'longAction' event when the PressComposer fires a longPress", function () {
var callback = jasmine.createSpy();
aButton.addEventListener("longAction", callback, false);
aButton._pressComposer.dispatchEventNamed("longPress");
expect(callback).toHaveBeenCalled();
it("should be requested after label is changed", function () {
aButton.preventFocus = true;
expect(aButton.needsDraw).toBeTruthy();
});
describe("once prepareForActivationEvents is called", function () {
beforeEach(function () {
aButton.element = anElement;
aButton.prepareForActivationEvents();
});
it("should fire an 'action' event when the PressComposer fires a pressStart + press", function () {
var callback = jasmine.createSpy().and.callFake(function (event) {
expect(event.type).toEqual("action");
});
aButton.addEventListener("action", callback, false);

aButton._pressComposer.dispatchEventNamed("pressStart");
aButton._pressComposer.dispatchEventNamed("press");

expect(callback).toHaveBeenCalled();
});
it("shouldn't fire an 'action' event when the PressComposer fires a pressStart + pressCancel", function () {
var callback = jasmine.createSpy().and.callFake(function (event) {
expect(event.type).toEqual("action");
});
aButton.addEventListener("action", callback, false);

aButton._pressComposer.dispatchEventNamed("pressStart");
aButton._pressComposer.dispatchEventNamed("pressCancel");

expect(callback).not.toHaveBeenCalled();
});
it("should fire an 'action' event with the contents of the detail property", function () {
var callback = jasmine.createSpy().and.callFake(function (event) {
expect(event.detail.get("foo")).toEqual("bar");
});
aButton.addEventListener("action", callback, false);

aButton.detail.set("foo", "bar");

aButton._pressComposer.dispatchEventNamed("pressStart");
aButton._pressComposer.dispatchEventNamed("press");

expect(callback).toHaveBeenCalled();
});
});
});
});
describe("objectDescriptor", function () {
Expand Down
Loading