summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-03-29 16:10:36 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-03-29 16:10:36 +0200
commitbb38273b6a2efd3795480cc36fa0ad0d67b73997 (patch)
tree146cc8f4fddb6d1203126546e0610077b42f4588 /spec
parentebf7436261c8fc3197a48dc6b21dff9edd9271e3 (diff)
downloadsvg.js-bb38273b6a2efd3795480cc36fa0ad0d67b73997.tar.gz
svg.js-bb38273b6a2efd3795480cc36fa0ad0d67b73997.zip
clear does not remove parser anymore
make test work in svg documents
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/arrange.js84
-rw-r--r--spec/spec/bare.js12
-rw-r--r--spec/spec/container.js28
-rw-r--r--spec/spec/element.js49
-rw-r--r--spec/spec/helper.js7
-rw-r--r--spec/spec/svg.js54
6 files changed, 138 insertions, 96 deletions
diff --git a/spec/spec/arrange.js b/spec/spec/arrange.js
index 07f87d1..3424b2a 100644
--- a/spec/spec/arrange.js
+++ b/spec/spec/arrange.js
@@ -11,17 +11,17 @@ describe('Arrange', function() {
describe('siblings()', function() {
it('returns all siblings of targeted element', function() {
- expect(e1.siblings().length).toBe(3)
- expect([e1,e2,e3]).toEqual(e2.siblings())
+ expect(e1.siblings().length).toBe(3+parserInDoc)
+ expect(parser.concat([e1,e2,e3])).toEqual(e2.siblings())
})
})
describe('position()', function() {
it('returns the index position within it\'s parent', function() {
- expect(e1.siblings().length).toBe(3)
- expect(e1.position()).toBe(0)
- expect(e2.position()).toBe(1)
- expect(e3.position()).toBe(2)
+ expect(e1.siblings().length).toBe(3+parserInDoc)
+ expect(e1.position()).toBe(0+parserInDoc)
+ expect(e2.position()).toBe(1+parserInDoc)
+ expect(e3.position()).toBe(2+parserInDoc)
})
})
@@ -35,7 +35,7 @@ describe('Arrange', function() {
describe('previous()', function() {
it('returns the previous sibling within the parent element', function() {
- expect(e1.previous()).toBe(undefined)
+ expect(e1.previous()).toBe(parser[0])
expect(e2.previous()).toBe(e1)
expect(e3.previous()).toBe(e2)
})
@@ -47,35 +47,39 @@ describe('Arrange', function() {
})
it('moves the element one step forward within its parent', function() {
e1.forward()
- expect(e1.position()).toBe(1)
- expect(e2.position()).toBe(0)
- expect(e3.position()).toBe(2)
+ expect(e1.position()).toBe(1+parserInDoc)
+ expect(e2.position()).toBe(0+parserInDoc)
+ expect(e3.position()).toBe(2+parserInDoc)
})
it('keeps the last element at the same position', function() {
e3.forward()
- expect(e3.position()).toBe(2)
+ expect(e3.position()).toBe(2+parserInDoc)
})
it('keeps the defs on top of the stack', function() {
draw.defs()
e3.forward()
- expect(draw.node.childNodes[2]).toBe(e3.node)
- expect(draw.node.childNodes[3]).toBe(draw.defs().node)
+ expect(draw.node.childNodes[2+parserInDoc]).toBe(e3.node)
+ expect(draw.node.childNodes[3+parserInDoc]).toBe(draw.defs().node)
})
})
describe('backward()', function() {
it('returns the element itself', function() {
- expect(e1.backward()).toBe(e1)
+ if(parserInDoc){
+ expect(parser[0].backward()).toBe(parser[0])
+ }else{
+ expect(e1.backward()).toBe(e1)
+ }
})
it('moves the element one step backwards within its parent', function() {
e3.backward()
- expect(e1.position()).toBe(0)
- expect(e2.position()).toBe(2)
- expect(e3.position()).toBe(1)
+ expect(e1.position()).toBe(0+parserInDoc)
+ expect(e2.position()).toBe(2+parserInDoc)
+ expect(e3.position()).toBe(1+parserInDoc)
})
it('keeps the first element at the same position', function() {
e3.backward()
- expect(e1.position()).toBe(0)
+ expect(e1.position()).toBe(0+parserInDoc)
})
})
@@ -85,18 +89,18 @@ describe('Arrange', function() {
})
it('moves the element to the top of the stack within its parent', function() {
e1.front()
- expect(e1.position()).toBe(2)
- expect(e2.position()).toBe(0)
- expect(e3.position()).toBe(1)
+ expect(e1.position()).toBe(2+parserInDoc)
+ expect(e2.position()).toBe(0+parserInDoc)
+ expect(e3.position()).toBe(1+parserInDoc)
})
it('keeps the last element at the same position', function() {
e3.front()
- expect(e3.position()).toBe(2)
+ expect(e3.position()).toBe(2+parserInDoc)
})
it('keeps the defs on top of the stack', function() {
e1.front()
- expect(draw.node.childNodes[2]).toBe(e1.node)
- expect(draw.node.childNodes[3]).toBe(draw.defs().node)
+ expect(draw.node.childNodes[2+parserInDoc]).toBe(e1.node)
+ expect(draw.node.childNodes[3+parserInDoc]).toBe(draw.defs().node)
})
})
@@ -106,8 +110,8 @@ describe('Arrange', function() {
})
it('moves the element to the bottom of the stack within its parent', function() {
e3.back()
- expect(e1.position()).toBe(1)
- expect(e2.position()).toBe(2)
+ expect(e1.position()).toBe(1+parserInDoc)
+ expect(e2.position()).toBe(2+parserInDoc)
expect(e3.position()).toBe(0)
})
it('keeps the first element at the same position', function() {
@@ -122,9 +126,9 @@ describe('Arrange', function() {
})
it('inserts a given element before the targeted element', function() {
e3.before(e1)
- expect(e1.position()).toBe(1)
- expect(e2.position()).toBe(0)
- expect(e3.position()).toBe(2)
+ expect(e1.position()).toBe(1+parserInDoc)
+ expect(e2.position()).toBe(0+parserInDoc)
+ expect(e3.position()).toBe(2+parserInDoc)
})
it('moves elements between containers', function() {
var group = draw.group()
@@ -133,10 +137,10 @@ describe('Arrange', function() {
, e6 = group.rect(80,120)
e2.before(e5)
- expect(e1.position()).toBe(0)
- expect(e2.position()).toBe(2)
- expect(e3.position()).toBe(3)
- expect(e5.position()).toBe(1)
+ expect(e1.position()).toBe(0+parserInDoc)
+ expect(e2.position()).toBe(2+parserInDoc)
+ expect(e3.position()).toBe(3+parserInDoc)
+ expect(e5.position()).toBe(1+parserInDoc)
})
})
@@ -146,9 +150,9 @@ describe('Arrange', function() {
})
it('inserts a given element after the targeted element', function() {
e3.after(e1)
- expect(e1.position()).toBe(2)
- expect(e2.position()).toBe(0)
- expect(e3.position()).toBe(1)
+ expect(e1.position()).toBe(2+parserInDoc)
+ expect(e2.position()).toBe(0+parserInDoc)
+ expect(e3.position()).toBe(1+parserInDoc)
})
it('moves elements between containers', function() {
var group = draw.group()
@@ -157,10 +161,10 @@ describe('Arrange', function() {
, e6 = group.rect(80,120)
e2.after(e5)
- expect(e1.position()).toBe(0)
- expect(e2.position()).toBe(1)
- expect(e3.position()).toBe(3)
- expect(e5.position()).toBe(2)
+ expect(e1.position()).toBe(0+parserInDoc)
+ expect(e2.position()).toBe(1+parserInDoc)
+ expect(e3.position()).toBe(3+parserInDoc)
+ expect(e5.position()).toBe(2+parserInDoc)
})
})
diff --git a/spec/spec/bare.js b/spec/spec/bare.js
index 9dbb8c2..0488bbd 100644
--- a/spec/spec/bare.js
+++ b/spec/spec/bare.js
@@ -22,12 +22,20 @@ describe('Bare', function() {
describe('words()', function() {
it('inserts plain text in a node', function() {
var element = draw.element('title').words('These are some words.').id(null)
- expect(element.svg()).toBe('<title>These are some words.</title>')
+ var result = element.svg()
+ expect(
+ result == '<title>These are some words.</title>'
+ || result == '<title xmlns="http://www.w3.org/2000/svg">These are some words.</title>'
+ ).toBe(true)
})
it('removes all nodes before adding words', function() {
var element = draw.element('title').words('These are some words.').id(null)
element.words('These are some words.')
- expect(element.svg()).toBe('<title>These are some words.</title>')
+ var result = element.svg()
+ expect(
+ result == '<title>These are some words.</title>'
+ || result == '<title xmlns="http://www.w3.org/2000/svg">These are some words.</title>'
+ ).toBe(true)
})
})
})
diff --git a/spec/spec/container.js b/spec/spec/container.js
index a027c5e..b9fabe7 100644
--- a/spec/spec/container.js
+++ b/spec/spec/container.js
@@ -205,10 +205,10 @@ describe('Container', function() {
})
describe('clear()', function() {
- it('removes all children', function() {
+ it('removes all children except the parser if present', function() {
draw.rect(100,100)
draw.clear()
- expect(draw.children().length).toBe(0)
+ expect(draw.children().length).toBe(parserInDoc)
})
it('creates a new defs node', function() {
var oldDefs = draw.defs()
@@ -234,7 +234,7 @@ describe('Container', function() {
draw.each(function() {
children.push(this.type)
})
- expect(children).toEqual(['rect', 'ellipse', 'polygon'])
+ expect(children).toEqual((parserInDoc ? [parser[0].type] : []).concat(['rect', 'ellipse', 'polygon']))
})
it('should only include the its own children', function() {
var children = []
@@ -268,7 +268,7 @@ describe('Container', function() {
children.push(this)
}, true)
- expect(children.length).toEqual(draw.children().length + group.children().length)
+ expect(children.length).toEqual(draw.children().length + group.children().length + (parserInDoc ? parser[0].children().length : 0))
})
})
@@ -278,23 +278,23 @@ describe('Container', function() {
var rect = draw.rect(100,100)
var circle = draw.circle(100)
var line = draw.line(0,0,100,100)
- expect(draw.get(0)).toBe(rect)
- expect(draw.get(1)).toBe(circle)
- expect(draw.get(2)).toBe(line)
- expect(draw.get(3)).toBeNull()
+ expect(draw.get(0+parserInDoc)).toBe(rect)
+ expect(draw.get(1+parserInDoc)).toBe(circle)
+ expect(draw.get(2+parserInDoc)).toBe(line)
+ expect(draw.get(3+parserInDoc)).toBeNull()
})
})
-
+
describe('first()', function() {
it('gets the first child', function() {
draw.clear()
var rect = draw.rect(100,100)
var circle = draw.circle(100)
var line = draw.line(0,0,100,100)
- expect(draw.first()).toBe(rect)
+ expect(draw.first()).toBe(parserInDoc ? parser[0] : rect)
})
})
-
+
describe('last()', function() {
it('gets the last child', function() {
draw.clear()
@@ -325,9 +325,9 @@ describe('Container', function() {
var circle = draw.circle(100)
var group = draw.group()
var line = group.line(0,0,100,100)
- expect(draw.index(rect)).toBe(0)
- expect(draw.index(circle)).toBe(1)
- expect(draw.index(group)).toBe(2)
+ expect(draw.index(rect)).toBe(0+parserInDoc)
+ expect(draw.index(circle)).toBe(1+parserInDoc)
+ expect(draw.index(group)).toBe(2+parserInDoc)
expect(draw.index(line)).toBe(-1)
expect(group.index(line)).toBe(0)
})
diff --git a/spec/spec/element.js b/spec/spec/element.js
index 1f3f107..8846474 100644
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -215,7 +215,7 @@ describe('Element', function() {
rect.transform({ scaleY: 3 })
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([1,0,0,3,0,-100])
})
-
+
it('performs an absolute scale by default', function() {
rect.transform({ scale: 3 }).transform({ scale: 0.5 })
expect(window.matrixStringToArray(rect.node.getAttribute('transform'))).toEqual([0.5,0,0,0.5,25,25])
@@ -460,7 +460,7 @@ describe('Element', function() {
}))
})
- it('ungroups everything to the doc root when called on SVG.Doc / does not ungroup defs', function() {
+ it('ungroups everything to the doc root when called on SVG.Doc / does not ungroup defs/parser', function() {
draw.ungroup()
expect(rect1.parent()).toBe(draw)
expect(rect2.parent()).toBe(draw)
@@ -476,10 +476,10 @@ describe('Element', function() {
a:0.5, b:0, c:0, d:0.5, e:45, f:45
}))
- expect(draw.children().length).toBe(3) // 2 * rect + defs
+ expect(draw.children().length).toBe(3+parserInDoc) // 2 * rect + defs
})
})
-
+
describe('flatten()', function() {
it('redirects the call to ungroup()', function() {
spyOn(draw, 'ungroup')
@@ -819,8 +819,15 @@ describe('Element', function() {
// Test for different browsers namely Firefox and Chrome
expect(
+ // IE
toBeTested === '<svg xmlns:svgjs="http://svgjs.com/svgjs" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" xmlns="http://www.w3.org/2000/svg" height="100" width="100" id="' + draw.id() + '"><rect height="100" width="100"></rect><circle fill="#ff0066" cy="50" cx="50" r="50"></circle></svg>'
- || toBeTested === '<svg id="' + draw.id() + '" width="100" height="100" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs"><rect width="100" height="100"></rect><circle r="50" cx="50" cy="50" fill="#ff0066"></circle></svg>').toBeTruthy()
+
+ // Firefox
+ || toBeTested === '<svg id="' + draw.id() + '" width="100" height="100" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs"><rect width="100" height="100"></rect><circle r="50" cx="50" cy="50" fill="#ff0066"></circle></svg>'
+
+ // svgdom
+ || toBeTested === '<svg id="' + draw.id() + '" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="100" height="100"><svg id="SvgjsSvg1002" width="2" height="0" style="overflow: hidden; top: -100%; left: -100%; position: absolute; opacity: 0"><polyline id="SvgjsPolyline1003" points="10,10 20,10 30,10"></polyline><path id="SvgjsPath1004" d="M80 80A45 45 0 0 0 125 125L125 80Z "></path></svg><rect width="100" height="100"></rect><circle r="50" cx="50" cy="50" fill="#ff0066"></circle></svg>'
+ ).toBeTruthy()
})
it('returns partial raw svg when called on a sub group', function() {
@@ -832,7 +839,9 @@ describe('Element', function() {
expect(
toBeTested === '<g><rect width="100" height="100"></rect><circle r="50" cx="50" cy="50" fill="#ff0066"></circle></g>'
- || toBeTested === '<g><rect height="100" width="100"></rect><circle fill="#ff0066" cy="50" cx="50" r="50"></circle></g>').toBeTruthy()
+ || toBeTested === '<g><rect height="100" width="100"></rect><circle fill="#ff0066" cy="50" cx="50" r="50"></circle></g>'
+ || toBeTested === '<g xmlns="http://www.w3.org/2000/svg"><rect width="100" height="100"></rect><circle r="50" cx="50" cy="50" fill="#ff0066"></circle></g>'
+ ).toBeTruthy()
})
it('returns a single element when called on an element', function() {
var group = draw.group().id(null)
@@ -842,31 +851,37 @@ describe('Element', function() {
expect(
toBeTested === '<circle r="50" cx="50" cy="50" fill="#ff0066"></circle>'
- || toBeTested === '<circle fill="#ff0066" cy="50" cx="50" r="50"></circle>').toBeTruthy()
+ || toBeTested === '<circle fill="#ff0066" cy="50" cx="50" r="50"></circle>'
+ || toBeTested === '<circle xmlns="http://www.w3.org/2000/svg" r="50" cx="50" cy="50" fill="#ff0066"></circle>'
+ ).toBeTruthy()
})
})
describe('with raw svg given', function() {
it('imports a full svg document', function() {
draw.svg('<svg id="SvgjsSvg1000" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 50 50"><rect id="SvgjsRect1183" width="100" height="100"></rect><circle id="SvgjsCircle1184" r="50" cx="25" cy="25" fill="#ff0066"></circle></svg>')
- expect(draw.get(0).type).toBe('svg')
- expect(draw.get(0).children().length).toBe(2)
- expect(draw.get(0).get(0).type).toBe('rect')
- expect(draw.get(0).get(1).type).toBe('circle')
- expect(draw.get(0).get(1).attr('fill')).toBe('#ff0066')
+
+ expect(draw.get(0+parserInDoc).type).toBe('svg')
+ expect(draw.get(0+parserInDoc).children().length).toBe(2)
+ expect(draw.get(0+parserInDoc).get(0).type).toBe('rect')
+ expect(draw.get(0+parserInDoc).get(1).type).toBe('circle')
+ expect(draw.get(0+parserInDoc).get(1).attr('fill')).toBe('#ff0066')
})
it('imports partial svg content', function() {
draw.svg('<g id="SvgjsG1185"><rect id="SvgjsRect1186" width="100" height="100"></rect><circle id="SvgjsCircle1187" r="50" cx="25" cy="25" fill="#ff0066"></circle></g>')
- expect(draw.get(0).type).toBe('g')
- expect(draw.get(0).get(0).type).toBe('rect')
- expect(draw.get(0).get(1).type).toBe('circle')
- expect(draw.get(0).get(1).attr('fill')).toBe('#ff0066')
+ expect(draw.get(0+parserInDoc).type).toBe('g')
+ expect(draw.get(0+parserInDoc).get(0).type).toBe('rect')
+ expect(draw.get(0+parserInDoc).get(1).type).toBe('circle')
+ expect(draw.get(0+parserInDoc).get(1).attr('fill')).toBe('#ff0066')
})
it('does not import on single elements, even with an argument it acts as a getter', function() {
var rect = draw.rect(100,100).id(null)
, result = rect.svg('<circle r="300"></rect>')
+
expect(
result === '<rect width="100" height="100"></rect>'
- || result === '<rect height="100" width="100"></rect>').toBeTruthy()
+ || result === '<rect height="100" width="100"></rect>'
+ || result === '<rect xmlns="http://www.w3.org/2000/svg" width="100" height="100"></rect>'
+ ).toBeTruthy()
})
})
})
diff --git a/spec/spec/helper.js b/spec/spec/helper.js
index fb0e50d..e23778f 100644
--- a/spec/spec/helper.js
+++ b/spec/spec/helper.js
@@ -1,12 +1,15 @@
// create canavs
//var drawing, window = window, document = document, SVG = SVG
+parserInDoc = false
+
if(typeof exports === 'object'){
window = require('../../../svgdom/dom.js')
SVG = require('../../dist/svg.js')
document = window.document
drawing = document.documentElement
imageUrl = 'spec/fixtures/pixel.png'
+ parserInDoc = true
function tag(name, attrs, children) {
var el = document.createElement(name)
@@ -130,9 +133,13 @@ if(typeof exports === 'object'){
document.getElementsByTagName('body')[0].appendChild(drawing)
imageUrl = 'fixtures/pixel.png'
}
+
+parserInDoc |= 0
drawing.id = 'drawing'
draw = SVG(drawing).size(100,100)
+parser = parserInDoc ? [SVG.parser.draw.instance] : []
+
// raw path data
svgPath = 'M88.006,61.994c3.203,0,6.216-1.248,8.481-3.514C98.752,56.215,100,53.203,100,50c0-3.204-1.248-6.216-3.513-8.481 c-2.266-2.265-5.278-3.513-8.481-3.513c-2.687,0-5.237,0.877-7.327,2.496h-7.746l5.479-5.479 c5.891-0.757,10.457-5.803,10.457-11.896c0-6.614-5.381-11.995-11.994-11.995c-6.093,0-11.14,4.567-11.896,10.457l-5.479,5.479 v-7.747c1.618-2.089,2.495-4.641,2.495-7.327c0-3.204-1.247-6.216-3.513-8.481C56.216,1.248,53.204,0,50,0 c-3.204,0-6.216,1.248-8.481,3.513c-2.265,2.265-3.513,5.277-3.513,8.481c0,2.686,0.877,5.237,2.495,7.327v7.747l-5.479-5.479 c-0.757-5.89-5.803-10.457-11.896-10.457c-6.614,0-11.995,5.381-11.995,11.995c0,6.093,4.567,11.139,10.458,11.896l5.479,5.479 h-7.747c-2.089-1.619-4.641-2.496-7.327-2.496c-3.204,0-6.216,1.248-8.481,3.513C1.248,43.784,0,46.796,0,50 c0,3.203,1.248,6.216,3.513,8.48c2.265,2.266,5.277,3.514,8.481,3.514c2.686,0,5.237-0.877,7.327-2.496h7.747l-5.479,5.479 c-5.891,0.757-10.458,5.804-10.458,11.896c0,6.614,5.381,11.994,11.995,11.994c6.093,0,11.139-4.566,11.896-10.457l5.479-5.479 v7.749c-3.63,4.7-3.291,11.497,1.018,15.806C43.784,98.752,46.796,100,50,100c3.204,0,6.216-1.248,8.481-3.514 c4.309-4.309,4.647-11.105,1.018-15.806v-7.749l5.479,5.479c0.757,5.891,5.804,10.457,11.896,10.457 c6.613,0,11.994-5.38,11.994-11.994c0-6.093-4.566-11.14-10.457-11.896l-5.479-5.479h7.746 C82.769,61.117,85.319,61.994,88.006,61.994z M76.874,68.354c4.705,0,8.52,3.814,8.52,8.521c0,4.705-3.814,8.52-8.52,8.52 s-8.52-3.814-8.52-8.52l-12.33-12.33V81.98c3.327,3.328,3.327,8.723,0,12.049c-3.327,3.328-8.722,3.328-12.049,0 c-3.327-3.326-3.327-8.721,0-12.049V64.544l-12.33,12.33c0,4.705-3.814,8.52-8.52,8.52s-8.52-3.814-8.52-8.52 c0-4.706,3.814-8.521,8.52-8.521l12.33-12.33H18.019c-3.327,3.328-8.722,3.328-12.049,0c-3.327-3.326-3.327-8.721,0-12.048 s8.722-3.327,12.049,0h17.438l-12.33-12.33c-4.706,0-8.52-3.814-8.52-8.52c0-4.706,3.814-8.52,8.52-8.52s8.52,3.814,8.52,8.52 l12.33,12.33V18.019c-3.327-3.327-3.327-8.722,0-12.049s8.722-3.327,12.049,0s3.327,8.722,0,12.049v17.438l12.33-12.33 c0-4.706,3.814-8.52,8.52-8.52s8.52,3.814,8.52,8.52c0,4.705-3.814,8.52-8.52,8.52l-12.33,12.33h17.438 c3.327-3.327,8.722-3.327,12.049,0s3.327,8.722,0,12.048c-3.327,3.328-8.722,3.328-12.049,0H64.544L76.874,68.354z'
diff --git a/spec/spec/svg.js b/spec/spec/svg.js
index bb6e5b5..7738b0e 100644
--- a/spec/spec/svg.js
+++ b/spec/spec/svg.js
@@ -2,49 +2,57 @@ describe('SVG', function() {
describe('()', function() {
var drawing, wrapper
-
+
beforeEach(function() {
wrapper = document.createElement('svg')
document.documentElement.appendChild(wrapper)
drawing = SVG(wrapper)
})
-
+
afterEach(function() {
wrapper.parentNode.removeChild(wrapper)
})
-
+
it('creates a new svg drawing', function() {
expect(drawing.type).toBe('svg')
})
it('creates an instance of SVG.Doc', function() {
expect(drawing instanceof SVG.Doc).toBe(true)
})
- it('sets size to 100%', function() {
- expect(drawing.width()).toBe('100%')
- expect(drawing.height()).toBe('100%')
- })
+
+ if(parserInDoc){
+ it('sets no default size in svg documents', function() {
+ expect(drawing.width()).toBe(0)
+ expect(drawing.height()).toBe(0)
+ })
+ }else{
+ it('sets size to 100% in html documents', function() {
+ expect(drawing.width()).toBe('100%')
+ expect(drawing.height()).toBe('100%')
+ })
+ }
})
-
+
describe('create()', function() {
it('creates an element with given node name and return it', function() {
var element = SVG.create('rect')
-
+
expect(element.nodeName).toBe('rect')
})
it('increases the global id sequence', function() {
var did = SVG.did
, element = SVG.create('rect')
-
+
expect(did + 1).toBe(SVG.did)
})
it('adds a unique id containing the node name', function() {
var did = SVG.did
, element = SVG.create('rect')
-
+
expect(element.getAttribute('id')).toBe('SvgjsRect' + did)
})
})
-
+
describe('extend()', function() {
it('adds all functions in the given object to the target object', function() {
SVG.extend(SVG.Rect, {
@@ -52,7 +60,7 @@ describe('SVG', function() {
return this.opacity(0.2)
}
})
-
+
expect(typeof SVG.Rect.prototype.soft).toBe('function')
expect(draw.rect(100,100).soft().attr('opacity')).toBe(0.2)
})
@@ -62,7 +70,7 @@ describe('SVG', function() {
return this.opacity(0.5)
}
})
-
+
expect(typeof SVG.Rect.prototype.soft).toBe('function')
expect(draw.rect(100,100).soft().attr('opacity')).toBe(0.5)
expect(typeof SVG.Ellipse.prototype.soft).toBe('function')
@@ -76,32 +84,32 @@ describe('SVG', function() {
return this.opacity(0.3)
}
})
-
+
expect(typeof SVG.Rect.prototype.soft).toBe('function')
expect(draw.rect(100,100).soft().attr('opacity')).toBe(0.3)
expect(typeof SVG.Bogus).toBe('undefined')
})
})
-
+
describe('prepare()', function() {
var drawing, wrapper, parser
-
+
beforeEach(function() {
wrapper = document.createElement('svg')
document.documentElement.appendChild(wrapper)
drawing = SVG(wrapper)
})
-
+
it('creates a parser element when calling SVG()', function() {
- expect(SVG.parser.draw.node.nodeName).toBe('svg')
+ expect(SVG.parser.draw.nodeName).toBe('svg')
})
it('hides the parser', function() {
- expect(window.stripped(SVG.parser.draw.node.getAttribute('style'))).toBe('overflow:hidden;top:-100%;left:-100%;position:absolute;opacity:0')
+ expect(window.stripped(SVG.parser.draw.getAttribute('style'))).toBe('overflow:hidden;top:-100%;left:-100%;position:absolute;opacity:0')
})
it('holds polyline and path', function() {
- expect(SVG.select('polyline', SVG.parser.draw.node).first().type).toBe('polyline')
- expect(SVG.select('path', SVG.parser.draw.node).first().type).toBe('path')
+ expect(SVG.select('polyline', SVG.parser.draw).first().type).toBe('polyline')
+ expect(SVG.select('path', SVG.parser.draw).first().type).toBe('path')
})
})
-
+
}) \ No newline at end of file