2022-09-09 20:20:38 +02:00
|
|
|
import chai from 'chai'
|
2022-09-19 23:35:52 +02:00
|
|
|
import { Design, Snippet, Point } from '../src/index.mjs'
|
2022-08-25 11:47:54 +02:00
|
|
|
|
|
|
|
const expect = chai.expect
|
2018-08-12 13:32:53 +02:00
|
|
|
|
2022-08-27 09:27:07 +02:00
|
|
|
describe('Snippet', () => {
|
2022-09-09 20:20:38 +02:00
|
|
|
it('Should create a snippet', () => {
|
|
|
|
let snip1 = new Snippet('test', new Point(12, 34))
|
|
|
|
expect(snip1.def).to.equal('test')
|
|
|
|
expect(snip1.anchor.x).to.equal(12)
|
|
|
|
expect(snip1.anchor.y).to.equal(34)
|
|
|
|
})
|
2018-08-12 13:32:53 +02:00
|
|
|
|
2022-09-09 20:20:38 +02:00
|
|
|
it('Should clone a snippet', () => {
|
|
|
|
let snip3 = new Snippet('boo', new Point(56, 78))
|
|
|
|
expect(snip3.clone().def).to.equal('boo')
|
|
|
|
expect(snip3.clone().anchor.x).to.equal(56)
|
|
|
|
expect(snip3.clone().anchor.y).to.equal(78)
|
|
|
|
})
|
2022-07-30 20:02:42 +02:00
|
|
|
|
2022-09-09 20:20:38 +02:00
|
|
|
it('Should set an attribute', () => {
|
|
|
|
let s = new Snippet('test', new Point(12, -34)).attr('class', 'test')
|
|
|
|
expect(s.attributes.get('class')).to.equal('test')
|
|
|
|
s.attr('class', 'more')
|
|
|
|
expect(s.attributes.get('class')).to.equal('test more')
|
|
|
|
s.attr('class', 'less', true)
|
|
|
|
expect(s.attributes.get('class')).to.equal('less')
|
|
|
|
})
|
2022-09-19 23:35:52 +02:00
|
|
|
|
|
|
|
it('Should get a snippet via the snippets proxy', () => {
|
|
|
|
let result
|
|
|
|
const part = {
|
|
|
|
name: 'test',
|
|
|
|
draft: ({ snippets, part }) => {
|
|
|
|
snippets.test = ':)'
|
|
|
|
result = snippets.test
|
|
|
|
|
|
|
|
return part
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const design = new Design({ parts: [part] })
|
|
|
|
const pattern = new design()
|
|
|
|
pattern.draft()
|
|
|
|
expect(result).to.equal(':)')
|
|
|
|
})
|
2022-09-09 20:20:38 +02:00
|
|
|
})
|