diff --git a/test/.DS_Store b/test/.DS_Store index ea2da09..217a11e 100644 Binary files a/test/.DS_Store and b/test/.DS_Store differ diff --git a/test/element.js b/test/element.js index 62b02da..1524b76 100644 --- a/test/element.js +++ b/test/element.js @@ -112,8 +112,7 @@ describe("Element methods", function () { expect(rect.node.parentNode).to.be(s.node); var result = rect.remove(); 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.getSubpath() Element.getTotalLength() + Element.innerSVG() + Element.toString() */ it("Element.attr - get", function() { @@ -147,6 +148,11 @@ describe("Element methods", function () { expect(cy).to.be("2"); 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() { var circle = s.circle(10, 20, 30); circle.data("foo", "bar"); @@ -226,6 +232,40 @@ describe("Element methods", function () { var path = s.path("M0,0 100,0"); 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(/\w*\w*\w*/); + }); + 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(/\w*\w*<\/g>/); + }); /* Misc: @@ -413,11 +453,9 @@ describe("Element methods", function () { Element.drag() Element.undrag() + Element.onDragOver() Element.hover() Element.unhover() - - TODO: - Element.onDragOver() */ // Helper function to simulate event triggering @@ -557,6 +595,24 @@ describe("Element methods", function () { expect(ended).to.be(1); // 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() { var circle = s.circle(10, 20, 30); var eventIn = 0; diff --git a/test/paper.js b/test/paper.js index a3d68e9..2112334 100644 --- a/test/paper.js +++ b/test/paper.js @@ -40,3 +40,67 @@ describe("Check for Paper Creation", function () { 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(''); + 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(/.*?.*?/); + }); +}); \ No newline at end of file diff --git a/test/res/file-for-ajax.txt b/test/res/file-for-ajax.txt new file mode 100644 index 0000000..0f0c913 --- /dev/null +++ b/test/res/file-for-ajax.txt @@ -0,0 +1 @@ +success \ No newline at end of file diff --git a/test/savage-tests.js b/test/savage-tests.js new file mode 100644 index 0000000..071d4d7 --- /dev/null +++ b/test/savage-tests.js @@ -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'); + }); +}); \ No newline at end of file diff --git a/test/test.html b/test/test.html index 304a848..322e982 100644 --- a/test/test.html +++ b/test/test.html @@ -33,6 +33,7 @@ +