aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-10 15:04:42 +1000
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-10 15:04:42 +1000
commit373b78a10b3255104e221c64494e3139d11d058b (patch)
tree8ed9b7da1febf8efb75fa3ca10d5a11205573c77
parent47dc23cf13f870c9ce5dbc69c22a1c33f01619ef (diff)
downloadsvg.js-373b78a10b3255104e221c64494e3139d11d058b.tar.gz
svg.js-373b78a10b3255104e221c64494e3139d11d058b.zip
added tests for Line
-rw-r--r--spec/spec/elements/Line.js104
-rw-r--r--spec/spec/elements/Marker.js4
-rw-r--r--src/elements/Line.js2
3 files changed, 107 insertions, 3 deletions
diff --git a/spec/spec/elements/Line.js b/spec/spec/elements/Line.js
new file mode 100644
index 0000000..9fe1871
--- /dev/null
+++ b/spec/spec/elements/Line.js
@@ -0,0 +1,104 @@
+/* globals describe, expect, it, beforeEach, spyOn, jasmine, container */
+
+import { Line, PointArray, SVG, G } from '../../../src/main.js'
+
+const { any, objectContaining } = jasmine
+
+describe('Line.js', () => {
+ let line
+
+ beforeEach(() => {
+ line = new Line()
+ })
+
+ describe('()', () => {
+ it('creates a new object of type Line', () => {
+ expect(new Line()).toEqual(any(Line))
+ })
+
+ it('sets passed attributes on the element', () => {
+ expect(new Line({ id: 'foo' }).id()).toBe('foo')
+ })
+ })
+
+ describe('array()', () => {
+ it('returns a PointArray containing the points of the line', () => {
+ const array = line.plot(1, 2, 3, 4).array()
+ expect(array).toEqual(any(PointArray))
+ expect(array).toEqual([ [ 1, 2 ], [ 3, 4 ] ])
+ })
+ })
+
+ describe('plot()', () => {
+ it('relays to array() as getter', () => {
+ const spy = spyOn(line, 'array')
+ line.plot()
+ expect(spy).toHaveBeenCalled()
+ })
+
+ it('calls attr with line attributes when 4 parameters given', () => {
+ const spy = spyOn(line, 'attr')
+ line.plot(1, 2, 3, 4)
+ expect(spy).toHaveBeenCalledWith({ x1: 1, y1: 2, x2: 3, y2: 4 })
+ })
+
+ it('calls attr with line attributes when array given', () => {
+ const spy = spyOn(line, 'attr')
+ line.plot([ 1, 2, 3, 4 ])
+ expect(spy).toHaveBeenCalledWith({ x1: 1, y1: 2, x2: 3, y2: 4 })
+ })
+
+ it('calls attr with line attributes when multi array given', () => {
+ const spy = spyOn(line, 'attr')
+ line.plot([ [ 1, 2 ], [ 3, 4 ] ])
+ expect(spy).toHaveBeenCalledWith({ x1: 1, y1: 2, x2: 3, y2: 4 })
+ })
+
+ it('calls attr with line attributes when PointArray given', () => {
+ const spy = spyOn(line, 'attr')
+ line.plot(new PointArray([ [ 1, 2 ], [ 3, 4 ] ]))
+ expect(spy).toHaveBeenCalledWith({ x1: 1, y1: 2, x2: 3, y2: 4 })
+ })
+ })
+
+ describe('move()', () => {
+ it('returns itself', () => {
+ expect(line.move(0, 0)).toBe(line)
+ })
+
+ it('moves the line along x and y axis', () => {
+ const canvas = SVG().addTo(container)
+ const line = canvas.line(1, 2, 3, 4)
+ line.move(50, 50)
+ expect(line.bbox()).toEqual(objectContaining({
+ x: 50, y: 50, width: 2, height: 2
+ }))
+ })
+ })
+
+ describe('size()', () => {
+ it('returns itself', () => {
+ expect(line.size(50, 50)).toBe(line)
+ })
+
+ it('sets the size of the line', () => {
+ const canvas = SVG().addTo(container)
+ const line = canvas.line(1, 2, 3, 4)
+ line.size(50, 50)
+ expect(line.bbox()).toEqual(objectContaining({
+ width: 50, height: 50, x: 1, y: 2
+ }))
+ })
+ })
+
+ describe('Container', () => {
+ describe('line()', () => {
+ it('creates a line with given points', () => {
+ const group = new G()
+ const line = group.line(1, 2, 3, 4)
+ expect(line.array()).toEqual([ [ 1, 2 ], [ 3, 4 ] ])
+ expect(line).toEqual(any(Line))
+ })
+ })
+ })
+})
diff --git a/spec/spec/elements/Marker.js b/spec/spec/elements/Marker.js
index 67be0bd..129bbc2 100644
--- a/spec/spec/elements/Marker.js
+++ b/spec/spec/elements/Marker.js
@@ -32,8 +32,8 @@ describe('Marker.js', function () {
describe('orient()', () => {
it('sets the orient attribute', () => {
- const marker = new Marker().orient('start')
- expect(marker.attr('orient')).toBe('start')
+ const marker = new Marker().orient('auto')
+ expect(marker.attr('orient')).toBe('auto')
})
})
diff --git a/src/elements/Line.js b/src/elements/Line.js
index 146aa45..b9982f4 100644
--- a/src/elements/Line.js
+++ b/src/elements/Line.js
@@ -29,7 +29,7 @@ export default class Line extends Shape {
if (x1 == null) {
return this.array()
} else if (typeof y1 !== 'undefined') {
- x1 = { x1: x1, y1: y1, x2: x2, y2: y2 }
+ x1 = { x1, y1, x2, y2 }
} else {
x1 = new PointArray(x1).toLine()
}