[Time Conductor] Test mct-click-elsewhere
This commit is contained in:
@@ -34,14 +34,14 @@ define(
|
|||||||
mockElement,
|
mockElement,
|
||||||
testAttrs,
|
testAttrs,
|
||||||
mockBody,
|
mockBody,
|
||||||
mockParentEl,
|
mockPlainEl,
|
||||||
testRect,
|
testRect,
|
||||||
mctClickElsewhere;
|
mctClickElsewhere;
|
||||||
|
|
||||||
function testEvent(x, y) {
|
function testEvent(x, y) {
|
||||||
return {
|
return {
|
||||||
pageX: x,
|
clientX: x,
|
||||||
pageY: y,
|
clientY: y,
|
||||||
preventDefault: jasmine.createSpy("preventDefault")
|
preventDefault: jasmine.createSpy("preventDefault")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -55,8 +55,8 @@ define(
|
|||||||
jasmine.createSpyObj("element", JQLITE_METHODS);
|
jasmine.createSpyObj("element", JQLITE_METHODS);
|
||||||
mockBody =
|
mockBody =
|
||||||
jasmine.createSpyObj("body", JQLITE_METHODS);
|
jasmine.createSpyObj("body", JQLITE_METHODS);
|
||||||
mockParentEl =
|
mockPlainEl =
|
||||||
jasmine.createSpyObj("parent", ["getBoundingClientRect"]);
|
jasmine.createSpyObj("htmlElement", ["getBoundingClientRect"]);
|
||||||
|
|
||||||
testAttrs = {
|
testAttrs = {
|
||||||
mctClickElsewhere: "some Angular expression"
|
mctClickElsewhere: "some Angular expression"
|
||||||
@@ -67,6 +67,8 @@ define(
|
|||||||
width: 60,
|
width: 60,
|
||||||
height: 75
|
height: 75
|
||||||
};
|
};
|
||||||
|
mockElement[0] = mockPlainEl;
|
||||||
|
mockPlainEl.getBoundingClientRect.andReturn(testRect);
|
||||||
|
|
||||||
mockDocument.find.andReturn(mockBody);
|
mockDocument.find.andReturn(mockBody);
|
||||||
|
|
||||||
@@ -78,6 +80,49 @@ define(
|
|||||||
expect(mctClickElsewhere.restrict).toEqual("A");
|
expect(mctClickElsewhere.restrict).toEqual("A");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("detaches listeners when destroyed", function () {
|
||||||
|
expect(mockBody.off).not.toHaveBeenCalled();
|
||||||
|
mockScope.$on.calls.forEach(function (call) {
|
||||||
|
if (call.args[0] === '$destroy') {
|
||||||
|
call.args[1]();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(mockBody.off).toHaveBeenCalled();
|
||||||
|
expect(mockBody.off.mostRecentCall.args)
|
||||||
|
.toEqual(mockBody.on.mostRecentCall.args);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("listens for mousedown on the document's body", function () {
|
||||||
|
expect(mockBody.on)
|
||||||
|
.toHaveBeenCalledWith('mousedown', jasmine.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when a click occurs outside the element's bounds", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
mockBody.on.mostRecentCall.args[1](testEvent(
|
||||||
|
testRect.left + testRect.width + 10,
|
||||||
|
testRect.top + testRect.height + 10
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("triggers an evaluation of its related Angular expression", function () {
|
||||||
|
expect(mockScope.$eval)
|
||||||
|
.toHaveBeenCalledWith(testAttrs.mctClickElsewhere);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when a click occurs within the element's bounds", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
mockBody.on.mostRecentCall.args[1](testEvent(
|
||||||
|
testRect.left + testRect.width / 2,
|
||||||
|
testRect.top + testRect.height / 2
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("triggers no evaluation", function () {
|
||||||
|
expect(mockScope.$eval).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user