Add toJSON back to image filters

Add toJSON to unit tests
This commit is contained in:
Kienz 2013-08-09 20:37:56 +02:00
parent f2035da955
commit a61b384684
12 changed files with 187 additions and 0 deletions

View file

@ -50,6 +50,15 @@ fabric.Image.filters.Brightness = fabric.util.createClass(/** @lends fabric.Imag
type: this.type,
brightness: this.brightness
};
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -102,6 +102,15 @@ fabric.Image.filters.Convolute = fabric.util.createClass(/** @lends fabric.Image
opaque: this.opaque,
matrix: this.matrix
};
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -49,6 +49,15 @@ fabric.Image.filters.GradientTransparency = fabric.util.createClass(/** @lends f
type: this.type,
threshold: this.threshold
};
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -42,6 +42,15 @@ fabric.Image.filters.Grayscale = fabric.util.createClass(/** @lends fabric.Image
*/
toObject: function() {
return { type: this.type };
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -38,6 +38,15 @@ fabric.Image.filters.Invert = fabric.util.createClass(/** @lends fabric.Image.fi
*/
toObject: function() {
return { type: this.type };
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -53,6 +53,15 @@ fabric.Image.filters.Noise = fabric.util.createClass(/** @lends fabric.Image.fil
type: this.type,
noise: this.noise
};
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -78,6 +78,15 @@ fabric.Image.filters.Pixelate = fabric.util.createClass(/** @lends fabric.Image.
type: this.type,
blocksize: this.blocksize
};
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -66,6 +66,15 @@ fabric.Image.filters.RemoveWhite = fabric.util.createClass(/** @lends fabric.Ima
threshold: this.threshold,
distance: this.distance
};
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -42,6 +42,15 @@ fabric.Image.filters.Sepia2 = fabric.util.createClass(/** @lends fabric.Image.fi
*/
toObject: function() {
return { type: this.type };
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -39,6 +39,15 @@ fabric.Image.filters.Sepia = fabric.util.createClass(/** @lends fabric.Image.fil
*/
toObject: function() {
return { type: this.type };
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -60,6 +60,15 @@ fabric.Image.filters.Tint = fabric.util.createClass(/** @lends fabric.Image.filt
type: this.type,
color: this.color
};
},
/**
* Returns a JSON representation of an instance
* @return {Object} JSON
*/
toJSON: function() {
// delegate, not alias
return this.toObject();
}
});

View file

@ -32,6 +32,14 @@
equal(JSON.stringify(object), '{"type":"Brightness","brightness":100}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Brightness();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Brightness","brightness":100}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Brightness();
@ -73,6 +81,14 @@
equal(JSON.stringify(object), '{"type":"Convolute","opaque":1,"matrix":[0,0,0,0,1,0,0,0,0]}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Convolute({opaque: 1});
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Convolute","opaque":1,"matrix":[0,0,0,0,1,0,0,0,0]}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Convolute();
@ -111,6 +127,14 @@
equal(JSON.stringify(object), '{"type":"GradientTransparency","threshold":100}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.GradientTransparency();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"GradientTransparency","threshold":100}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.GradientTransparency();
@ -146,6 +170,14 @@
equal(JSON.stringify(object), '{"type":"Grayscale"}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Grayscale();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Grayscale"}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Grayscale();
@ -181,6 +213,14 @@
equal(JSON.stringify(object), '{"type":"Invert"}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Invert();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Invert"}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Invert();
@ -220,6 +260,14 @@
equal(JSON.stringify(object), '{"type":"Noise","noise":100}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Noise();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Noise","noise":100}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Noise();
@ -259,6 +307,14 @@
equal(JSON.stringify(object), '{"type":"Pixelate","blocksize":4}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Pixelate();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Pixelate","blocksize":4}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Pixelate();
@ -300,6 +356,14 @@
equal(JSON.stringify(object), '{"type":"RemoveWhite","threshold":30,"distance":20}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.RemoveWhite();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"RemoveWhite","threshold":30,"distance":20}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.RemoveWhite();
@ -335,6 +399,14 @@
equal(JSON.stringify(object), '{"type":"Sepia2"}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Sepia2();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Sepia2"}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Sepia2();
@ -370,6 +442,14 @@
equal(JSON.stringify(object), '{"type":"Sepia"}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Sepia();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Sepia"}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Sepia();
@ -409,6 +489,14 @@
equal(JSON.stringify(object), '{"type":"Tint","color":0}');
});
test('toJSON', function() {
var filter = new fabric.Image.filters.Tint();
ok(typeof filter.toJSON == 'function');
var json = filter.toJSON();
equal(JSON.stringify(json), '{"type":"Tint","color":0}');
});
test('fromObject', function() {
var filter = new fabric.Image.filters.Tint();