import { Vector } from '../../vector'
describe('Vector', () => {
describe('#create', () => {
it('should create a vector instance with tagName', () => {
const vel = Vector.create('rect')
expect(Vector.isVector(vel)).toBe(true)
expect(vel.node).toBeInstanceOf(SVGRectElement)
})
it('should create a vector instance with SVGElement', () => {
const old = Vector.create('rect')
const vel = Vector.create(old.node)
expect(Vector.isVector(vel)).toBe(true)
expect(vel.node).toBeInstanceOf(SVGRectElement)
})
it('should create a vector instance with another vector', () => {
const old = Vector.create('rect')
const vel = Vector.create(old)
expect(Vector.isVector(vel)).toBe(true)
expect(vel.node).toBeInstanceOf(SVGRectElement)
})
it('should create a vector instance with markup', () => {
const vel = Vector.create(
'',
)
expect(vel.node).toBeInstanceOf(SVGRectElement)
expect(vel.getAttribute('width')).toEqual('100%')
expect(vel.getAttribute('height')).toEqual('100%')
expect(vel.getAttribute('fill')).toEqual('red')
})
it('should throw an error with invalid markup', () => {
const fn = () => Vector.create('')
expect(fn).toThrowError()
})
it('should throw an error with empty markup', () => {
const fn = () => Vector.create('')
expect(fn).toThrowError()
})
})
describe('#createVectors', () => {
it('should return an array of vectors', () => {
const vels = Vector.createVectors(
'' +
'' +
'' +
' ' +
' ' +
'' +
'' +
'Test' +
'' +
'' +
' ' +
' ' +
' ' +
' ' +
' ' +
'' +
'' +
'',
)
expect(Array.isArray(vels)).toBe(true)
expect(vels.length).toEqual(9)
vels.forEach((vel) => {
expect(Vector.isVector(vel)).toBe(true)
})
})
it('should fall back to create a vector', () => {
expect(Vector.createVectors('rect').length).toEqual(1)
})
})
})