Skip to content

Instantly share code, notes, and snippets.

@jriecken
Last active October 28, 2015 17:57
Show Gist options
  • Save jriecken/04fbfc5486ef22ddf9f8 to your computer and use it in GitHub Desktop.
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
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();
}
};
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');
};
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 */
}
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;
};
beforeEach(function(done) {
imageEditor.init({
canvas: 'canvas',
imageElemSelector: '.myImg',
success: function() {
myEditor = imageEditor.getEditor();
expect(myEditor).toBeTruthy();
done();
}
});
});
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