add more element and paper tests

master
adeveria 2013-09-11 15:03:34 -07:00
parent 9ff432a12f
commit 440f4cef94
2 changed files with 125 additions and 5 deletions

View File

@ -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(/<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:
@ -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;

View File

@ -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('<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>/);
});
});