2013-09-05 00:29:15 +00:00
|
|
|
|
describe("Check for Paper Creation", function () {
|
|
|
|
|
it("creates simple paper 20 × 10", function () {
|
2013-09-25 05:52:57 +00:00
|
|
|
|
var s = Snap(20, 10);
|
2013-09-05 00:29:15 +00:00
|
|
|
|
var S = s.node;
|
|
|
|
|
expect(S).to.not.be(null);
|
|
|
|
|
expect(S.getAttribute("width")).to.be("20");
|
|
|
|
|
expect(S.getAttribute("height")).to.be("10");
|
|
|
|
|
s.remove();
|
|
|
|
|
});
|
|
|
|
|
it("removal of paper", function () {
|
2013-09-25 05:52:57 +00:00
|
|
|
|
var s = Snap(20, 10);
|
2013-09-05 00:29:15 +00:00
|
|
|
|
var S = s.node;
|
|
|
|
|
expect(S).to.not.be(null);
|
|
|
|
|
s.remove();
|
|
|
|
|
S = document.querySelectorAll("svg").length;
|
|
|
|
|
expect(S).to.be(1);
|
|
|
|
|
});
|
|
|
|
|
it("creates simple paper 20% × 10em", function () {
|
2013-09-25 05:52:57 +00:00
|
|
|
|
var s = Snap("20%", "10em");
|
2013-09-05 00:29:15 +00:00
|
|
|
|
var S = s.node;
|
|
|
|
|
expect(S).to.not.be(null);
|
|
|
|
|
expect(S.getAttribute("width")).to.be("20%");
|
|
|
|
|
expect(S.getAttribute("height")).to.be("10em");
|
|
|
|
|
s.remove();
|
|
|
|
|
});
|
|
|
|
|
it("converts existing SVG element to paper", function () {
|
|
|
|
|
var S = document.getElementById("svgroot");
|
2013-09-25 05:52:57 +00:00
|
|
|
|
var s = Snap(S);
|
2013-09-05 00:29:15 +00:00
|
|
|
|
expect(document.querySelector("#svgroot circle")).to.be(null);
|
|
|
|
|
var c = s.circle(10, 20, 5);
|
|
|
|
|
expect(document.querySelectorAll("#svgroot circle").length).to.be(1);
|
|
|
|
|
c.remove();
|
|
|
|
|
});
|
|
|
|
|
it("converts existing SVG element to paper (as query)", function () {
|
|
|
|
|
var S = document.getElementById("svgroot");
|
2013-09-25 05:52:57 +00:00
|
|
|
|
var s = Snap("#svgroot");
|
2013-09-05 00:29:15 +00:00
|
|
|
|
expect(document.querySelector("#svgroot circle")).to.be(null);
|
|
|
|
|
var c = s.circle(10, 20, 5);
|
|
|
|
|
expect(document.querySelectorAll("#svgroot circle").length).to.be(1);
|
|
|
|
|
c.remove();
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-09-11 22:03:34 +00:00
|
|
|
|
|
|
|
|
|
describe("Paper methods", function () {
|
|
|
|
|
/*
|
|
|
|
|
Paper.el
|
|
|
|
|
Paper.filter
|
|
|
|
|
Paper.gradient
|
|
|
|
|
Paper.image
|
|
|
|
|
Paper.toString
|
|
|
|
|
*/
|
|
|
|
|
var paper;
|
|
|
|
|
beforeEach(function () {
|
2013-09-25 05:52:57 +00:00
|
|
|
|
paper = Snap(100, 100);
|
2013-09-11 22:03:34 +00:00
|
|
|
|
});
|
|
|
|
|
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>/);
|
|
|
|
|
});
|
|
|
|
|
});
|