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))
+ })
})
})
})
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>')
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))
+ })
})
})
})
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()', () => {
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))
+ })
})
})
})
})
})
- 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(() => {
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)
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', () => {
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', () => {
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()', () => {
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('')
+ })
})
})
})
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', () => {
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()', () => {