').html(@toolbar.buildButton('foosep1', ' ')).html()
expect(html).toEqual('
').html(@toolbar.buildButton('foosep1', '-')).html()
expect(html).toEqual('
')
it "builds buttons from configuration", ->
expect($('.mercury-primary-toolbar .mercury-save-button').length).toEqual(1)
expect($('.mercury-primary-toolbar .mercury-preview-button').length).toEqual(1)
it "builds button groups from configuration", ->
expect($('.mercury-editable-toolbar .mercury-decoration-group').length).toEqual(1)
expect($('.mercury-editable-toolbar .mercury-script-group').length).toEqual(1)
it "builds separators from configuration", ->
expect($('.mercury-separator').length).toBeGreaterThan(1);
expect($('.mercury-line-separator').length).toBeGreaterThan(1);
describe "observed events", ->
beforeEach ->
@toolbar = new Mercury.Toolbar({appendTo: fixture.el})
describe "custom event: region:focused", ->
it "enables toolbars based on the region type", ->
$('.mercury-editable-toolbar').addClass('disabled')
Mercury.trigger('region:focused', {region: {type: -> 'full'}})
expect($('.mercury.editable-toolbar').hasClass('disabled')).toEqual(false)
$('.mercury-editable-toolbar').addClass('disabled')
Mercury.trigger('region:focused', {region: {type: -> 'markdown'}})
expect($('.mercury.editable-toolbar').hasClass('disabled')).toEqual(false)
describe "custom event: region:blurred", ->
it "disables toolbars for the region type", ->
$('.mercury-editable-toolbar').removeClass('disabled')
Mercury.trigger('region:blurred', {region: {type: -> 'full'}})
expect($('.mercury-editable-toolbar').hasClass('disabled')).toEqual(true)
describe "click", ->
it "triggers hide:dialogs", ->
spy = spyOn(Mercury, 'trigger')
jasmine.simulate.click(@toolbar.element.get(0))
expect(spy.callCount).toEqual(1)
expect(spy.argsForCall[0]).toEqual(['hide:dialogs'])
describe "#height", ->
beforeEach ->
spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('
'))
spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>)
describe "when visible", ->
beforeEach ->
@toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: true})
it "returns the element outerheight", ->
expect(@toolbar.height()).toEqual($('.mercury-toolbar-container').outerHeight())
describe "when not visible", ->
beforeEach ->
@toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: false})
it "returns 0", ->
expect(@toolbar.height()).toEqual(0)
describe "when forced", ->
beforeEach ->
@toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: false})
it "returns the element outerheight", ->
expect(@toolbar.height(true)).toEqual($('.mercury-toolbar-container').outerHeight())
describe "#top", ->
beforeEach ->
spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('
'))
spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>)
describe "when visible", ->
beforeEach ->
@toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: true})
it "returns the element offests top", ->
expect(@toolbar.top()).toEqual($('.mercury-toolbar-container').offset().top)
describe "when not visible", ->
beforeEach ->
@toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: false})
it "returns the element offests top", ->
expect(@toolbar.top()).toEqual(0)
describe "#show", ->
beforeEach ->
spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('
'))
spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>)
@toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: false})
it "sets visible to true", ->
@toolbar.visible = false
@toolbar.show()
expect(@toolbar.visible).toEqual(true)
it "displays the element", ->
$('.mercury-toolbar-container').css({display: 'none'})
@toolbar.show()
expect($('.mercury-toolbar-container').css('display')).toEqual('block')
it "sets the top of the element", ->
$('.mercury-toolbar-container').css({top: '-20px'})
@toolbar.show()
expect($('.mercury-toolbar-container').css('top')).toEqual('0px')
describe "#hide", ->
beforeEach ->
spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('
'))
spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>)
@toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: true})
it "sets visible to false", ->
@toolbar.visible = true
@toolbar.hide()
expect(@toolbar.visible).toEqual(false)
it "hides the element", ->
$('.mercury-toolbar-container').css({display: 'block'})
@toolbar.hide()
expect($('.mercury-toolbar-container').css('display')).toEqual('none')