mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-05 20:34:45 +00:00
Add fabric.Pattern tests
This commit is contained in:
parent
7fd1a09174
commit
107dcfcbd6
3 changed files with 79 additions and 1 deletions
3
test.js
3
test.js
|
|
@ -25,7 +25,8 @@ testrunner.run({
|
|||
'./test/unit/parser.js',
|
||||
'./test/unit/canvas.js',
|
||||
'./test/unit/canvas_static.js',
|
||||
'./test/unit/gradient.js'
|
||||
'./test/unit/gradient.js',
|
||||
'./test/unit/pattern.js'
|
||||
]
|
||||
}, function(err, report) {
|
||||
if(report.failed > 0){
|
||||
|
|
|
|||
BIN
test/fixtures/greyfloral.png
vendored
Normal file
BIN
test/fixtures/greyfloral.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6 KiB |
77
test/unit/pattern.js
Normal file
77
test/unit/pattern.js
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
(function() {
|
||||
|
||||
function createImageElement() {
|
||||
return fabric.isLikelyNode ? new (require('canvas').Image) : fabric.document.createElement('img');
|
||||
}
|
||||
function setSrc(img, src, callback) {
|
||||
if (fabric.isLikelyNode) {
|
||||
require('fs').readFile(src, function(err, imgData) {
|
||||
if (err) throw err;
|
||||
img.src = imgData;
|
||||
img._src = src;
|
||||
callback && callback();
|
||||
});
|
||||
}
|
||||
else {
|
||||
img.src = src;
|
||||
callback && callback();
|
||||
}
|
||||
}
|
||||
|
||||
QUnit.module('fabric.Pattern');
|
||||
|
||||
var img = createImageElement();
|
||||
setSrc(img, fabric.isLikelyNode ?
|
||||
(__dirname + '/../fixtures/greyfloral.png')
|
||||
: '../fixtures/greyfloral.png');
|
||||
|
||||
function createPattern() {
|
||||
return new fabric.Pattern({
|
||||
source: img
|
||||
});
|
||||
}
|
||||
|
||||
test('constructor', function() {
|
||||
ok(fabric.Pattern);
|
||||
|
||||
var pattern = createPattern();
|
||||
ok(pattern instanceof fabric.Pattern, 'should inherit from fabric.Pattern');
|
||||
});
|
||||
|
||||
test('properties', function() {
|
||||
var pattern = createPattern();
|
||||
|
||||
equal(pattern.source, img);
|
||||
equal(pattern.repeat, 'repeat');
|
||||
});
|
||||
|
||||
test('toObject', function() {
|
||||
var pattern = createPattern();
|
||||
|
||||
ok(typeof pattern.toObject == 'function');
|
||||
|
||||
var object = pattern.toObject();
|
||||
|
||||
// node-canvas doesn't give <img> "src"
|
||||
if (img.src) {
|
||||
equal(object.source, '../fixtures/greyfloral.png');
|
||||
}
|
||||
equal(object.repeat, 'repeat');
|
||||
|
||||
var sourceExecuted;
|
||||
var patternWithGetSource = new fabric.Pattern({
|
||||
source: function() {return fabric.document.createElement("canvas")}
|
||||
});
|
||||
|
||||
var object2 = patternWithGetSource.toObject();
|
||||
equal(object2.source, 'return fabric.document.createElement("canvas")');
|
||||
equal(object2.repeat, 'repeat');
|
||||
});
|
||||
|
||||
test('toLive', function() {
|
||||
var pattern = createPattern();
|
||||
|
||||
ok(typeof pattern.toLive == 'function');
|
||||
});
|
||||
|
||||
})();
|
||||
Loading…
Reference in a new issue