describe "Mercury.modalHandlers.insertMedia", -> template 'mercury/modals/insertmedia.html' beforeEach -> Mercury.region = null spyOn(window, 'setTimeout').andCallFake((callback, timeout) => callback()) @modal = element: $('#test') hide: -> resize: -> @insertMedia = $.extend(@modal, Mercury.modalHandlers.insertMedia) window.mercuryInstance = {document: $(document)} describe "clicking on a radio button (in a label)", -> beforeEach -> @insertMedia.initialize() it "focuses the next input with a selectable class", -> spy = spyOn($.fn, 'focus').andCallFake(=>) jasmine.simulate.click($('input[value=image_url]').get(0)) expect(spy.callCount).toEqual(1) describe "focusing an input", -> beforeEach -> @insertMedia.initialize() it "checks the corresponding checkbox", -> $('#media_youtube_url').focus() expect($('input[value=youtube_url]').get(0).checked).toEqual(true) it "hides all the option divs", -> $('#media_youtube_url').focus() expect($('#image_url_options').css('display')).toEqual('none') expect($('#vimeo_url_options').css('display')).toEqual('none') it "shows the options for the item that was focused", -> $('#media_youtube_url').focus() expect($('#youtube_url_options').css('display')).toNotEqual('none') it "calls resize", -> spy = spyOn(@modal, 'resize').andCallFake(=>) $('#media_youtube_url').focus() expect(spy.callCount).toEqual(1) describe "when editing", -> describe "an existing image", -> beforeEach -> @focusSpy = spyOn($.fn, 'focus').andCallThrough() @selection = {is: -> $('', {src: '/foo.gif', align: 'right', style: 'float: left;'})} Mercury.region = selection: => @selection @insertMedia.initialize() it "pre-fills the image url", -> expect($('#media_image_url').val()).toEqual('/foo.gif') it "focuses the url input", -> expect(@focusSpy.callCount).toEqual(2) expect($('input[value=image_url]').get(0).checked).toEqual(true) it "sets the image alignment option", -> expect($('#media_image_alignment').val()).toEqual('right') it "sets the image float option", -> expect($('#media_image_float').val()).toEqual('left') describe "an existing youtube video", -> beforeEach -> @focusSpy = spyOn($.fn, 'focus').andCallThrough() @selection = {is: -> $('