From fdabf6514cb0bad2e81b7181ed2d85a857c173eb Mon Sep 17 00:00:00 2001 From: Juanfran Date: Tue, 28 Apr 2015 14:32:50 +0200 Subject: [PATCH] lightbox-factory spec --- .../lightbox-factory.service.spec.coffee | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 app/modules/services/lightbox-factory.service.spec.coffee diff --git a/app/modules/services/lightbox-factory.service.spec.coffee b/app/modules/services/lightbox-factory.service.spec.coffee new file mode 100644 index 00000000..c939e66b --- /dev/null +++ b/app/modules/services/lightbox-factory.service.spec.coffee @@ -0,0 +1,71 @@ +describe "tgLightboxFactory", -> + lightboxFactoryService = provide = null + mocks = {} + + _mockRootScope = () -> + mocks.rootScope = sinon.stub() + provide.value "$rootScope", {$new: mocks.rootScope} + + _mockCompile = () -> + mocks.compile = sinon.stub() + fn = () -> "

fake

" + mocks.compile.returns(fn) + provide.value "$compile", mocks.compile + + _inject = (callback) -> + inject (_tgLightboxFactory_) -> + lightboxFactoryService = _tgLightboxFactory_ + callback() if callback + + _mocks = () -> + module ($provide) -> + provide = $provide + _mockRootScope() + _mockCompile() + + return null + + _setup = -> + _mocks() + + beforeEach -> + module "taigaCommon" + _setup() + _inject() + + it "insert directive", () -> + lightboxFactoryService.create("fake-directive") + + expect($(document.body).find("#fake")).to.have.length(1) + + it "directive must have the tg-bind-scope directive", () -> + lightboxFactoryService.create("fake-directive") + + checkDirective = sinon.match ( (value) -> + return value.attr("tg-bind-scope") + ), "checkDirective" + + expect(mocks.compile.withArgs(checkDirective)).to.have.been.calledOnce + + it "custom attributes", () -> + attrs = { + "class": "x1", + "id": "x2" + } + + lightboxFactoryService.create("fake-directive", attrs) + + checkAttributes = sinon.match ( (value) -> + return value.attr("class") == "x1" && value.attr("id") == "x2" + ), "checkAttributes" + + expect(mocks.compile.withArgs(checkAttributes)).to.have.been.calledOnce + + it "directive has class remove-on-close", () -> + lightboxFactoryService.create("fake-directive") + + checkClass = sinon.match ( (value) -> + return value.hasClass("remove-on-close") + ), "checkClass" + + expect(mocks.compile.withArgs(checkClass)).to.have.been.calledOnce