diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2019-01-14 11:01:25 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2019-01-14 11:01:25 +0100 |
commit | aec779cb019b5ad1c2ea709d9bf8e93d3d1e0c87 (patch) | |
tree | 41ec3b5c369374c33750091d291320aa3de8bc7c /spec | |
parent | 1388b1f67b18cb2bc561840079f981253fa1643e (diff) | |
download | svg.js-aec779cb019b5ad1c2ea709d9bf8e93d3d1e0c87.tar.gz svg.js-aec779cb019b5ad1c2ea709d9bf8e93d3d1e0c87.zip |
fixed `textPath()` and `path().text()`
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/textpath.js | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/spec/spec/textpath.js b/spec/spec/textpath.js index 8a3d4c2..9d4577f 100644 --- a/spec/spec/textpath.js +++ b/spec/spec/textpath.js @@ -13,6 +13,25 @@ describe('TextPath', function() { draw.clear() }) + describe('textPath()', function () { + it ('creates a new textPath and uses text and path', function () { + expect(draw.textPath(txt, data)).toEqual(jasmine.any(SVG.TextPath)) + }) + + it ('reuses text and path instances if possible', function () { + const textPath = draw.textPath(text, path) + expect(text.find('textPath')[0]).toBe(textPath) + expect(textPath.reference('href')).toBe(path) + }) + + it ('passes the text into textPath and not text', function () { + const tspan = text.first() + const textPath = draw.textPath(text, path) + expect(textPath.first()).toBe(tspan) + expect(text.first()).toBe(textPath) + }) + }) + describe('text().path()', function() { it('returns an instance of TextPath', function() { expect(text.path(data) instanceof SVG.TextPath).toBe(true) @@ -21,6 +40,10 @@ describe('TextPath', function() { text.path(data) expect(text.node.querySelector('textPath')).not.toBe(null) }) + it('references the passed path', function () { + const textPath = text.path(path) + expect(textPath.reference('href')).toBe(path) + }) }) describe('path().text()', function() { @@ -28,13 +51,19 @@ describe('TextPath', function() { expect(path.text(txt) instanceof SVG.TextPath).toBe(true) }) it('creates a text with textPath node and inserts it after the path', function() { - var instance = path.text(txt) - expect(instance.parent() instanceof SVG.Text).toBe(true) + var textPath = path.text(txt) + expect(textPath.parent() instanceof SVG.Text).toBe(true) expect(SVG.adopt(path.node.nextSibling) instanceof SVG.Text).toBe(true) }) + it('transplants the node from text to textPath', function () { + let nodesInText = [].slice.call(text.node.childNodes) + var textPath = path.text(txt) + let nodesInTextPath = [].slice.call(textPath.node.childNodes) + expect(nodesInText).toEqual(nodesInTextPath) + }) }) - describe('textPath()', function() { + describe('text.textPath()', function() { it('returns only the first textPath element in a text', function() { text.path(data) expect(text.textPath() instanceof SVG.TextPath).toBe(true) |