lightbox-factory spec

stable
Juanfran 2015-04-28 14:32:50 +02:00
parent 5bedf76d96
commit fdabf6514c
1 changed files with 71 additions and 0 deletions

View File

@ -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 = () -> "<p id='fake'>fake</p>"
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