Created
June 4, 2015 09:36
-
-
Save regedarek/01ae30f1940ecd746d5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@reloadWindow = -> | |
# window cannot be reloaded in jasmine tests | |
{ } | |
class FileUploadStub | |
constructor: ($el, options) -> | |
@done = options.done | |
@$el = $el | |
@addEventListeners | |
addEventListeners: -> | |
@$el.on | |
@fakeSuccessfulFileUpload = ($el, e, data) -> | |
spyOn($el, 'fileupload').and.callFake -> | |
args = $el.fileupload.mostRecentCall.args | |
args.done(e, data) | |
@fakeSuccessfulAjaxCall = (data) -> | |
spyOn($, 'ajax').and.callFake (req) -> | |
d = $.Deferred() | |
d.resolve(data) | |
d.promise() | |
@fakeUnsuccessfulAjaxCall = (data) -> | |
spyOn($, 'ajax').and.callFake (req) -> | |
d = $.Deferred() | |
d.reject(data) | |
d.promise() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CoachesApp.AvatarUploader | |
constructor: ($el) -> | |
@$el = $el | |
@addEventListeners() | |
@modal = new CoachesApp.StandardModal | |
addEventListeners: -> | |
@setFileUpload() | |
@onImageHover() | |
setFileUpload: => | |
@$el.fileupload | |
dataType: 'json', | |
done: (e, data) => | |
if data.result.redirect_to | |
@modal.openModal | |
href: data.result.redirect_to | |
new CoachesApp.Jcrop($('#cropbox')) | |
if data.result.html | |
CoachesApp.EventBus.trigger('flash_message:added', data.result.html) | |
onImageHover: -> | |
$('.coach_profile-image').hover( | |
(e) -> | |
$(@).find('.overlay').animate {'opacity' : 1} | |
(e) -> | |
$(@).find('.overlay').animate {'opacity' : 0} | |
) | |
$ -> | |
if $('#new_editing_profile_avatar_form').length > 0 | |
new CoachesApp.AvatarUploader($('#new_editing_profile_avatar_form')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'AvatarUploader', -> | |
$fixture = null | |
describe 'on file upload', -> | |
beforeEach -> | |
$fixture = $(readFixtures('avatar.html')) | |
it 'opens modal', -> | |
@fakeSuccessfulFileUpload($fixture, null, { result: { redirect_to: 'coaches/crop' } }) | |
@uploader = new CoachesApp.AvatarUploader($('#new_editing_profile_avatar_form')) | |
spyOn(@uploader.modal, 'onModalOpened') | |
it 'replaces avatar image' | |
it 'shows flash message' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment