describe "directives", ->
beforeEach module("mb.directives")
$rootScope = null
element = null
describe "osEsc", ->
beforeEach inject ($compile, _$rootScope_) ->
$rootScope = _$rootScope_
$rootScope.bar = ->
element = angular.element """
"""
$compile(element)($rootScope)
$rootScope.$digest()
it "calls the given function when the ESC was pressed", ->
spyOn($rootScope, 'bar')
event = jQuery.Event("keyup", keyCode: 27)
element.trigger(event)
expect($rootScope.bar).toHaveBeenCalled()
it "does nothing on other keys", ->
spyOn($rootScope, 'bar')
event = jQuery.Event("keyup", keyCode: 13)
element.trigger(event)
expect($rootScope.bar).not.toHaveBeenCalled()
describe "showButton", ->
renderedButton = null
# TODO use this trick in other places
compileTemplate = (template, callback = ->) ->
beforeEach inject ($compile, $rootScope) ->
element = angular.element(template)
$compile(element)($rootScope)
$rootScope.$digest()
callback(element)
describe "when a custom label is not provided", ->
template = """
"""
compileTemplate template, (element) ->
renderedButton = element.find("a")
it "renders the button", ->
expect(renderedButton.length).toBe(1)
expect(renderedButton.hasClass("btn")).toBeTruthy()
expect(renderedButton.hasClass("btn-success")).toBeTruthy()
it "renders the path", ->
expect(renderedButton.attr("href")).toEqual("/foo/bar/biz")
it "renders the custom label", ->
expect(renderedButton.text()).toContain("Show")
describe "when a custom label is provided", ->
template = """
"""
compileTemplate template, (element) ->
renderedButton = element.find("a")
it "renders the button", ->
expect(renderedButton.length).toBe(1)
expect(renderedButton.hasClass("btn")).toBeTruthy()
expect(renderedButton.hasClass("btn-success")).toBeTruthy()
expect(renderedButton.attr("href")).toEqual("/foo/bar")
it "renders the custom label", ->
expect(renderedButton.text()).toContain("Display me the foo")
describe "deleteButton", ->
beforeEach inject ($compile, $rootScope) ->
$rootScope = $rootScope
$rootScope.bar = ->
element = angular.element """