-
-
Save jriecken/04fbfc5486ef22ddf9f8 to your computer and use it in GitHub Desktop.
Steven Xu - Why I changed my functioning code to accommodate a test - code.hootsuite.com
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
var expectEditor = { | |
toBeClosed: function() { | |
expect($('.image-editor')).toBeHidden(); | |
expect($('.drag-to-reposition')).toBeHidden(); | |
expect($('.filter-options')).toBeHidden(); | |
expect($('.tools')).toBeHidden(); | |
expect($('.patterns')).toBeHidden(); | |
expect($('.edit-img')).toBeVisible(); | |
}, | |
toBeOpen: function() { | |
expect($('.image-editor')).toBeVisible(); | |
expect($('.drag-to-reposition')).toBeVisible(); | |
expect($('.filter-options')).toBeHidden(); | |
expect($('.tools')).toBeVisible(); | |
expect($('.patterns')).toBeHidden(); | |
expect($('.edit-img')).toBeHidden(); | |
} | |
}; |
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
var _controlEditMode = function(toClose) { | |
if (toClose) { | |
$imageElem.removeClass('hide'); | |
$canvasElem.parent().addClass('hide'); | |
$tools.addClass('hide'); | |
$editBtn.removeClass('hide'); | |
$dragToReposition.addClass('hide'); | |
$(document).trigger('editor.closed') | |
} else { | |
$(imageElemSelector).addClass('hide'); | |
$canvasElem.parent().removeClass('hide'); | |
$tools.removeClass('hide'); | |
$editBtn.addClass('hide'); | |
if (fabricCanvas.getObjects().length) { | |
$dragToReposition.removeClass('hide'); | |
} | |
$(document).trigger('editor.opened'); | |
} | |
$filterLayer.addClass('hide'); | |
}; |
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
beforeEach(function() { | |
myEditor = imageEditor.init({ | |
canvas: 'canvas', | |
imageElemSelector: '.myImg', | |
}); | |
expect(myEditor).toBeTruthy(); | |
}); | |
describe('Testing open/close', function() { | |
it('should be able to open by clicking on edit', function() { | |
$('.edit-img').click(); | |
expectEditor.toBeOpen(); | |
}); | |
/* some other tests */ | |
} |
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
var initImageEditor = function(options) { | |
fabricCanvas = new fabric.Canvas(canvasID, canvasOptions); | |
var imageUrl = 'some/default/image.png'; | |
fabric.Image.fromURL(imageUrl, function(img) { | |
fabricCanvas.add(img); | |
}, imgOptions); | |
return this; | |
}; |
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
beforeEach(function(done) { | |
imageEditor.init({ | |
canvas: 'canvas', | |
imageElemSelector: '.myImg', | |
success: function() { | |
myEditor = imageEditor.getEditor(); | |
expect(myEditor).toBeTruthy(); | |
done(); | |
} | |
}); | |
}); |
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
var initImageEditor = function(options) { | |
fabricCanvas = new fabric.Canvas(canvasID, canvasOptions); | |
var imageUrl = 'some/default/image.png'; | |
fabric.Image.fromURL(imageUrl, function(img) { | |
fabricCanvas.add(img); | |
if (options.success) options.success(); | |
}, imgOptions); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment