Dmitry Baranovskiy 2013-09-12 11:11:58 +10:00
commit 3849db5e2f
6 changed files with 179 additions and 5 deletions

BIN
test/.DS_Store vendored

Binary file not shown.

View File

@ -112,8 +112,7 @@ describe("Element methods", function () {
expect(rect.node.parentNode).to.be(s.node); expect(rect.node.parentNode).to.be(s.node);
var result = rect.remove(); var result = rect.remove();
expect(rect.node.parentNode).to.be(null); expect(rect.node.parentNode).to.be(null);
// NOTE: docs say it does not return anything, but perhaps it should? expect(result).to.be(rect);
// expect(result).to.be(rect);
}); });
/* /*
@ -126,6 +125,8 @@ describe("Element methods", function () {
Element.getPointAtLength() Element.getPointAtLength()
Element.getSubpath() Element.getSubpath()
Element.getTotalLength() Element.getTotalLength()
Element.innerSVG()
Element.toString()
*/ */
it("Element.attr - get", function() { it("Element.attr - get", function() {
@ -147,6 +148,11 @@ describe("Element methods", function () {
expect(cy).to.be("2"); expect(cy).to.be("2");
expect(r).to.be("3"); expect(r).to.be("3");
}); });
it("Element.attr - set on group", function() {
var group = s.group();
group.attr({'class': 'myclass'});
expect(group.node.getAttribute('class')).to.be('myclass');
});
it("Element.data", function() { it("Element.data", function() {
var circle = s.circle(10, 20, 30); var circle = s.circle(10, 20, 30);
circle.data("foo", "bar"); circle.data("foo", "bar");
@ -226,6 +232,40 @@ describe("Element methods", function () {
var path = s.path("M0,0 100,0"); var path = s.path("M0,0 100,0");
expect(+path.getTotalLength("M0,0 100,0").toFixed(2)).to.be(100); expect(+path.getTotalLength("M0,0 100,0").toFixed(2)).to.be(100);
}); });
it("Element.innerSVG", function() {
var group1 = s.group().attr({
'class': 'group-one'
});
var group2 = s.group().attr({
'class': 'group-two'
});
var group3 = s.group().attr({
'class': 'group-three'
});
var circle1 = s.circle(10, 20, 30).attr({
'class': 'circle-one'
});
var circle2 = s.circle(5, 10, 25).attr({
'class': 'circle-two'
});
group1.add(group2);
group2.add(group3);
group2.add(circle1);
group3.add(circle2);
var innerSVG = group1.innerSVG();
expect(innerSVG).to.match(/<g .*?class="group-two".*?>\w*<g .*?class="group-three".*?>\w*<circle .*?class="circle-two".*?>\w*<circle .*?class="circle-one".*?>/);
});
it("Element.toString", function() {
var group1 = s.group();
var circle1 = s.circle(10, 20, 30).attr({
'class': 'circle-one'
});
group1.add(circle1);
var str = group1.toString();
expect(str).to.match(/<g.*?>\w*<circle .*?class="circle-one".*?>\w*<\/g>/);
});
/* /*
Misc: Misc:
@ -413,11 +453,9 @@ describe("Element methods", function () {
Element.drag() Element.drag()
Element.undrag() Element.undrag()
Element.onDragOver()
Element.hover() Element.hover()
Element.unhover() Element.unhover()
TODO:
Element.onDragOver()
*/ */
// Helper function to simulate event triggering // Helper function to simulate event triggering
@ -557,6 +595,24 @@ describe("Element methods", function () {
expect(ended).to.be(1); expect(ended).to.be(1);
// expect(result2).to.be(circle); // TODO: Make undrag return element // expect(result2).to.be(circle); // TODO: Make undrag return element
}); });
it("Element.onDragOver", function() {
var rect1 = s.rect(0, 0, 10, 10);
var rect2 = s.rect(0, 0, 10, 10);
var draggedOver = 0;
rect1.drag(function() {}, function() {}, function() {});
rect2.onDragOver = function() {
draggedOver++;
};
expect(draggedOver).to.be(0);
triggerEvent(rect1, 'mousedown');
triggerEvent(rect1, 'mousemove');
triggerEvent(rect1, 'mouseup');
expect(draggedOver).to.be(1);
});
it("Element.hover, Element.unhover - no contexts", function() { it("Element.hover, Element.unhover - no contexts", function() {
var circle = s.circle(10, 20, 30); var circle = s.circle(10, 20, 30);
var eventIn = 0; var eventIn = 0;

View File

@ -40,3 +40,67 @@ describe("Check for Paper Creation", function () {
c.remove(); c.remove();
}); });
}); });
describe("Paper methods", function () {
/*
Paper.el
Paper.filter
Paper.gradient
Paper.image
Paper.toString
*/
var paper;
beforeEach(function () {
paper = Savage(100, 100);
});
afterEach(function () {
paper.remove();
});
it("Paper.el", function() {
var c = paper.el("circle");
expect(c.node.nodeName).to.be("circle");
expect(c.node.parentNode).to.be(paper.node);
});
it("Paper.filter", function() {
var filter = paper.filter('<feGaussianBlur stdDeviation="2"/>');
expect(filter.node.nodeName).to.be('filter');
var child = filter.node.firstChild;
expect(child).to.be.ok();
expect(child.nodeName).to.be('feGaussianBlur');
expect(child.getAttribute("stdDeviation")).to.be('2');
});
it("Paper.gradient - linear", function() {
var gradient = paper.gradient("l(0, 0, 1, 1)#000-#f00-#fff");
expect(gradient.node.nodeName).to.be('linearGradient');
expect(gradient.node.getAttribute('x1')).to.be("0");
expect(gradient.node.getAttribute('y1')).to.be("0");
expect(gradient.node.getAttribute('x2')).to.be("1");
expect(gradient.node.getAttribute('y2')).to.be("1");
var stops = gradient.node.querySelectorAll("stop");
expect(stops.length).to.be(3);
});
it("Paper.gradient - radial", function() {
var gradient = paper.gradient("r(0.3, 0.4, 0.5)#000-#fff");
expect(gradient.node.nodeName).to.be('radialGradient');
expect(gradient.node.getAttribute('cx')).to.be("0.3");
expect(gradient.node.getAttribute('cy')).to.be("0.4");
expect(gradient.node.getAttribute('r')).to.be("0.5");
var stops = gradient.node.querySelectorAll("stop");
expect(stops.length).to.be(2);
});
it("Paper.image", function() {
var image = paper.image('#', 10, 20, 30, 40);
var img = document.querySelector("image");
expect(img).to.not.be(null);
expect(img.getAttribute("x")).to.be("10");
expect(img.getAttribute("y")).to.be("20");
expect(img.getAttribute("width")).to.be("30");
expect(img.getAttribute("height")).to.be("40");
});
it("Paper.toString", function() {
paper.circle(10, 20, 30);
var str = paper.toString();
expect(str).to.match(/.*?<svg.*?>.*?<circle.*?<\/svg>/);
});
});

View File

@ -0,0 +1 @@
success

52
test/savage-tests.js Normal file
View File

@ -0,0 +1,52 @@
describe("Savage methods", function () {
it("Savage.Matrix - six params", function () {
var matrix = new Savage.Matrix(1, 2, 3, 4, 5, 6);
expect(matrix).to.eql({
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
f: 6
});
});
it("Savage.Matrix - SVGMatrix param", function () {
var svgMatrix = new Savage(10, 10).node.createSVGMatrix();
var matrix = new Savage.Matrix(svgMatrix);
expect(matrix).to.eql({
a: 1,
b: 0,
c: 0,
d: 1,
e: 0,
f: 0
});
});
it("Savage.ajax - no postData", function(done) {
var xhr = Savage.ajax('./res/file-for-ajax.txt', function(xhr) {
var responseText = xhr.responseText;
expect(responseText).to.be('success');
expect(this.isContext).to.be(true);
done();
}, {'isContext': true});
expect(xhr).to.be.an('object');
});
it("Savage.ajax - with object postData", function(done) {
var xhr = Savage.ajax('./res/file-for-ajax.txt', {foo: 'bar'}, function(xhr) {
var responseText = xhr.responseText;
expect(responseText).to.be('success');
expect(this.isContext).to.be(true);
done();
}, {'isContext': true});
expect(xhr).to.be.an('object');
});
it("Savage.ajax - with string postData", function(done) {
var xhr = Savage.ajax('./res/file-for-ajax.txt', 'foo=bar', function(xhr) {
var responseText = xhr.responseText;
expect(responseText).to.be('success');
expect(this.isContext).to.be(true);
done();
}, {'isContext': true});
expect(xhr).to.be.an('object');
});
});

View File

@ -33,6 +33,7 @@
<script>mocha.setup("bdd");</script> <script>mocha.setup("bdd");</script>
<script src="system.js"></script> <script src="system.js"></script>
<script src="paper.js"></script> <script src="paper.js"></script>
<script src="savage-tests.js"></script>
<script src="primitives.js"></script> <script src="primitives.js"></script>
<script src="colors.js"></script> <script src="colors.js"></script>
<script src="attrs.js"></script> <script src="attrs.js"></script>