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: -> describe "clicking on a radio button (in a label)", -> beforeEach -> Mercury.modalHandlers.insertMedia.call(@modal) it "focuses the next input with a selectable class", -> spy = spyOn($.fn, 'focus').andCallFake(=>) jasmine.simulate.click($('#checkbox1').get(0)) expect(spy.callCount).toEqual(1) describe "focusing an input", -> beforeEach -> Mercury.modalHandlers.insertMedia.call(@modal) it "checks the corresponding checkbox", -> $('#media_youtube_url').focus() expect($('#checkbox2').get(0).checked).toEqual(true) it "hides all the option divs", -> $('#media_youtube_url').focus() expect($('#image_url').css('display')).toEqual('none') expect($('#vimeo_url').css('display')).toEqual('none') it "shows the options for the item that was focused", -> $('#media_youtube_url').focus() expect($('#youtube_url').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'})} Mercury.region = selection: => @selection Mercury.modalHandlers.insertMedia.call(@modal) it "pre-fills the image url", -> expect($('#media_image_url').val()).toEqual('/foo.gif') it "focuses the url input", -> expect(@focusSpy.callCount).toEqual(1) expect($('input[value=image_url]').get(0).checked).toEqual(true) it "sets the image alignment option", -> expect($('#media_image_alignment').val()).toEqual('right') describe "an existing youtube video", -> beforeEach -> @focusSpy = spyOn($.fn, 'focus').andCallThrough() @selection = {is: -> $('