diff options
Diffstat (limited to 'spec/spec/text.js')
-rw-r--r-- | spec/spec/text.js | 286 |
1 files changed, 0 insertions, 286 deletions
diff --git a/spec/spec/text.js b/spec/spec/text.js deleted file mode 100644 index 0bef0d1..0000000 --- a/spec/spec/text.js +++ /dev/null @@ -1,286 +0,0 @@ -// IMPORTANT!!! -// The native getBBox() on text elements isn't always accurate in the decimals. -// Therefore sometimes some rounding is used to make test work as expected. - -describe('Text', function() { - var text - - beforeEach(function() { - text = draw.text(loremIpsum).size(5) - }) - - afterEach(function() { - draw.clear() - }) - - describe('leading()', function() { - it('returns the leading value of the text without an argument', function() { - expect(text.leading() instanceof SVG.Number) - expect(text.leading().valueOf()).toBe(1.3) - }) - it('sets the leading value of the text with the first argument', function() { - expect(text.leading(1.5).dom.leading.valueOf()).toBe(1.5) - }) - }) - - describe('rebuild()', function() { - it('disables the rebuild if called with false', function() { - expect(text.rebuild(false)._rebuild).toBeFalsy() - }) - it('enables the rebuild if called with true', function() { - expect(text.rebuild(true)._rebuild).toBeTruthy() - }) - it('rebuilds the text without an argument given', function() { - var dy = text.get(2).attr('dy') - text.leading(1.7) - expect(dy == text.get(2).attr('dy')).toBeFalsy() - }) - }) - - describe('x()', function() { - it('returns the value of x without an argument', function() { - expect(text.x(0).x()).toBe(0) - }) - it('sets the x value of the bbox with the first argument', function() { - text.x(123) - expect(text.bbox().x).toBe(123) - }) - it('sets the value of all lines', function() { - text.x(200) - text.each(function() { - expect(this.x()).toBe(text.attr('x')) - }) - }) - }) - - describe('ax()', function () { - it('sets the value of x with a percent value', function() { - text.ax('40%') - expect(text.node.getAttribute('x')).toBe('40%') - }) - it('returns the value of x when x is a percentual value', function() { - expect(text.ax('45%').ax()).toBe('45%') - }) - }) - - describe('y()', function() { - it('returns the value of y without an argument', function() { - expect(text.y(0).y()).toBeCloseTo(0) - }) - it('sets the y value of the bbox with the first argument', function() { - text.y(345) - var box = text.bbox() - expect(box.y).toBe(345) - }) - }) - - describe('ay()', function () { - it('sets the value of y with a percent value', function() { - text.ay('40%') - expect(text.node.getAttribute('y')).toBe('40%') - }) - it('returns the value of y when y is a percentual value', function() { - expect(text.ay('45%').ay()).toBe('45%') - }) - }) - - - describe('cx()', function() { - it('returns the value of cx without an argument', function() { - var box = text.bbox() - expect(text.cx()).toBeCloseTo(box.x + box.width / 2) - }) - it('sets the value of cx with the first argument', function() { - text.cx(123) - var box = text.bbox() - // this is a hack. it should be exactly 123 since you set it. But bbox with text is a thing... - expect(box.cx).toBeCloseTo(box.x + box.width/2) - }) - }) - - describe('cy()', function() { - it('returns the value of cy without an argument', function() { - var box = text.bbox() - expect(text.cy()).toBe(box.cy) - }) - it('sets the value of cy with the first argument', function() { - text.cy(345) - var box = text.bbox() - expect(Math.round(box.cy * 10) / 10).toBe(345) - }) - }) - - describe('move()', function() { - it('sets the x and y position', function() { - text.move(123,456) - expect(text.bbox().x).toBe(123) - expect(text.bbox().y).toBe(456) - }) - }) - - describe('center()', function() { - it('sets the cx and cy position', function() { - text.center(321, 567) - var box = text.bbox() - expect(text.bbox().cx).toBeCloseTo(321, 1) - expect(text.bbox().cy).toBeCloseTo(567, 1) - }) - }) - - describe('translate()', function() { - it('sets the translation of an element', function() { - text.transform({ tx: 12, ty: 12 }) - expect(text.node.getAttribute('transform')).toBe('matrix(1,0,0,1,12,12)') - }) - }) - - describe('text()', function() { - it('adds content in a nested tspan', function() { - text.text('It is a bear!') - expect(text.node.childNodes[0].nodeType).toBe(1) - expect(text.node.childNodes[0].childNodes[0].data).toBe('It is a bear!') - }) - it('adds content in a nested tspan even with an empty string', function() { - text.text('') - expect(text.node.childNodes[0].nodeType).toBe(1) - expect(text.node.childNodes[0].childNodes[0].data).toBe('') - }) - it('creates multiple lines with a newline separated string', function() { - text.text('It is\nJUST\na bear!') - expect(text.node.childNodes.length).toBe(3) - }) - it('restores the content from the dom', function() { - text.text('It is\nJUST\na bear!') - expect(text.text()).toBe('It is\nJUST\na bear!') - }) - it('gets the given content of a text element without an argument', function() { - text.text('It is another bear!') - expect(text.node.childNodes[0].nodeType).toBe(1) - expect(text.text()).toMatch('It is another bear!') - }) - it('accepts a block as first arguments', function() { - text.text(function(add) { - add.tspan('mastaba') - add.plain('hut') - }) - expect(text.node.childNodes[0].nodeType).toBe(1) - expect(text.node.childNodes[0].childNodes[0].data).toBe('mastaba') - expect(text.node.childNodes[1].nodeType).toBe(3) - expect(text.node.childNodes[1].data).toBe('hut') - }) - }) - - describe('plain()', function() { - it('adds content without a tspan', function() { - text.plain('It is a bear!') - expect(text.node.childNodes[0].nodeType).toBe(3) - expect(text.node.childNodes[0].data).toBe('It is a bear!') - }) - it('clears content before adding new content', function() { - text.plain('It is not a bear!') - expect(text.node.childNodes.length).toBe(1) - expect(text.node.childNodes[0].data).toBe('It is not a bear!') - }) - it('restores the content from the dom', function() { - text.plain('Just plain text!') - expect(text.text()).toBe('Just plain text!') - }) - }) - - describe('tspan()', function() { - it('adds content in a tspan', function() { - text.tspan('It is a bear!') - expect(text.node.childNodes[0].nodeType).toBe(1) - expect(text.node.childNodes[0].childNodes[0].data).toBe('It is a bear!') - }) - it('clears content before adding new content', function() { - text.tspan('It is not a bear!') - expect(text.node.childNodes.length).toBe(1) - expect(text.node.childNodes[0].childNodes[0].data).toBe('It is not a bear!') - }) - }) - - describe('clear()', function() { - it('removes all content', function() { - text.text(function(add) { - add.tspan('The first.') - add.tspan('The second.') - add.tspan('The third.') - }) - expect(text.node.childNodes.length).toBe(3) - text.clear() - expect(text.node.childNodes.length).toBe(0) - }) - }) - - describe('lines()', function() { - it('gets an array of individual lines as an instance of SVG.Set', function() { - var l1, l2, l3 - text.text(function(add) { - l1 = add.tspan('The first.') - l2 = add.tspan('The second.') - l3 = add.tspan('The third.') - }) - expect(text.children().length).toBe(3) - expect(text.get(0)).toBe(l1) - expect(text.get(1)).toBe(l2) - expect(text.get(2)).toBe(l3) - }) - }) - - describe('length()', function() { - it('gets total length of text', function() { - text.text(function(add) { - add.tspan('The first.') - add.tspan('The second.') - add.tspan('The third.') - }) - expect(text.length()).toBeCloseTo(text.get(0).length() + text.get(1).length() + text.get(2).length(), 3) - }) - }) - - describe('build()', function() { - it('enables adding multiple plain text nodes when given true', function() { - text.clear().build(true) - text.plain('A great piece!') - text.plain('Another great piece!') - expect(text.node.childNodes[0].data).toBe('A great piece!') - expect(text.node.childNodes[1].data).toBe('Another great piece!') - }) - it('enables adding multiple tspan nodes when given true', function() { - text.clear().build(true) - text.tspan('A great piece!') - text.tspan('Another great piece!') - expect(text.node.childNodes[0].childNodes[0].data).toBe('A great piece!') - expect(text.node.childNodes[1].childNodes[0].data).toBe('Another great piece!') - }) - it('disables adding multiple plain text nodes when given false', function() { - text.clear().build(true) - text.plain('A great piece!') - text.build(false).plain('Another great piece!') - expect(text.node.childNodes[0].data).toBe('Another great piece!') - expect(text.node.childNodes[1]).toBe(undefined) - }) - it('disables adding multiple tspan nodes when given false', function() { - text.clear().build(true) - text.tspan('A great piece!') - text.build(false).tspan('Another great piece!') - expect(text.node.childNodes[0].childNodes[0].data).toBe('Another great piece!') - expect(text.node.childNodes[1]).toBe(undefined) - }) - }) - - describe('setData()', function() { - it('read all data from the svgjs:data attribute and assign it to el.dom', function(){ - - text.attr('svgjs:data', '{"foo":"bar","leading":"3px"}') - text.setData(JSON.parse(text.attr('svgjs:data'))) - - expect(text.dom.foo).toBe('bar') - expect(text.dom.leading instanceof SVG.Number).toBeTruthy() - expect(text.dom.leading.value).toBe(3) - expect(text.dom.leading.unit).toBe('px') - }) - }) - -}) |