add more tests

master
adeveria 2013-09-12 15:44:59 -07:00
parent 2a8f553eaf
commit f7fa0526ba
2 changed files with 196 additions and 0 deletions

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50">
<circle cx="10" cy="20" r="30"/>
</svg>

After

Width:  |  Height:  |  Size: 146 B

View File

@ -49,4 +49,196 @@ describe("Savage methods", function () {
}, {'isContext': true}); }, {'isContext': true});
expect(xhr).to.be.an('object'); expect(xhr).to.be.an('object');
}); });
var validateMina = function(minaObj) {
expect(minaObj).to.be.an('object');
expect(minaObj.id).to.be.a('string');
expect(minaObj.duration).to.be.a('function');
expect(minaObj.easing).to.be.a('function');
expect(minaObj.speed).to.be.a('function');
expect(minaObj.status).to.be.a('function');
expect(minaObj.stop).to.be.a('function');
};
it("Savage.animate - numbers, no easing or callback", function(done) {
var n;
var minaObj = Savage.animate(10, 20, function(newN) { n = newN; }, 50);
setTimeout(function() {
expect(n).to.be(20);
done();
}, 100);
validateMina(minaObj);
});
it("Savage.animate - numbers, callback", function(done) {
var n;
var minaObj = Savage.animate(10, 20, function(newN) { n = newN; }, 50, function() {
expect(n).to.be(20);
done();
});
validateMina(minaObj);
});
it("Savage.animate - numbers, easing", function(done) {
var n;
var minaObj = Savage.animate(10, 20, function(newN) { n = newN; }, 50, mina.easeinout);
setTimeout(function() {
expect(n).to.be(20);
done();
}, 100);
validateMina(minaObj);
});
it("Savage.animate - numbers, easing & callback", function(done) {
var n;
var minaObj = Savage.animate(10, 20, function(newN) { n = newN; }, 50, mina.bounce, function() {
expect(n).to.be(20);
done();
});
validateMina(minaObj);
});
it("Savage.animate - arrays, no easing or callback", function(done) {
var n1, n2;
var minaObj = Savage.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0]; n2 = nArr[1]; }, 50);
setTimeout(function() {
expect(n1).to.be(10);
expect(n2).to.be(20);
done();
}, 100);
validateMina(minaObj);
});
it("Savage.animate - arrays, callback", function(done) {
var n1, n2;
var minaObj = Savage.animate([5, 10], [10, 20], function(nArr) {n1 = nArr[0]; n2 = nArr[1]; }, 50, function() {
expect(n1).to.be(10);
expect(n2).to.be(20);
done();
});
validateMina(minaObj);
});
it("Savage.animate - arrays, easing", function(done) {
var n1, n2;
var minaObj = Savage.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0], n2 = nArr[1]; }, 50, mina.easeinout);
setTimeout(function() {
expect(n1).to.be(10);
expect(n2).to.be(20);
done();
}, 100);
validateMina(minaObj);
});
it("Savage.animate - arrays, easing & callback", function(done) {
var n1, n2;
var minaObj = Savage.animate([5, 10], [10, 20], function(nArr) { n1 = nArr[0], n2 = nArr[1] }, 50, mina.backin, function() {
expect(n1).to.be(10);
expect(n2).to.be(20);
done();
});
validateMina(minaObj);
});
it("Savage.animation - no easing or callback", function() {
var anim = Savage.animation({ foo: "bar" }, 100);
expect(anim).to.be.an("object");
expect(anim.dur).to.be(100);
expect(anim.attr.foo).to.be("bar");
});
it("Savage.animation - with easing", function() {
var anim = Savage.animation({ foo: "bar" }, 100, mina.easein);
expect(anim).to.be.an("object");
expect(anim.dur).to.be(100);
expect(anim.attr.foo).to.be("bar");
expect(anim.easing).to.be.a("function");
});
it("Savage.animation - with callback", function() {
var cb = function(){};
var anim = Savage.animation({ foo: "bar" }, 100, cb);
expect(anim).to.be.an("object");
expect(anim.dur).to.be(100);
expect(anim.attr.foo).to.be("bar");
expect(anim.callback).to.be.a("function");
});
it("Savage.animation - with easing & callback", function() {
var cb = function(){};
var anim = Savage.animation({ foo: "bar" }, 100, mina.linear, cb);
expect(anim).to.be.an("object");
expect(anim.dur).to.be(100);
expect(anim.attr.foo).to.be("bar");
expect(anim.easing).to.be.a("function");
expect(anim.callback).to.be.a("function");
expect(anim.easing).to.not.be(anim.callback);
});
it("Savage.deg", function() {
expect(Savage.deg(Math.PI)).to.be(180);
expect(Savage.deg(Math.PI / 2)).to.be(90);
expect(Savage.deg(Math.PI / 4)).to.be(45)
expect(Savage.deg(Math.PI * 2)).to.be(0);
});
it("Savage.rad", function() {
expect(Savage.rad(180)).to.be(Math.PI);
expect(Savage.rad(90)).to.be(Math.PI / 2);
expect(Savage.rad(45)).to.be(Math.PI / 4);
expect(Savage.rad(0)).to.be(0);
});
it("Savage.format", function() {
var outputStr;
outputStr = Savage.format("{x}", {x: 1});
expect(outputStr).to.be("1");
outputStr = Savage.format("{a['foo']}", {
a: {
foo: 'bar'
}
});
expect(outputStr).to.be("bar");
outputStr = Savage.format("M{x},{y}h{dim.width}v{dim.height}h{dim['negative width']}z", {
x: 10,
y: 20,
dim: {
width: 40,
height: 50,
"negative width": -40
}
});
expect(outputStr).to.be("M10,20h40v50h-40z");
});
it("Savage.fragment", function() {
var frag = Savage.fragment('<g class="foo"></g>', '<g class="foo2"></g>');
expect(frag).to.be.an("object");
expect(frag.node.childNodes.length).to.be(2);
expect(frag.node.firstChild.nodeName).to.be("g");
expect(frag.node.firstChild.getAttribute("class")).to.be("foo");
expect(frag.node.lastChild.getAttribute("class")).to.be("foo2");
frag = Savage.fragment('<g class="foo"><rect x="0" y="0" width="10" height="10"/></g>');
var rectWidth = frag.select('rect').attr('width');
expect(rectWidth).to.be("10");
});
it("Savage.is", function() {
var undef;
expect(Savage.is("foo", "string")).to.be.ok();
expect(Savage.is(123, "number")).to.be.ok();
expect(Savage.is({}, "object")).to.be.ok();
expect(Savage.is([], "array")).to.be.ok();
expect(Savage.is(null, "null")).to.be.ok();
expect(Savage.is(false, "boolean")).to.be.ok();
expect(Savage.is(undef, "undefined")).to.be.ok();
expect(Savage.is(function(){}, "function")).to.be.ok();
});
it("Savage.load - with context", function(done) {
Savage.load('./res/external-svg.svg', function(fragment) {
expect(fragment.node.firstElementChild.nodeName).to.be('svg');
expect(this.myContext).to.be(true);
done();
}, {myContext: true});
});
it("Savage.load - without context", function(done) {
Savage.load('./res/external-svg.svg', function(fragment) {
expect(fragment.node.firstElementChild.nodeName).to.be('svg');
done();
});
});
it("Savage.parse", function() {
var frag = Savage.parse('<g class="foo"></g>');
expect(frag).to.be.an("object");
expect(frag.node.childNodes.length).to.be(1);
expect(frag.node.firstChild.nodeName).to.be("g");
expect(frag.node.firstChild.getAttribute("class")).to.be("foo");
frag = Savage.parse('<g class="foo"><rect x="0" y="0" width="10" height="10"/></g>');
var rectWidth = frag.select('rect').attr('width');
expect(rectWidth).to.be("10");
});
}); });