[Common UI] Update mct-popup spec

...to reflect usage of popupService.
This commit is contained in:
Victor Woeltjen
2015-10-02 14:36:04 -07:00
parent c4aff95341
commit 553b17fafe

View File

@@ -29,15 +29,16 @@ define(
var JQLITE_METHODS = [ "on", "off", "find", "parent", "css", "append" ]; var JQLITE_METHODS = [ "on", "off", "find", "parent", "css", "append" ];
describe("The mct-popup directive", function () { describe("The mct-popup directive", function () {
var testWindow, var mockCompile,
mockDocument, mockPopupService,
mockCompile, mockPopup,
mockScope, mockScope,
mockElement, mockElement,
testAttrs, testAttrs,
mockBody, mockBody,
mockTransclude, mockTransclude,
mockParentEl, mockParentEl,
mockNewElement,
testRect, testRect,
mctPopup; mctPopup;
@@ -50,12 +51,12 @@ define(
} }
beforeEach(function () { beforeEach(function () {
testWindow =
{ innerWidth: 600, innerHeight: 300 };
mockDocument =
jasmine.createSpyObj("$document", JQLITE_METHODS);
mockCompile = mockCompile =
jasmine.createSpy("$compile"); jasmine.createSpy("$compile");
mockPopupService =
jasmine.createSpyObj("popupService", ["display"]);
mockPopup =
jasmine.createSpyObj("popup", ["dismiss"]);
mockScope = mockScope =
jasmine.createSpyObj("$scope", [ "$eval", "$apply", "$on" ]); jasmine.createSpyObj("$scope", [ "$eval", "$apply", "$on" ]);
mockElement = mockElement =
@@ -66,6 +67,8 @@ define(
jasmine.createSpy("transclude"); jasmine.createSpy("transclude");
mockParentEl = mockParentEl =
jasmine.createSpyObj("parent", ["getBoundingClientRect"]); jasmine.createSpyObj("parent", ["getBoundingClientRect"]);
mockNewElement =
jasmine.createSpyObj("newElement", JQLITE_METHODS);
testAttrs = { testAttrs = {
mctClickElsewhere: "some Angular expression" mctClickElsewhere: "some Angular expression"
@@ -77,15 +80,17 @@ define(
height: 75 height: 75
}; };
mockDocument.find.andReturn(mockBody); mockCompile.andCallFake(function () {
mockCompile.andReturn(jasmine.createSpy()); var mockFn = jasmine.createSpy();
mockCompile().andCallFake(function () { mockFn.andReturn(mockNewElement);
return jasmine.createSpyObj("newElement", JQLITE_METHODS); return mockFn;
}); });
mockElement.parent.andReturn([mockParentEl]); mockElement.parent.andReturn([mockParentEl]);
mockParentEl.getBoundingClientRect.andReturn(testRect); mockParentEl.getBoundingClientRect.andReturn(testRect);
mockPopupService.display.andReturn(mockPopup);
mctPopup = new MCTPopup(mockCompile, mockPopupService);
mctPopup = new MCTPopup(testWindow, mockDocument, mockCompile);
mctPopup.link( mctPopup.link(
mockScope, mockScope,
mockElement, mockElement,
@@ -99,6 +104,32 @@ define(
expect(mctPopup.restrict).toEqual("E"); expect(mctPopup.restrict).toEqual("E");
}); });
describe("creates an element which", function () {
it("displays as a popup", function () {
expect(mockPopupService.display).toHaveBeenCalledWith(
mockNewElement,
[ testRect.left, testRect.top ]
);
});
it("displays transcluded content", function () {
var mockClone =
jasmine.createSpyObj('clone', JQLITE_METHODS);
mockTransclude.mostRecentCall.args[0](mockClone);
expect(mockNewElement.append)
.toHaveBeenCalledWith(mockClone);
});
it("is removed when its containing scope is destroyed", function () {
expect(mockPopup.dismiss).not.toHaveBeenCalled();
mockScope.$on.calls.forEach(function (call) {
if (call.args[0] === '$destroy') {
call.args[1]();
}
});
expect(mockPopup.dismiss).toHaveBeenCalled();
});
});
}); });
} }