diff options
author | wout <wout@impinc.co.uk> | 2014-02-01 14:27:31 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-02-01 14:27:31 +0100 |
commit | f047e3c3aad7920df978a2dbc758a961112c9d43 (patch) | |
tree | d97689f6563aebd823d1190cc76809073da3a449 /spec | |
parent | 745a0148c9de8c14367507eb21355604a42e84d5 (diff) | |
download | svg.js-f047e3c3aad7920df978a2dbc758a961112c9d43.tar.gz svg.js-f047e3c3aad7920df978a2dbc758a961112c9d43.zip |
Added index() method to SVG.Parent and SVG.Set
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/container.js | 27 | ||||
-rw-r--r-- | spec/spec/set.js | 11 |
2 files changed, 38 insertions, 0 deletions
diff --git a/spec/spec/container.js b/spec/spec/container.js index 47a871e..02bc4e9 100644 --- a/spec/spec/container.js +++ b/spec/spec/container.js @@ -287,7 +287,34 @@ describe('Container', function() { expect(draw.get(3)).toBe(undefined) }) }) + + describe('has()', function() { + it('determines if a given element is a child of the parent', function() { + var rect = draw.rect(100,100) + var circle = draw.circle(100) + var group = draw.group() + var line = group.line(0,0,100,100) + expect(draw.has(rect)).toBe(true) + expect(draw.has(circle)).toBe(true) + expect(draw.has(group)).toBe(true) + expect(draw.has(line)).toBe(false) + expect(group.has(line)).toBe(true) + }) + }) + describe('index()', function() { + it('determines the index of given element', function() { + var rect = draw.rect(100,100) + 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(line)).toBe(-1) + expect(group.index(line)).toBe(0) + }) + }) }) diff --git a/spec/spec/set.js b/spec/spec/set.js index b6199d7..0eb822d 100644 --- a/spec/spec/set.js +++ b/spec/spec/set.js @@ -88,6 +88,17 @@ describe('Set', function() { }) }) + describe('index()', function() { + it('returns the index of a given element within the set', function() { + set.add(e1).add(e2).add(e3).add(e5) + expect(set.index(e1)).toBe(0) + expect(set.index(e2)).toBe(1) + expect(set.index(e3)).toBe(2) + expect(set.index(e4)).toBe(-1) + expect(set.index(e5)).toBe(3) + }) + }) + describe('valueOf()', function() { it('returns the members array', function() { set.add(e1) |