spec/javascripts/mercury/toolbar_spec.js.coffee in kiteditor-1.0.12 vs spec/javascripts/mercury/toolbar_spec.js.coffee in kiteditor-1.0.13

- old
+ new

@@ -1,9 +1,10 @@ describe "Mercury.Toolbar", -> + template 'mercury/toolbar.html' + beforeEach -> - fixture.load('mercury/toolbar.html') $.fx.off = true spyOn($, 'ajax').andCallFake (url, options) => options.success('data') if options.success afterEach -> @@ -13,14 +14,14 @@ describe "constructor", -> beforeEach -> @buildSpy = spyOn(Mercury.Toolbar.prototype, 'build').andCallFake(=>) @bindEventsSpy = spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>) - @toolbar = new Mercury.Toolbar({appendTo: fixture.el, foo: true}) + @toolbar = new Mercury.Toolbar({appendTo: '#test', foo: true}) it "accepts options as an argument", -> - expect(@toolbar.options).toEqual({appendTo: fixture.el, foo: true}) + expect(@toolbar.options).toEqual({appendTo: '#test', foo: true}) it "calls build", -> expect(@buildSpy.callCount).toEqual(1) it "calls bindEvents", -> @@ -45,11 +46,11 @@ expect($('#toolbar_container .mercury-toolbar-container').length).toEqual(1) it "builds out toolbar elements from the configuration", -> expect($('.mercury-primary-toolbar').length).toEqual(1) expect($('.mercury-editable-toolbar').length).toEqual(1) - expect($('.mercury-editable-toolbar').data('regions')).toEqual('full,markdown') + expect($('.mercury-editable-toolbar').data('regions')).toEqual('editable,markupable') it "builds buttons etc.", -> expect(@buildButtonSpy.callCount).toBeGreaterThan(10) it "sets it's width back to 100%", -> @@ -79,11 +80,11 @@ describe "#buildButton", -> beforeEach -> - @toolbar = new Mercury.Toolbar({appendTo: fixture.el}) + @toolbar = new Mercury.Toolbar({appendTo: '#test'}) it "throws an exception when invalid options are passed", -> expect(=> @toolbar.buildButton('foo', false)).toThrow('Unknown button structure -- please provide an array, object, or string for "foo".') it "returns false if the name is _custom, or _regions", -> @@ -124,28 +125,28 @@ describe "observed events", -> beforeEach -> - @toolbar = new Mercury.Toolbar({appendTo: fixture.el}) + @toolbar = new Mercury.Toolbar({appendTo: '#test'}) 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'}}) + Mercury.trigger('region:focused', {region: {type: 'editable'}}) expect($('.mercury.editable-toolbar').hasClass('disabled')).toEqual(false) $('.mercury-editable-toolbar').addClass('disabled') - Mercury.trigger('region:focused', {region: {type: -> 'markdown'}}) + Mercury.trigger('region:focused', {region: {type: 'markupable'}}) 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'}}) + Mercury.trigger('region:blurred', {region: {type: 'editable'}}) expect($('.mercury-editable-toolbar').hasClass('disabled')).toEqual(true) describe "click", -> it "triggers hide:dialogs", -> @@ -164,60 +165,30 @@ spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>) describe "when visible", -> beforeEach -> - @toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: true}) + @toolbar = new Mercury.Toolbar({appendTo: '#test', 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}) + @toolbar = new Mercury.Toolbar({appendTo: '#test', 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(=> $('<div>')) - 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(=> $('<div>')) spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>) - @toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: false}) + @toolbar = new Mercury.Toolbar({appendTo: '#test', visible: false}) it "sets visible to true", -> @toolbar.visible = false @toolbar.show() expect(@toolbar.visible).toEqual(true) @@ -236,10 +207,10 @@ describe "#hide", -> beforeEach -> spyOn(Mercury.Toolbar.prototype, 'buildButton').andCallFake(=> $('<div>')) spyOn(Mercury.Toolbar.prototype, 'bindEvents').andCallFake(=>) - @toolbar = new Mercury.Toolbar({appendTo: fixture.el, visible: true}) + @toolbar = new Mercury.Toolbar({appendTo: '#test', visible: true}) it "sets visible to false", -> @toolbar.visible = true @toolbar.hide() expect(@toolbar.visible).toEqual(false)