diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-10 19:24:08 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-10 19:24:08 +1000 |
commit | 27b9c7a7f605816cd8d1ac75c1d65cc47fabafca (patch) | |
tree | 49350a3263c361fdf67c8b88973d5e52f15960d0 | |
parent | e497f9ccfb3107ba5c0991db5e1e07a2297948e6 (diff) | |
download | svg.js-27b9c7a7f605816cd8d1ac75c1d65cc47fabafca.tar.gz svg.js-27b9c7a7f605816cd8d1ac75c1d65cc47fabafca.zip |
added tests to cover all branches
-rw-r--r-- | spec/spec/elements/Circle.js | 7 | ||||
-rw-r--r-- | spec/spec/elements/Dom.js | 8 | ||||
-rw-r--r-- | spec/spec/elements/Ellipse.js | 16 | ||||
-rw-r--r-- | spec/spec/elements/G.js | 11 | ||||
-rw-r--r-- | spec/spec/elements/Line.js | 7 | ||||
-rw-r--r-- | spec/spec/elements/Marker.js | 27 | ||||
-rw-r--r-- | spec/spec/elements/Stop.js | 20 | ||||
-rw-r--r-- | spec/spec/elements/Text.js | 21 | ||||
-rw-r--r-- | spec/spec/elements/TextPath.js | 16 |
9 files changed, 132 insertions, 1 deletions
diff --git a/spec/spec/elements/Circle.js b/spec/spec/elements/Circle.js index e9b8b56..0b339f1 100644 --- a/spec/spec/elements/Circle.js +++ b/spec/spec/elements/Circle.js @@ -61,6 +61,13 @@ describe('Circle.js', () => { expect(circle.attr('r')).toBe(25) expect(circle).toEqual(any(Circle)) }) + + it('defaults to zero size', () => { + const group = new G() + const circle = group.circle() + expect(circle.attr('r')).toBe(0) + expect(circle).toEqual(any(Circle)) + }) }) }) }) diff --git a/spec/spec/elements/Dom.js b/spec/spec/elements/Dom.js index 3227ba1..2310473 100644 --- a/spec/spec/elements/Dom.js +++ b/spec/spec/elements/Dom.js @@ -48,6 +48,14 @@ describe('Dom.js', function () { expect(g.get(1)).toBe(rect) }) + it('does nothing if element is already the element at that position', () => { + const g = new G() + g.rect(100, 100) + const rect = g.rect(100, 100) + g.add(rect, 1) + expect(g.get(1)).toBe(rect) + }) + it('handles svg strings', () => { const g = new G() g.add('<rect>') diff --git a/spec/spec/elements/Ellipse.js b/spec/spec/elements/Ellipse.js index 56e5d11..2172669 100644 --- a/spec/spec/elements/Ellipse.js +++ b/spec/spec/elements/Ellipse.js @@ -55,6 +55,22 @@ describe('Ellipse.js', () => { expect(ellipse.attr('ry')).toBe(25) expect(ellipse).toEqual(any(Ellipse)) }) + + it('defaults to same radius with one argument', () => { + const group = new G() + const ellipse = group.ellipse(50) + expect(ellipse.attr('rx')).toBe(25) + expect(ellipse.attr('ry')).toBe(25) + expect(ellipse).toEqual(any(Ellipse)) + }) + + it('defaults to zero radius with no argument', () => { + const group = new G() + const ellipse = group.ellipse() + expect(ellipse.attr('rx')).toBe(0) + expect(ellipse.attr('ry')).toBe(0) + expect(ellipse).toEqual(any(Ellipse)) + }) }) }) }) diff --git a/spec/spec/elements/G.js b/spec/spec/elements/G.js index b6850d5..e9f803f 100644 --- a/spec/spec/elements/G.js +++ b/spec/spec/elements/G.js @@ -96,6 +96,17 @@ describe('G.js', () => { g.move(100, 150) expect(g.dmove).toHaveBeenCalledWith(-11, -73) }) + + it('defaults to x=0 and y=0', () => { + const canvas = SVG().addTo(container) + const g = canvas.group() + g.rect(100, 200).move(111, 223) + + spyOn(g, 'dmove') + + g.move() + expect(g.dmove).toHaveBeenCalledWith(-111, -223) + }) }) describe('x()', () => { diff --git a/spec/spec/elements/Line.js b/spec/spec/elements/Line.js index ebb2406..9f25937 100644 --- a/spec/spec/elements/Line.js +++ b/spec/spec/elements/Line.js @@ -123,6 +123,13 @@ describe('Line.js', () => { expect(line.array()).toEqual([ [ 1, 2 ], [ 3, 4 ] ]) expect(line).toEqual(any(Line)) }) + + it('defaults to zero line', () => { + const group = new G() + const line = group.line() + expect(line.array()).toEqual([ [ 0, 0 ], [ 0, 0 ] ]) + expect(line).toEqual(any(Line)) + }) }) }) }) diff --git a/spec/spec/elements/Marker.js b/spec/spec/elements/Marker.js index 129bbc2..d2726a9 100644 --- a/spec/spec/elements/Marker.js +++ b/spec/spec/elements/Marker.js @@ -93,7 +93,25 @@ describe('Marker.js', function () { }) }) - describe('Path', () => { + describe('Defs', () => { + describe('marker()', () => { + it('creates a marker in the defs and sets all attributes', () => { + const canvas = SVG() + const defs = canvas.defs() + const marker = defs.marker(10, 12) + expect(marker.attr('refX')).toBe(5) + expect(marker.attr('refY')).toBe(6) + expect(marker.attr('markerWidth')).toBe(10) + expect(marker.attr('markerHeight')).toBe(12) + expect(marker.attr('viewBox')).toBe('0 0 10 12') + expect(marker.attr('orient')).toBe('auto') + expect(marker).toEqual(any(Marker)) + expect(defs.children()).toEqual([ marker ]) + }) + }) + }) + + describe('marker', () => { var path, marker, canvas beforeEach(() => { @@ -140,6 +158,13 @@ describe('Marker.js', function () { expect(path.node.getAttribute('marker-end')).toBe(marker.toString()) }) + it('creates a marker and applies it to the marker-end attribute', () => { + path.marker('all', 10, 12) + marker = path.reference('marker') + + expect(path.node.getAttribute('marker')).toBe(marker.toString()) + }) + it('accepts an instance of an existing marker element as the second argument', () => { marker = new Marker().size(11, 11) path.marker('mid', marker) diff --git a/spec/spec/elements/Stop.js b/spec/spec/elements/Stop.js index b6f331d..e2ce2a8 100644 --- a/spec/spec/elements/Stop.js +++ b/spec/spec/elements/Stop.js @@ -31,6 +31,26 @@ describe('Stop.js', () => { expect(stop.attr('stop-color')).toBe('#ffffff') expect(stop.attr('stop-opacity')).toBe(0.5) }) + + it('sets efault values if not all supplied', () => { + let stop = new Stop() + stop.update({ offset: 0.1 }) + expect(stop.attr('offset')).toBe(0.1) + expect(stop.attr('stop-color')).toBe('#000000') + expect(stop.attr('stop-opacity')).toBe(1) + + stop = new Stop() + stop.update({ color: '#ffffff' }) + expect(stop.attr('offset')).toBe(0) + expect(stop.attr('stop-color')).toBe('#ffffff') + expect(stop.attr('stop-opacity')).toBe(1) + + stop = new Stop() + stop.update({ opacity: 0.5 }) + expect(stop.attr('offset')).toBe(0) + expect(stop.attr('stop-color')).toBe('#000000') + expect(stop.attr('stop-opacity')).toBe(0.5) + }) }) describe('Gradient', () => { diff --git a/spec/spec/elements/Text.js b/spec/spec/elements/Text.js index f28c256..e1a74d2 100644 --- a/spec/spec/elements/Text.js +++ b/spec/spec/elements/Text.js @@ -125,6 +125,13 @@ describe('Text.js', () => { expect(text.dom.leading.value).toBe(3) expect(text.dom.leading.unit).toBe('px') }) + + it('uses a leading of 1.3 when no leading is set or 0', () => { + const text = new Text() + text.setData({ leading: 0 }) + + expect(text.dom.leading.value).toBe(1.3) + }) }) describe('Container', () => { @@ -135,6 +142,13 @@ describe('Text.js', () => { expect(text).toEqual(any(Text)) expect(text.text()).toBe('Hello World\nHow is it\ngoing') }) + + it('defaults to empty string', () => { + const group = new G() + const text = group.text() + expect(text).toEqual(any(Text)) + expect(text.text()).toBe('') + }) }) describe('plain()', () => { @@ -144,6 +158,13 @@ describe('Text.js', () => { expect(text).toEqual(any(Text)) expect(text.node.childNodes[0].data).toBe('A piece') }) + + it('defaults to empty string', () => { + const group = new G() + const text = group.plain() + expect(text).toEqual(any(Text)) + expect(text.node.childNodes[0].data).toBe('') + }) }) }) }) diff --git a/spec/spec/elements/TextPath.js b/spec/spec/elements/TextPath.js index 213b867..41c2357 100644 --- a/spec/spec/elements/TextPath.js +++ b/spec/spec/elements/TextPath.js @@ -53,6 +53,11 @@ describe('TextPath.js', () => { expect(textPath.plot()).toBe(textPath.array()) expect(textPath.plot()).not.toBe(null) }) + + it('does nothingif no path is attached as track', () => { + const textPath = Object.freeze(new TextPath()) + expect(textPath.plot('M0 0')).toBe(textPath) + }) }) describe('Container', () => { @@ -95,6 +100,17 @@ describe('TextPath.js', () => { const textPath = text.path(path) expect(textPath.reference('href')).toBe(path) }) + + it('imports all nodes from the text by default', () => { + const children = text.children() + const textPath = text.path(path) + expect(textPath.children()).toEqual(children) + }) + + it('does not import all nodes from the text when second parameter false', () => { + const textPath = text.path(path, false) + expect(textPath.children()).toEqual([]) + }) }) describe('textPath()', () => { |