Merge branch 'master' into open671
This commit is contained in:
@@ -25,20 +25,20 @@ define(
|
||||
function (ClickAwayController) {
|
||||
|
||||
describe("The click-away controller", function () {
|
||||
var mockScope,
|
||||
mockDocument,
|
||||
var mockDocument,
|
||||
mockTimeout,
|
||||
controller;
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
[ "$apply" ]
|
||||
);
|
||||
mockDocument = jasmine.createSpyObj(
|
||||
"$document",
|
||||
[ "on", "off" ]
|
||||
);
|
||||
controller = new ClickAwayController(mockScope, mockDocument);
|
||||
mockTimeout = jasmine.createSpy('timeout');
|
||||
controller = new ClickAwayController(
|
||||
mockDocument,
|
||||
mockTimeout
|
||||
);
|
||||
});
|
||||
|
||||
it("is initially inactive", function () {
|
||||
@@ -77,10 +77,12 @@ define(
|
||||
});
|
||||
|
||||
it("deactivates and detaches listener on document click", function () {
|
||||
var callback;
|
||||
var callback, timeout;
|
||||
controller.setState(true);
|
||||
callback = mockDocument.on.mostRecentCall.args[1];
|
||||
callback();
|
||||
timeout = mockTimeout.mostRecentCall.args[0];
|
||||
timeout();
|
||||
expect(controller.isActive()).toEqual(false);
|
||||
expect(mockDocument.off).toHaveBeenCalledWith("mouseup", callback);
|
||||
});
|
||||
@@ -89,4 +91,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -92,18 +92,18 @@ define(
|
||||
it("exposes start time validator", function () {
|
||||
var testValue = 42000000;
|
||||
mockScope.formModel = { end: testValue };
|
||||
expect(mockScope.validateStart(testValue + 1))
|
||||
expect(controller.validateStart(testValue + 1))
|
||||
.toBe(false);
|
||||
expect(mockScope.validateStart(testValue - 60 * 60 * 1000 - 1))
|
||||
expect(controller.validateStart(testValue - 60 * 60 * 1000 - 1))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it("exposes end time validator", function () {
|
||||
var testValue = 42000000;
|
||||
mockScope.formModel = { start: testValue };
|
||||
expect(mockScope.validateEnd(testValue - 1))
|
||||
expect(controller.validateEnd(testValue - 1))
|
||||
.toBe(false);
|
||||
expect(mockScope.validateEnd(testValue + 60 * 60 * 1000 + 1))
|
||||
expect(controller.validateEnd(testValue + 60 * 60 * 1000 + 1))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
@@ -117,25 +117,87 @@ define(
|
||||
start: DAY * 10000,
|
||||
end: DAY * 11000
|
||||
};
|
||||
// These watches may not exist, but Angular would fire
|
||||
// them if they did.
|
||||
});
|
||||
|
||||
it('updates all changed bounds when requested', function () {
|
||||
fireWatchCollection("formModel", mockScope.formModel);
|
||||
fireWatch("formModel.start", mockScope.formModel.start);
|
||||
fireWatch("formModel.end", mockScope.formModel.end);
|
||||
});
|
||||
|
||||
it("does not immediately make changes to the model", function () {
|
||||
expect(mockScope.ngModel.outer.start)
|
||||
.not.toEqual(mockScope.formModel.start);
|
||||
expect(mockScope.ngModel.inner.start)
|
||||
.not.toEqual(mockScope.formModel.start);
|
||||
|
||||
expect(mockScope.ngModel.outer.end)
|
||||
.not.toEqual(mockScope.formModel.end);
|
||||
expect(mockScope.ngModel.inner.end)
|
||||
.not.toEqual(mockScope.formModel.end);
|
||||
|
||||
controller.updateBoundsFromForm();
|
||||
|
||||
expect(mockScope.ngModel.outer.start)
|
||||
.toEqual(mockScope.formModel.start);
|
||||
expect(mockScope.ngModel.inner.start)
|
||||
.toEqual(mockScope.formModel.start);
|
||||
|
||||
expect(mockScope.ngModel.outer.end)
|
||||
.toEqual(mockScope.formModel.end);
|
||||
expect(mockScope.ngModel.inner.end)
|
||||
.toEqual(mockScope.formModel.end);
|
||||
});
|
||||
|
||||
it('updates changed start bound when requested', function () {
|
||||
fireWatchCollection("formModel", mockScope.formModel);
|
||||
fireWatch("formModel.start", mockScope.formModel.start);
|
||||
|
||||
expect(mockScope.ngModel.outer.start)
|
||||
.not.toEqual(mockScope.formModel.start);
|
||||
expect(mockScope.ngModel.inner.start)
|
||||
.not.toEqual(mockScope.formModel.start);
|
||||
|
||||
expect(mockScope.ngModel.outer.end)
|
||||
.not.toEqual(mockScope.formModel.end);
|
||||
expect(mockScope.ngModel.inner.end)
|
||||
.not.toEqual(mockScope.formModel.end);
|
||||
|
||||
controller.updateBoundsFromForm();
|
||||
|
||||
expect(mockScope.ngModel.outer.start)
|
||||
.toEqual(mockScope.formModel.start);
|
||||
expect(mockScope.ngModel.inner.start)
|
||||
.toEqual(mockScope.formModel.start);
|
||||
|
||||
expect(mockScope.ngModel.outer.end)
|
||||
.not.toEqual(mockScope.formModel.end);
|
||||
expect(mockScope.ngModel.inner.end)
|
||||
.not.toEqual(mockScope.formModel.end);
|
||||
});
|
||||
|
||||
it("updates model bounds on request", function () {
|
||||
mockScope.updateBoundsFromForm();
|
||||
it('updates changed end bound when requested', function () {
|
||||
fireWatchCollection("formModel", mockScope.formModel);
|
||||
fireWatch("formModel.end", mockScope.formModel.end);
|
||||
|
||||
expect(mockScope.ngModel.outer.start)
|
||||
.toEqual(mockScope.formModel.start);
|
||||
.not.toEqual(mockScope.formModel.start);
|
||||
expect(mockScope.ngModel.inner.start)
|
||||
.not.toEqual(mockScope.formModel.start);
|
||||
|
||||
expect(mockScope.ngModel.outer.end)
|
||||
.not.toEqual(mockScope.formModel.end);
|
||||
expect(mockScope.ngModel.inner.end)
|
||||
.not.toEqual(mockScope.formModel.end);
|
||||
|
||||
controller.updateBoundsFromForm();
|
||||
|
||||
expect(mockScope.ngModel.outer.start)
|
||||
.not.toEqual(mockScope.formModel.start);
|
||||
expect(mockScope.ngModel.inner.start)
|
||||
.not.toEqual(mockScope.formModel.start);
|
||||
|
||||
expect(mockScope.ngModel.outer.end)
|
||||
.toEqual(mockScope.formModel.end);
|
||||
expect(mockScope.ngModel.inner.end)
|
||||
.toEqual(mockScope.formModel.end);
|
||||
});
|
||||
});
|
||||
@@ -158,27 +220,27 @@ define(
|
||||
});
|
||||
|
||||
it("updates the start time for left drags", function () {
|
||||
mockScope.startLeftDrag();
|
||||
mockScope.leftDrag(250);
|
||||
controller.startLeftDrag();
|
||||
controller.leftDrag(250);
|
||||
expect(mockScope.ngModel.inner.start)
|
||||
.toEqual(DAY * 1000 + HOUR * 9);
|
||||
});
|
||||
|
||||
it("updates the end time for right drags", function () {
|
||||
mockScope.startRightDrag();
|
||||
mockScope.rightDrag(-250);
|
||||
controller.startRightDrag();
|
||||
controller.rightDrag(-250);
|
||||
expect(mockScope.ngModel.inner.end)
|
||||
.toEqual(DAY * 1000 + HOUR * 15);
|
||||
});
|
||||
|
||||
it("updates both start and end for middle drags", function () {
|
||||
mockScope.startMiddleDrag();
|
||||
mockScope.middleDrag(-125);
|
||||
controller.startMiddleDrag();
|
||||
controller.middleDrag(-125);
|
||||
expect(mockScope.ngModel.inner).toEqual({
|
||||
start: DAY * 1000,
|
||||
end: DAY * 1000 + HOUR * 18
|
||||
});
|
||||
mockScope.middleDrag(250);
|
||||
controller.middleDrag(250);
|
||||
expect(mockScope.ngModel.inner).toEqual({
|
||||
start: DAY * 1000 + HOUR * 6,
|
||||
end: DAY * 1001
|
||||
@@ -186,8 +248,8 @@ define(
|
||||
});
|
||||
|
||||
it("enforces a minimum inner span", function () {
|
||||
mockScope.startRightDrag();
|
||||
mockScope.rightDrag(-9999999);
|
||||
controller.startRightDrag();
|
||||
controller.rightDrag(-9999999);
|
||||
expect(mockScope.ngModel.inner.end)
|
||||
.toBeGreaterThan(mockScope.ngModel.inner.start);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user