1
0
Fork 0

chore: formatting with prettier

This commit is contained in:
Joost De Cock 2021-11-21 16:33:35 +01:00
parent a279e2b40f
commit 2684766592
8 changed files with 588 additions and 630 deletions

View file

@ -1,21 +1,12 @@
import freesewing from "@freesewing/core"; import freesewing from '@freesewing/core'
let expect = require("chai").expect; let expect = require('chai').expect
let plugin = require("../dist/index.js"); let plugin = require('../dist/index.js')
let bundle = [ let bundle = ['cutonfold', 'dimension', 'grainline', 'logo', 'title', 'scalebox']
"cutonfold",
"dimension",
"grainline",
"logo",
"title",
"scalebox"
];
it("Should set the plugins name:version attribute", () => { it('Should set the plugins name:version attribute', () => {
let pattern = new freesewing.Pattern(); let pattern = new freesewing.Pattern()
pattern.use(plugin).render(); pattern.use(plugin).render()
for (let plug of bundle) { for (let plug of bundle) {
expect( expect(typeof pattern.svg.attributes.get('freesewing:plugin-' + plug)).to.equal('string')
typeof pattern.svg.attributes.get("freesewing:plugin-" + plug)
).to.equal("string");
} }
}); })

View file

@ -1,61 +1,59 @@
import freesewing from "@freesewing/core"; import freesewing from '@freesewing/core'
import { version } from "../../plugin-cutonfold/package.json"; import { version } from '../../plugin-cutonfold/package.json'
const round = freesewing.utils.round; const round = freesewing.utils.round
const expect = require("chai").expect; const expect = require('chai').expect
const plugin = require("../dist/index.js"); const plugin = require('../dist/index.js')
describe("plugin-cutonfold", function() { describe('plugin-cutonfold', function () {
it("Should set the plugin name:version attribute", () => { it('Should set the plugin name:version attribute', () => {
const pattern = new freesewing.Pattern().use(plugin); const pattern = new freesewing.Pattern().use(plugin)
pattern.render(); pattern.render()
expect(pattern.svg.attributes.get("freesewing:plugin-cutonfold")).to.equal( expect(pattern.svg.attributes.get('freesewing:plugin-cutonfold')).to.equal(version)
version })
);
});
it("Should run the default cutonfold macro", () => { it('Should run the default cutonfold macro', () => {
const pattern = new freesewing.Pattern().use(plugin); const pattern = new freesewing.Pattern().use(plugin)
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20); pattern.parts.test.points.from = new pattern.Point(10, 20)
pattern.parts.test.points.to = new pattern.Point(10, 220); pattern.parts.test.points.to = new pattern.Point(10, 220)
const { macro } = pattern.parts.test.shorthand(); const { macro } = pattern.parts.test.shorthand()
macro("cutonfold", { macro('cutonfold', {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to
});
const c = pattern.parts.test.paths.cutonfold;
expect(c.attributes.get("class")).to.equal("note");
expect(c.attributes.get("marker-start")).to.equal("url(#cutonfoldFrom)");
expect(c.attributes.get("marker-end")).to.equal("url(#cutonfoldTo)");
expect(c.attributes.get("data-text")).to.equal("cutOnFold");
expect(c.attributes.get("data-text-class")).to.equal("center fill-note");
expect(c.ops[0].type).to.equal("move");
expect(c.ops[1].type).to.equal("line");
expect(c.ops[2].type).to.equal("line");
expect(c.ops[3].type).to.equal("line");
expect(round(c.ops[0].to.x)).to.equal(10);
expect(round(c.ops[0].to.y)).to.equal(30);
expect(round(c.ops[1].to.x)).to.equal(25);
expect(round(c.ops[1].to.y)).to.equal(30);
expect(round(c.ops[2].to.x)).to.equal(25);
expect(round(c.ops[2].to.y)).to.equal(210);
expect(round(c.ops[3].to.x)).to.equal(10);
expect(round(c.ops[3].to.y)).to.equal(210);
});
it("Should run the cutonfold/grainline macro", () => {
const pattern = new freesewing.Pattern().use(plugin);
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.from = new pattern.Point(10, 20);
pattern.parts.test.points.to = new pattern.Point(10, 230);
const { macro } = pattern.parts.test.shorthand();
macro("cutonfold", {
from: pattern.parts.test.points.from, from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to, to: pattern.parts.test.points.to,
grainline: true })
}); const c = pattern.parts.test.paths.cutonfold
const c = pattern.parts.test.paths.cutonfold; expect(c.attributes.get('class')).to.equal('note')
expect(c.attributes.get("data-text")).to.equal("cutOnFoldAndGrainline"); expect(c.attributes.get('marker-start')).to.equal('url(#cutonfoldFrom)')
}); expect(c.attributes.get('marker-end')).to.equal('url(#cutonfoldTo)')
}); expect(c.attributes.get('data-text')).to.equal('cutOnFold')
expect(c.attributes.get('data-text-class')).to.equal('center fill-note')
expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal('line')
expect(c.ops[2].type).to.equal('line')
expect(c.ops[3].type).to.equal('line')
expect(round(c.ops[0].to.x)).to.equal(10)
expect(round(c.ops[0].to.y)).to.equal(30)
expect(round(c.ops[1].to.x)).to.equal(25)
expect(round(c.ops[1].to.y)).to.equal(30)
expect(round(c.ops[2].to.x)).to.equal(25)
expect(round(c.ops[2].to.y)).to.equal(210)
expect(round(c.ops[3].to.x)).to.equal(10)
expect(round(c.ops[3].to.y)).to.equal(210)
})
it('Should run the cutonfold/grainline macro', () => {
const pattern = new freesewing.Pattern().use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20)
pattern.parts.test.points.to = new pattern.Point(10, 230)
const { macro } = pattern.parts.test.shorthand()
macro('cutonfold', {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to,
grainline: true,
})
const c = pattern.parts.test.paths.cutonfold
expect(c.attributes.get('data-text')).to.equal('cutOnFoldAndGrainline')
})
})

View file

@ -1,227 +1,222 @@
import freesewing from "@freesewing/core"; import freesewing from '@freesewing/core'
import { version } from "../package.json"; import { version } from '../package.json'
let expect = require("chai").expect; let expect = require('chai').expect
let plugin = require("../dist/index.js"); let plugin = require('../dist/index.js')
let round = freesewing.utils.round; let round = freesewing.utils.round
describe("The dimension plugin", function() { describe('The dimension plugin', function () {
it('Should set the plugin name:version attribute', () => {
let pattern = new freesewing.Pattern().use(plugin)
pattern.render()
expect(pattern.svg.attributes.get('freesewing:plugin-dimension')).to.equal(version)
})
it("Should set the plugin name:version attribute", () => { describe('Measures horizontal dimensions', function () {
let pattern = new freesewing.Pattern().use(plugin); let pattern = new freesewing.Pattern()
pattern.render(); pattern.draft = function () {}
expect(pattern.svg.attributes.get("freesewing:plugin-dimension")).to.equal( pattern.use(plugin)
version pattern.parts.test = new pattern.Part()
); pattern.parts.test.points.from = new pattern.Point(10, 20)
}); pattern.parts.test.points.to = new pattern.Point(200, 20)
let { macro } = pattern.parts.test.shorthand()
describe("Measures horizontal dimensions", function() { macro('hd', {
let pattern = new freesewing.Pattern();
pattern.draft = function() {};
pattern.use(plugin);
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.from = new pattern.Point(10, 20);
pattern.parts.test.points.to = new pattern.Point(200, 20);
let { macro } = pattern.parts.test.shorthand();
macro("hd", {
from: pattern.parts.test.points.from, from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to, to: pattern.parts.test.points.to,
y: 35 y: 35,
}) })
it("should draw a line and add text to indicate its length", () => { it('should draw a line and add text to indicate its length', () => {
let c = pattern.parts.test.paths["__paperless1"]; let c = pattern.parts.test.paths['__paperless1']
expect(c.attributes.get("class")).to.equal("mark"); expect(c.attributes.get('class')).to.equal('mark')
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)"); expect(c.attributes.get('marker-start')).to.equal('url(#dimensionFrom)')
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)"); expect(c.attributes.get('marker-end')).to.equal('url(#dimensionTo)')
expect(c.attributes.get("data-text")).to.equal("19cm"); expect(c.attributes.get('data-text')).to.equal('19cm')
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center"); expect(c.attributes.get('data-text-class')).to.equal('fill-mark center')
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal("line"); expect(c.ops[1].type).to.equal('line')
expect(c.ops[0].to.x).to.equal(10); expect(c.ops[0].to.x).to.equal(10)
expect(c.ops[0].to.y).to.equal(35); expect(c.ops[0].to.y).to.equal(35)
expect(c.ops[1].to.x).to.equal(200); expect(c.ops[1].to.x).to.equal(200)
expect(c.ops[1].to.y).to.equal(35); expect(c.ops[1].to.y).to.equal(35)
}); })
it("should draw the start marker", () => { it('should draw the start marker', () => {
let c = pattern.parts.test.paths["__paperless1_ls"]; let c = pattern.parts.test.paths['__paperless1_ls']
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.attributes.get('class')).to.equal('mark dotted')
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal("line"); expect(c.ops[1].type).to.equal('line')
expect(c.ops[0].to.x).to.equal(10); expect(c.ops[0].to.x).to.equal(10)
expect(c.ops[0].to.y).to.equal(20); expect(c.ops[0].to.y).to.equal(20)
expect(c.ops[1].to.x).to.equal(10); expect(c.ops[1].to.x).to.equal(10)
expect(c.ops[1].to.y).to.equal(35); expect(c.ops[1].to.y).to.equal(35)
}); })
it("should draw the end marker", () => { it('should draw the end marker', () => {
let c = pattern.parts.test.paths["__paperless1_le"]; let c = pattern.parts.test.paths['__paperless1_le']
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.attributes.get('class')).to.equal('mark dotted')
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal("line"); expect(c.ops[1].type).to.equal('line')
expect(c.ops[0].to.x).to.equal(200); expect(c.ops[0].to.x).to.equal(200)
expect(c.ops[0].to.y).to.equal(20); expect(c.ops[0].to.y).to.equal(20)
expect(c.ops[1].to.x).to.equal(200); expect(c.ops[1].to.x).to.equal(200)
expect(c.ops[1].to.y).to.equal(35); expect(c.ops[1].to.y).to.equal(35)
}); })
}); })
describe("Measures vertical dimensions", () => { describe('Measures vertical dimensions', () => {
let pattern = new freesewing.Pattern(); let pattern = new freesewing.Pattern()
pattern.draft = function() {}; pattern.draft = function () {}
pattern.use(plugin); pattern.use(plugin)
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20); pattern.parts.test.points.from = new pattern.Point(10, 20)
pattern.parts.test.points.to = new pattern.Point(10, 200); pattern.parts.test.points.to = new pattern.Point(10, 200)
let { macro } = pattern.parts.test.shorthand(); let { macro } = pattern.parts.test.shorthand()
macro("vd", { macro('vd', {
from: pattern.parts.test.points.from, from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to, to: pattern.parts.test.points.to,
x: 25 x: 25,
}); })
it("Should draw a line and add text to indicate its length", () => { it('Should draw a line and add text to indicate its length', () => {
let c = pattern.parts.test.paths["__paperless1"]; let c = pattern.parts.test.paths['__paperless1']
expect(c.attributes.get("class")).to.equal("mark"); expect(c.attributes.get('class')).to.equal('mark')
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)"); expect(c.attributes.get('marker-start')).to.equal('url(#dimensionFrom)')
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)"); expect(c.attributes.get('marker-end')).to.equal('url(#dimensionTo)')
expect(c.attributes.get("data-text")).to.equal("18cm"); expect(c.attributes.get('data-text')).to.equal('18cm')
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center"); expect(c.attributes.get('data-text-class')).to.equal('fill-mark center')
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal("line"); expect(c.ops[1].type).to.equal('line')
expect(c.ops[0].to.x).to.equal(25); expect(c.ops[0].to.x).to.equal(25)
expect(c.ops[0].to.y).to.equal(20); expect(c.ops[0].to.y).to.equal(20)
expect(c.ops[1].to.x).to.equal(25); expect(c.ops[1].to.x).to.equal(25)
expect(c.ops[1].to.y).to.equal(200); expect(c.ops[1].to.y).to.equal(200)
}); })
it("Should draw the start marker", () => { it('Should draw the start marker', () => {
let c = pattern.parts.test.paths["__paperless1_ls"]; let c = pattern.parts.test.paths['__paperless1_ls']
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.attributes.get('class')).to.equal('mark dotted')
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal("line"); expect(c.ops[1].type).to.equal('line')
expect(c.ops[0].to.x).to.equal(10); expect(c.ops[0].to.x).to.equal(10)
expect(c.ops[0].to.y).to.equal(20); expect(c.ops[0].to.y).to.equal(20)
expect(c.ops[1].to.x).to.equal(25); expect(c.ops[1].to.x).to.equal(25)
expect(c.ops[1].to.y).to.equal(20); expect(c.ops[1].to.y).to.equal(20)
}); })
it("Should draw the end marker", () => { it('Should draw the end marker', () => {
let c = pattern.parts.test.paths["__paperless1_le"]; let c = pattern.parts.test.paths['__paperless1_le']
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.attributes.get('class')).to.equal('mark dotted')
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal("line"); expect(c.ops[1].type).to.equal('line')
expect(c.ops[0].to.x).to.equal(10); expect(c.ops[0].to.x).to.equal(10)
expect(c.ops[0].to.y).to.equal(200); expect(c.ops[0].to.y).to.equal(200)
expect(c.ops[1].to.x).to.equal(25); expect(c.ops[1].to.x).to.equal(25)
expect(c.ops[1].to.y).to.equal(200); expect(c.ops[1].to.y).to.equal(200)
}); })
}); })
describe("Measures the length of straight lines", () => { describe('Measures the length of straight lines', () => {
let pattern = new freesewing.Pattern(); let pattern = new freesewing.Pattern()
pattern.draft = function() {}; pattern.draft = function () {}
pattern.use(plugin); pattern.use(plugin)
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 10); pattern.parts.test.points.from = new pattern.Point(10, 10)
pattern.parts.test.points.to = new pattern.Point(100, 100); pattern.parts.test.points.to = new pattern.Point(100, 100)
let { macro } = pattern.parts.test.shorthand(); let { macro } = pattern.parts.test.shorthand()
macro("ld", { macro('ld', {
from: pattern.parts.test.points.from, from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to, to: pattern.parts.test.points.to,
d: 15 d: 15,
}); })
it("Should draw a line and add text to indicate its length", () => {
let c = pattern.parts.test.paths["__paperless1"];
expect(c.attributes.get("class")).to.equal("mark");
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
expect(c.attributes.get("data-text")).to.equal("12.73cm");
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
expect(c.ops[0].type).to.equal("move");
expect(c.ops[1].type).to.equal("line");
expect(round(c.ops[0].to.x)).to.equal(20.61);
expect(round(c.ops[0].to.y)).to.equal(-0.61);
expect(round(c.ops[1].to.x)).to.equal(110.61);
expect(round(c.ops[1].to.y)).to.equal(89.39);
});
it("Should draw the start marker", () => { it('Should draw a line and add text to indicate its length', () => {
let c = pattern.parts.test.paths["__paperless1_ls"]; let c = pattern.parts.test.paths['__paperless1']
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.attributes.get('class')).to.equal('mark')
expect(c.ops[0].type).to.equal("move"); expect(c.attributes.get('marker-start')).to.equal('url(#dimensionFrom)')
expect(c.ops[1].type).to.equal("line"); expect(c.attributes.get('marker-end')).to.equal('url(#dimensionTo)')
expect(round(c.ops[0].to.x)).to.equal(10); expect(c.attributes.get('data-text')).to.equal('12.73cm')
expect(round(c.ops[0].to.y)).to.equal(10); expect(c.attributes.get('data-text-class')).to.equal('fill-mark center')
expect(round(c.ops[1].to.x)).to.equal(20.61); expect(c.ops[0].type).to.equal('move')
expect(round(c.ops[1].to.y)).to.equal(-0.61); expect(c.ops[1].type).to.equal('line')
}); expect(round(c.ops[0].to.x)).to.equal(20.61)
expect(round(c.ops[0].to.y)).to.equal(-0.61)
expect(round(c.ops[1].to.x)).to.equal(110.61)
expect(round(c.ops[1].to.y)).to.equal(89.39)
})
it("Should draw the end marker", () => { it('Should draw the start marker', () => {
let c = pattern.parts.test.paths["__paperless1_le"]; let c = pattern.parts.test.paths['__paperless1_ls']
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.attributes.get('class')).to.equal('mark dotted')
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal("line"); expect(c.ops[1].type).to.equal('line')
expect(round(c.ops[0].to.x)).to.equal(100); expect(round(c.ops[0].to.x)).to.equal(10)
expect(round(c.ops[0].to.y)).to.equal(100); expect(round(c.ops[0].to.y)).to.equal(10)
expect(round(c.ops[1].to.x)).to.equal(110.61); expect(round(c.ops[1].to.x)).to.equal(20.61)
expect(round(c.ops[1].to.y)).to.equal(89.39); expect(round(c.ops[1].to.y)).to.equal(-0.61)
}); })
});
it('Should draw the end marker', () => {
describe("Measures curved lines", () => { let c = pattern.parts.test.paths['__paperless1_le']
expect(c.attributes.get('class')).to.equal('mark dotted')
let pattern = new freesewing.Pattern(); expect(c.ops[0].type).to.equal('move')
pattern.draft = function() {}; expect(c.ops[1].type).to.equal('line')
pattern.use(plugin); expect(round(c.ops[0].to.x)).to.equal(100)
pattern.parts.test = new pattern.Part(); expect(round(c.ops[0].to.y)).to.equal(100)
let from = new pattern.Point(10, 10); expect(round(c.ops[1].to.x)).to.equal(110.61)
let cp1 = new pattern.Point(100, 10); expect(round(c.ops[1].to.y)).to.equal(89.39)
let cp2 = new pattern.Point(10, 100); })
let to = new pattern.Point(100, 100); })
let { macro } = pattern.parts.test.shorthand();
macro("pd", { describe('Measures curved lines', () => {
let pattern = new freesewing.Pattern()
pattern.draft = function () {}
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
let from = new pattern.Point(10, 10)
let cp1 = new pattern.Point(100, 10)
let cp2 = new pattern.Point(10, 100)
let to = new pattern.Point(100, 100)
let { macro } = pattern.parts.test.shorthand()
macro('pd', {
path: new pattern.Path().move(from).curve(cp1, cp2, to), path: new pattern.Path().move(from).curve(cp1, cp2, to),
d: 15 d: 15,
}); })
it("Should draw a line and add text to indicate the length", () => {
let c = pattern.parts.test.paths["__paperless1"];
expect(c.attributes.get("class")).to.equal("mark");
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
expect(c.attributes.get("data-text")).to.equal("15.09cm");
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
expect(c.ops[0].type).to.equal("move");
expect(c.ops[1].type).to.equal("curve");
expect(round(c.ops[0].to.x)).to.equal(10);
expect(round(c.ops[0].to.y)).to.equal(25);
expect(round(c.ops[1].to.x)).to.equal(37.15);
expect(round(c.ops[1].to.y)).to.equal(32.79);
});
it("Should draw the start marker", () => {
let c = pattern.parts.test.paths["__paperless1_ls"];
expect(c.attributes.get("class")).to.equal("mark dotted");
expect(c.ops[0].type).to.equal("move");
expect(c.ops[1].type).to.equal("line");
expect(c.ops[0].to.x).to.equal(10);
expect(c.ops[0].to.y).to.equal(10);
expect(c.ops[1].to.x).to.equal(10);
expect(c.ops[1].to.y).to.equal(25);
});
it("Should draw the end marker", () => { it('Should draw a line and add text to indicate the length', () => {
let c = pattern.parts.test.paths["__paperless1_le"]; let c = pattern.parts.test.paths['__paperless1']
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.attributes.get('class')).to.equal('mark')
expect(c.ops[0].type).to.equal("move"); expect(c.attributes.get('marker-start')).to.equal('url(#dimensionFrom)')
expect(c.ops[1].type).to.equal("line"); expect(c.attributes.get('marker-end')).to.equal('url(#dimensionTo)')
expect(c.ops[0].to.x).to.equal(100); expect(c.attributes.get('data-text')).to.equal('15.09cm')
expect(c.ops[0].to.y).to.equal(100); expect(c.attributes.get('data-text-class')).to.equal('fill-mark center')
expect(c.ops[1].to.x).to.equal(100); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].to.y).to.equal(115); expect(c.ops[1].type).to.equal('curve')
}); expect(round(c.ops[0].to.x)).to.equal(10)
}); expect(round(c.ops[0].to.y)).to.equal(25)
}); expect(round(c.ops[1].to.x)).to.equal(37.15)
expect(round(c.ops[1].to.y)).to.equal(32.79)
})
it('Should draw the start marker', () => {
let c = pattern.parts.test.paths['__paperless1_ls']
expect(c.attributes.get('class')).to.equal('mark dotted')
expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal('line')
expect(c.ops[0].to.x).to.equal(10)
expect(c.ops[0].to.y).to.equal(10)
expect(c.ops[1].to.x).to.equal(10)
expect(c.ops[1].to.y).to.equal(25)
})
it('Should draw the end marker', () => {
let c = pattern.parts.test.paths['__paperless1_le']
expect(c.attributes.get('class')).to.equal('mark dotted')
expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal('line')
expect(c.ops[0].to.x).to.equal(100)
expect(c.ops[0].to.y).to.equal(100)
expect(c.ops[1].to.x).to.equal(100)
expect(c.ops[1].to.y).to.equal(115)
})
})
})

View file

@ -1,41 +1,39 @@
import freesewing from "@freesewing/core"; import freesewing from '@freesewing/core'
import { version } from "../../plugin-grainline/package.json"; import { version } from '../../plugin-grainline/package.json'
let round = freesewing.utils.round; let round = freesewing.utils.round
let expect = require("chai").expect; let expect = require('chai').expect
let plugin = require("../dist/index.js"); let plugin = require('../dist/index.js')
describe("plugin-grainline", function() { describe('plugin-grainline', function () {
it("Should set the plugin name:version attribute", () => { it('Should set the plugin name:version attribute', () => {
let pattern = new freesewing.Pattern().use(plugin); let pattern = new freesewing.Pattern().use(plugin)
pattern.render(); pattern.render()
expect(pattern.svg.attributes.get("freesewing:plugin-grainline")).to.equal( expect(pattern.svg.attributes.get('freesewing:plugin-grainline')).to.equal(version)
version })
);
}); it('Should run the default grainline macro', () => {
let pattern = new freesewing.Pattern()
it("Should run the default grainline macro", () => { pattern.draft = function () {}
let pattern = new freesewing.Pattern(); pattern.use(plugin)
pattern.draft = function() {}; pattern.parts.test = new pattern.Part()
pattern.use(plugin); pattern.parts.test.points.from = new pattern.Point(10, 20)
pattern.parts.test = new pattern.Part(); pattern.parts.test.points.to = new pattern.Point(10, 230)
pattern.parts.test.points.from = new pattern.Point(10, 20); let { macro } = pattern.parts.test.shorthand()
pattern.parts.test.points.to = new pattern.Point(10, 230); macro('grainline', {
let { macro } = pattern.parts.test.shorthand();
macro("grainline", {
from: pattern.parts.test.points.from, from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to to: pattern.parts.test.points.to,
}); })
let c = pattern.parts.test.paths.grainline; let c = pattern.parts.test.paths.grainline
expect(c.attributes.get("class")).to.equal("note"); expect(c.attributes.get('class')).to.equal('note')
expect(c.attributes.get("marker-start")).to.equal("url(#grainlineFrom)"); expect(c.attributes.get('marker-start')).to.equal('url(#grainlineFrom)')
expect(c.attributes.get("marker-end")).to.equal("url(#grainlineTo)"); expect(c.attributes.get('marker-end')).to.equal('url(#grainlineTo)')
expect(c.attributes.get("data-text")).to.equal("grainline"); expect(c.attributes.get('data-text')).to.equal('grainline')
expect(c.attributes.get("data-text-class")).to.equal("center fill-note"); expect(c.attributes.get('data-text-class')).to.equal('center fill-note')
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].type).to.equal('move')
expect(c.ops[1].type).to.equal("line"); expect(c.ops[1].type).to.equal('line')
expect(round(c.ops[0].to.x)).to.equal(10); expect(round(c.ops[0].to.x)).to.equal(10)
expect(c.ops[0].to.y).to.equal(30.5); expect(c.ops[0].to.y).to.equal(30.5)
expect(round(c.ops[1].to.x)).to.equal(10); expect(round(c.ops[1].to.x)).to.equal(10)
expect(c.ops[1].to.y).to.equal(219.5); expect(c.ops[1].to.y).to.equal(219.5)
}); })
}); })

View file

@ -1,14 +1,12 @@
import freesewing from "@freesewing/core"; import freesewing from '@freesewing/core'
import { version } from "../../plugin-round/package.json"; import { version } from '../../plugin-round/package.json'
let expect = require("chai").expect; let expect = require('chai').expect
let plugin = require("../dist/index.js"); let plugin = require('../dist/index.js')
describe("plugin-round", function() { describe('plugin-round', function () {
it("Should set the plugin name:version attribute", () => { it('Should set the plugin name:version attribute', () => {
let pattern = new freesewing.Pattern().use(plugin); let pattern = new freesewing.Pattern().use(plugin)
pattern.render(); pattern.render()
expect(pattern.svg.attributes.get("freesewing:plugin-round")).to.equal( expect(pattern.svg.attributes.get('freesewing:plugin-round')).to.equal(version)
version })
); })
});
});

View file

@ -1,28 +1,26 @@
import freesewing from "@freesewing/core"; import freesewing from '@freesewing/core'
import { version } from "../../plugin-scalebox/package.json"; import { version } from '../../plugin-scalebox/package.json'
const round = freesewing.utils.round; const round = freesewing.utils.round
const expect = require("chai").expect; const expect = require('chai').expect
const plugin = require("../dist/index.js"); const plugin = require('../dist/index.js')
describe("plugin-scalebox", function() { describe('plugin-scalebox', function () {
it("Should set the plugin name:version attribute", () => { it('Should set the plugin name:version attribute', () => {
const pattern = new freesewing.Pattern().use(plugin); const pattern = new freesewing.Pattern().use(plugin)
pattern.render(); pattern.render()
expect(pattern.svg.attributes.get("freesewing:plugin-scalebox")).to.equal( expect(pattern.svg.attributes.get('freesewing:plugin-scalebox')).to.equal(version)
version })
);
});
it("Should run the default scalebox macro", () => { it('Should run the default scalebox macro', () => {
const pattern = new freesewing.Pattern().use(plugin); const pattern = new freesewing.Pattern().use(plugin)
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.anchor = new pattern.Point(100, 200); pattern.parts.test.points.anchor = new pattern.Point(100, 200)
const { macro } = pattern.parts.test.shorthand(); const { macro } = pattern.parts.test.shorthand()
macro("scalebox", { macro('scalebox', {
at: pattern.parts.test.points.anchor at: pattern.parts.test.points.anchor,
}); })
let p = pattern.parts.test.points; let p = pattern.parts.test.points
/* /*
* { * {
anchor: Point { x: 100, y: 200, attributes: Attributes { list: {} } }, anchor: Point { x: 100, y: 200, attributes: Attributes { list: {} } },
@ -43,158 +41,158 @@ describe("plugin-scalebox", function() {
} }
*/ */
expect(round(p.__scaleboxMetricTopLeft.x)).to.equal(50); expect(round(p.__scaleboxMetricTopLeft.x)).to.equal(50)
expect(round(p.__scaleboxMetricTopLeft.y)).to.equal(175); expect(round(p.__scaleboxMetricTopLeft.y)).to.equal(175)
expect(round(p.__scaleboxMetricTopRight.x)).to.equal(150); expect(round(p.__scaleboxMetricTopRight.x)).to.equal(150)
expect(round(p.__scaleboxMetricTopRight.y)).to.equal(175); expect(round(p.__scaleboxMetricTopRight.y)).to.equal(175)
expect(round(p.__scaleboxMetricBottomLeft.x)).to.equal(50); expect(round(p.__scaleboxMetricBottomLeft.x)).to.equal(50)
expect(round(p.__scaleboxMetricBottomLeft.y)).to.equal(225); expect(round(p.__scaleboxMetricBottomLeft.y)).to.equal(225)
expect(round(p.__scaleboxMetricBottomRight.x)).to.equal(150); expect(round(p.__scaleboxMetricBottomRight.x)).to.equal(150)
expect(round(p.__scaleboxMetricBottomRight.y)).to.equal(225); expect(round(p.__scaleboxMetricBottomRight.y)).to.equal(225)
expect(round(p.__scaleboxImperialTopLeft.x)).to.equal(49.2); expect(round(p.__scaleboxImperialTopLeft.x)).to.equal(49.2)
expect(round(p.__scaleboxImperialTopLeft.y)).to.equal(174.6); expect(round(p.__scaleboxImperialTopLeft.y)).to.equal(174.6)
expect(round(p.__scaleboxImperialTopRight.x)).to.equal(150.8); expect(round(p.__scaleboxImperialTopRight.x)).to.equal(150.8)
expect(round(p.__scaleboxImperialTopRight.y)).to.equal(174.6); expect(round(p.__scaleboxImperialTopRight.y)).to.equal(174.6)
expect(round(p.__scaleboxImperialBottomLeft.x)).to.equal(49.2); expect(round(p.__scaleboxImperialBottomLeft.x)).to.equal(49.2)
expect(round(p.__scaleboxImperialBottomLeft.y)).to.equal(225.4); expect(round(p.__scaleboxImperialBottomLeft.y)).to.equal(225.4)
expect(round(p.__scaleboxImperialBottomRight.x)).to.equal(150.8); expect(round(p.__scaleboxImperialBottomRight.x)).to.equal(150.8)
expect(round(p.__scaleboxImperialBottomRight.y)).to.equal(225.4); expect(round(p.__scaleboxImperialBottomRight.y)).to.equal(225.4)
expect(round(p.__scaleboxLead.x)).to.equal(55); expect(round(p.__scaleboxLead.x)).to.equal(55)
expect(round(p.__scaleboxLead.y)).to.equal(185); expect(round(p.__scaleboxLead.y)).to.equal(185)
expect(round(p.__scaleboxTitle.x)).to.equal(55); expect(round(p.__scaleboxTitle.x)).to.equal(55)
expect(round(p.__scaleboxTitle.y)).to.equal(195); expect(round(p.__scaleboxTitle.y)).to.equal(195)
expect(round(p.__scaleboxText.x)).to.equal(55); expect(round(p.__scaleboxText.x)).to.equal(55)
expect(round(p.__scaleboxText.y)).to.equal(207); expect(round(p.__scaleboxText.y)).to.equal(207)
expect(round(p.__scaleboxLink.x)).to.equal(55); expect(round(p.__scaleboxLink.x)).to.equal(55)
expect(round(p.__scaleboxLink.y)).to.equal(212); expect(round(p.__scaleboxLink.y)).to.equal(212)
expect(round(p.__scaleboxMetric.x)).to.equal(100); expect(round(p.__scaleboxMetric.x)).to.equal(100)
expect(round(p.__scaleboxMetric.y)).to.equal(220); expect(round(p.__scaleboxMetric.y)).to.equal(220)
expect(round(p.__scaleboxImperial.x)).to.equal(100); expect(round(p.__scaleboxImperial.x)).to.equal(100)
expect(round(p.__scaleboxImperial.y)).to.equal(224); expect(round(p.__scaleboxImperial.y)).to.equal(224)
p = pattern.parts.test.paths.__scaleboxMetric; p = pattern.parts.test.paths.__scaleboxMetric
expect(p.attributes.get("class")).to.equal("scalebox metric"); expect(p.attributes.get('class')).to.equal('scalebox metric')
expect(p.ops[0].type).to.equal("move"); expect(p.ops[0].type).to.equal('move')
expect(p.ops[1].type).to.equal("line"); expect(p.ops[1].type).to.equal('line')
expect(p.ops[2].type).to.equal("line"); expect(p.ops[2].type).to.equal('line')
expect(p.ops[3].type).to.equal("line"); expect(p.ops[3].type).to.equal('line')
expect(p.ops[4].type).to.equal("close"); expect(p.ops[4].type).to.equal('close')
expect(round(p.ops[0].to.x)).to.equal(50); expect(round(p.ops[0].to.x)).to.equal(50)
expect(round(p.ops[0].to.y)).to.equal(175); expect(round(p.ops[0].to.y)).to.equal(175)
expect(round(p.ops[1].to.x)).to.equal(50); expect(round(p.ops[1].to.x)).to.equal(50)
expect(round(p.ops[1].to.y)).to.equal(225); expect(round(p.ops[1].to.y)).to.equal(225)
expect(round(p.ops[2].to.x)).to.equal(150); expect(round(p.ops[2].to.x)).to.equal(150)
expect(round(p.ops[2].to.y)).to.equal(225); expect(round(p.ops[2].to.y)).to.equal(225)
expect(round(p.ops[3].to.x)).to.equal(150); expect(round(p.ops[3].to.x)).to.equal(150)
expect(round(p.ops[3].to.y)).to.equal(175); expect(round(p.ops[3].to.y)).to.equal(175)
p = pattern.parts.test.paths.__scaleboxImperial; p = pattern.parts.test.paths.__scaleboxImperial
expect(p.attributes.get("class")).to.equal("scalebox imperial"); expect(p.attributes.get('class')).to.equal('scalebox imperial')
expect(p.ops[0].type).to.equal("move"); expect(p.ops[0].type).to.equal('move')
expect(p.ops[1].type).to.equal("line"); expect(p.ops[1].type).to.equal('line')
expect(p.ops[2].type).to.equal("line"); expect(p.ops[2].type).to.equal('line')
expect(p.ops[3].type).to.equal("line"); expect(p.ops[3].type).to.equal('line')
expect(p.ops[4].type).to.equal("close"); expect(p.ops[4].type).to.equal('close')
expect(round(p.ops[0].to.x)).to.equal(49.2); expect(round(p.ops[0].to.x)).to.equal(49.2)
expect(round(p.ops[0].to.y)).to.equal(174.6); expect(round(p.ops[0].to.y)).to.equal(174.6)
expect(round(p.ops[1].to.x)).to.equal(49.2); expect(round(p.ops[1].to.x)).to.equal(49.2)
expect(round(p.ops[1].to.y)).to.equal(225.4); expect(round(p.ops[1].to.y)).to.equal(225.4)
expect(round(p.ops[2].to.x)).to.equal(150.8); expect(round(p.ops[2].to.x)).to.equal(150.8)
expect(round(p.ops[2].to.y)).to.equal(225.4); expect(round(p.ops[2].to.y)).to.equal(225.4)
expect(round(p.ops[3].to.x)).to.equal(150.8); expect(round(p.ops[3].to.x)).to.equal(150.8)
expect(round(p.ops[3].to.y)).to.equal(174.6); expect(round(p.ops[3].to.y)).to.equal(174.6)
}); })
it("Should run the scalebox macro with rotation", () => { it('Should run the scalebox macro with rotation', () => {
let pattern = new freesewing.Pattern(); let pattern = new freesewing.Pattern()
pattern.draft = function() {}; pattern.draft = function () {}
pattern.use(plugin); pattern.use(plugin)
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.anchor = new pattern.Point(100, 200); pattern.parts.test.points.anchor = new pattern.Point(100, 200)
let { macro } = pattern.parts.test.shorthand(); let { macro } = pattern.parts.test.shorthand()
macro("scalebox", { macro('scalebox', {
at: pattern.parts.test.points.anchor, at: pattern.parts.test.points.anchor,
rotate: 90 rotate: 90,
}); })
let p = pattern.parts.test.points; let p = pattern.parts.test.points
expect(round(p.__scaleboxMetricTopLeft.x)).to.equal(75); expect(round(p.__scaleboxMetricTopLeft.x)).to.equal(75)
expect(round(p.__scaleboxMetricTopLeft.y)).to.equal(250); expect(round(p.__scaleboxMetricTopLeft.y)).to.equal(250)
expect(round(p.__scaleboxMetricTopRight.x)).to.equal(75); expect(round(p.__scaleboxMetricTopRight.x)).to.equal(75)
expect(round(p.__scaleboxMetricTopRight.y)).to.equal(150); expect(round(p.__scaleboxMetricTopRight.y)).to.equal(150)
expect(round(p.__scaleboxMetricBottomLeft.x)).to.equal(125); expect(round(p.__scaleboxMetricBottomLeft.x)).to.equal(125)
expect(round(p.__scaleboxMetricBottomLeft.y)).to.equal(250); expect(round(p.__scaleboxMetricBottomLeft.y)).to.equal(250)
expect(round(p.__scaleboxMetricBottomRight.x)).to.equal(125); expect(round(p.__scaleboxMetricBottomRight.x)).to.equal(125)
expect(round(p.__scaleboxMetricBottomRight.y)).to.equal(150); expect(round(p.__scaleboxMetricBottomRight.y)).to.equal(150)
expect(round(p.__scaleboxImperialTopLeft.x)).to.equal(74.6); expect(round(p.__scaleboxImperialTopLeft.x)).to.equal(74.6)
expect(round(p.__scaleboxImperialTopLeft.y)).to.equal(250.8); expect(round(p.__scaleboxImperialTopLeft.y)).to.equal(250.8)
expect(round(p.__scaleboxImperialTopRight.x)).to.equal(74.6); expect(round(p.__scaleboxImperialTopRight.x)).to.equal(74.6)
expect(round(p.__scaleboxImperialTopRight.y)).to.equal(149.2); expect(round(p.__scaleboxImperialTopRight.y)).to.equal(149.2)
expect(round(p.__scaleboxImperialBottomLeft.x)).to.equal(125.4); expect(round(p.__scaleboxImperialBottomLeft.x)).to.equal(125.4)
expect(round(p.__scaleboxImperialBottomLeft.y)).to.equal(250.8); expect(round(p.__scaleboxImperialBottomLeft.y)).to.equal(250.8)
expect(round(p.__scaleboxImperialBottomRight.x)).to.equal(125.4); expect(round(p.__scaleboxImperialBottomRight.x)).to.equal(125.4)
expect(round(p.__scaleboxImperialBottomRight.y)).to.equal(149.2); expect(round(p.__scaleboxImperialBottomRight.y)).to.equal(149.2)
expect(round(p.__scaleboxLead.x)).to.equal(85); expect(round(p.__scaleboxLead.x)).to.equal(85)
expect(round(p.__scaleboxLead.y)).to.equal(245); expect(round(p.__scaleboxLead.y)).to.equal(245)
expect(round(p.__scaleboxTitle.x)).to.equal(95); expect(round(p.__scaleboxTitle.x)).to.equal(95)
expect(round(p.__scaleboxTitle.y)).to.equal(245); expect(round(p.__scaleboxTitle.y)).to.equal(245)
expect(round(p.__scaleboxText.x)).to.equal(107); expect(round(p.__scaleboxText.x)).to.equal(107)
expect(round(p.__scaleboxText.y)).to.equal(245); expect(round(p.__scaleboxText.y)).to.equal(245)
expect(round(p.__scaleboxLink.x)).to.equal(112); expect(round(p.__scaleboxLink.x)).to.equal(112)
expect(round(p.__scaleboxLink.y)).to.equal(245); expect(round(p.__scaleboxLink.y)).to.equal(245)
expect(round(p.__scaleboxMetric.x)).to.equal(120); expect(round(p.__scaleboxMetric.x)).to.equal(120)
expect(round(p.__scaleboxMetric.y)).to.equal(200); expect(round(p.__scaleboxMetric.y)).to.equal(200)
expect(round(p.__scaleboxImperial.x)).to.equal(124); expect(round(p.__scaleboxImperial.x)).to.equal(124)
expect(round(p.__scaleboxImperial.y)).to.equal(200); expect(round(p.__scaleboxImperial.y)).to.equal(200)
}); })
it("Should run the scalebox macro with default text", () => { it('Should run the scalebox macro with default text', () => {
let pattern = new freesewing.Pattern({ let pattern = new freesewing.Pattern({
name: "unitTest", name: 'unitTest',
version: 99 version: 99,
}); })
pattern.draft = function() {}; pattern.draft = function () {}
pattern.use(plugin); pattern.use(plugin)
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.anchor = new pattern.Point(100, 200); pattern.parts.test.points.anchor = new pattern.Point(100, 200)
let { macro } = pattern.parts.test.shorthand(); let { macro } = pattern.parts.test.shorthand()
macro("scalebox", { macro('scalebox', {
at: pattern.parts.test.points.anchor
});
let p = pattern.parts.test.points.__scaleboxLead.attributes;
expect(p.get("data-text")).to.equal("FreeSewing");
expect(p.get("data-text-class")).to.equal("text-sm");
p = pattern.parts.test.points.__scaleboxTitle.attributes;
expect(p.get("data-text")).to.equal("unitTest v99");
expect(p.get("data-text-class")).to.equal("text-lg");
p = pattern.parts.test.points.__scaleboxText.attributes;
expect(p.get("data-text-class")).to.equal("text-xs");
expect(p.get("data-text-lineheight")).to.equal("4");
expect(p.list["data-text"][0]).to.equal("supportFreesewingBecomeAPatron");
});
it("Should run the scalebox macro with custom text", () => {
let pattern = new freesewing.Pattern({
name: "unitTest",
version: 99
});
pattern.draft = function() {};
pattern.use(plugin);
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
let { macro } = pattern.parts.test.shorthand();
macro("scalebox", {
at: pattern.parts.test.points.anchor, at: pattern.parts.test.points.anchor,
lead: "theLead", })
title: "theTitle", let p = pattern.parts.test.points.__scaleboxLead.attributes
text: "theText" expect(p.get('data-text')).to.equal('FreeSewing')
}); expect(p.get('data-text-class')).to.equal('text-sm')
let p = pattern.parts.test.points.__scaleboxLead.attributes; p = pattern.parts.test.points.__scaleboxTitle.attributes
expect(p.get("data-text")).to.equal("theLead"); expect(p.get('data-text')).to.equal('unitTest v99')
expect(p.get("data-text-class")).to.equal("text-sm"); expect(p.get('data-text-class')).to.equal('text-lg')
p = pattern.parts.test.points.__scaleboxTitle.attributes; p = pattern.parts.test.points.__scaleboxText.attributes
expect(p.get("data-text")).to.equal("theTitle"); expect(p.get('data-text-class')).to.equal('text-xs')
expect(p.get("data-text-class")).to.equal("text-lg"); expect(p.get('data-text-lineheight')).to.equal('4')
p = pattern.parts.test.points.__scaleboxText.attributes; expect(p.list['data-text'][0]).to.equal('supportFreesewingBecomeAPatron')
expect(p.get("data-text")).to.equal("theText"); })
expect(p.get("data-text-class")).to.equal("text-xs");
expect(p.get("data-text-lineheight")).to.equal("4"); it('Should run the scalebox macro with custom text', () => {
}); let pattern = new freesewing.Pattern({
}); name: 'unitTest',
version: 99,
})
pattern.draft = function () {}
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.anchor = new pattern.Point(100, 200)
let { macro } = pattern.parts.test.shorthand()
macro('scalebox', {
at: pattern.parts.test.points.anchor,
lead: 'theLead',
title: 'theTitle',
text: 'theText',
})
let p = pattern.parts.test.points.__scaleboxLead.attributes
expect(p.get('data-text')).to.equal('theLead')
expect(p.get('data-text-class')).to.equal('text-sm')
p = pattern.parts.test.points.__scaleboxTitle.attributes
expect(p.get('data-text')).to.equal('theTitle')
expect(p.get('data-text-class')).to.equal('text-lg')
p = pattern.parts.test.points.__scaleboxText.attributes
expect(p.get('data-text')).to.equal('theText')
expect(p.get('data-text-class')).to.equal('text-xs')
expect(p.get('data-text-lineheight')).to.equal('4')
})
})

View file

@ -1,14 +1,12 @@
import freesewing from "@freesewing/core"; import freesewing from '@freesewing/core'
import { version } from "../../plugin-sprinkle/package.json"; import { version } from '../../plugin-sprinkle/package.json'
let expect = require("chai").expect; let expect = require('chai').expect
let plugin = require("../dist/index.js"); let plugin = require('../dist/index.js')
describe('plugin-sprinkle', function() { describe('plugin-sprinkle', function () {
it("Should set the plugin name:version attribute", () => { it('Should set the plugin name:version attribute', () => {
let pattern = new freesewing.Pattern().use(plugin); let pattern = new freesewing.Pattern().use(plugin)
pattern.render(); pattern.render()
expect(pattern.svg.attributes.get("freesewing:plugin-sprinkle")).to.equal( expect(pattern.svg.attributes.get('freesewing:plugin-sprinkle')).to.equal(version)
version })
); })
});
});

View file

@ -1,119 +1,101 @@
import freesewing from "@freesewing/core"; import freesewing from '@freesewing/core'
import { version } from "../../plugin-title/package.json"; import { version } from '../../plugin-title/package.json'
let expect = require("chai").expect; let expect = require('chai').expect
let plugin = require("../dist/index.js"); let plugin = require('../dist/index.js')
describe('plugin-title', function () { describe('plugin-title', function () {
it("Should set the plugin name:version attribute", () => { it('Should set the plugin name:version attribute', () => {
let pattern = new freesewing.Pattern(); let pattern = new freesewing.Pattern()
pattern.use(plugin); pattern.use(plugin)
pattern.render(); pattern.render()
expect(pattern.svg.attributes.get("freesewing:plugin-title")).to.equal( expect(pattern.svg.attributes.get('freesewing:plugin-title')).to.equal(version)
version })
);
});
it("Should run the title macro", () => { it('Should run the title macro', () => {
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 }); let pattern = new freesewing.Pattern({ name: 'testPattern', version: 99 })
pattern.draft = function() {}; pattern.draft = function () {}
pattern.use(plugin); pattern.use(plugin)
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.anchor = new pattern.Point(-12, -34); pattern.parts.test.points.anchor = new pattern.Point(-12, -34)
let { macro } = pattern.parts.test.shorthand(); let { macro } = pattern.parts.test.shorthand()
macro("title", { macro('title', {
at: pattern.parts.test.points.anchor, at: pattern.parts.test.points.anchor,
nr: 3, nr: 3,
title: "unitTest" title: 'unitTest',
}); })
pattern.render(); pattern.render()
let p = pattern.parts.test.points.__titleNr; let p = pattern.parts.test.points.__titleNr
expect(p.x).to.equal(-12); expect(p.x).to.equal(-12)
expect(p.y).to.equal(-34); expect(p.y).to.equal(-34)
expect(p.attributes.get("data-text")).to.equal("3"); expect(p.attributes.get('data-text')).to.equal('3')
expect(p.attributes.get("data-text-class")).to.equal( expect(p.attributes.get('data-text-class')).to.equal('title-nr note fill-note')
"title-nr note fill-note" expect(p.attributes.get('data-text-x')).to.equal('-12')
); expect(p.attributes.get('data-text-y')).to.equal('-34')
expect(p.attributes.get("data-text-x")).to.equal("-12"); p = pattern.parts.test.points.__titleName
expect(p.attributes.get("data-text-y")).to.equal("-34"); expect(p.attributes.get('data-text')).to.equal('unitTest')
p = pattern.parts.test.points.__titleName; expect(p.attributes.get('data-text-class')).to.equal('title-name')
expect(p.attributes.get("data-text")).to.equal("unitTest"); expect(p.attributes.get('data-text-x')).to.equal('-12')
expect(p.attributes.get("data-text-class")).to.equal("title-name"); expect(p.attributes.get('data-text-y')).to.equal('-21')
expect(p.attributes.get("data-text-x")).to.equal("-12"); p = pattern.parts.test.points.__titlePattern
expect(p.attributes.get("data-text-y")).to.equal("-21"); expect(p.attributes.get('data-text')).to.equal('testPattern v99')
p = pattern.parts.test.points.__titlePattern; expect(p.attributes.get('data-text-class')).to.equal('title-pattern fill-note')
expect(p.attributes.get("data-text")).to.equal("testPattern v99"); expect(p.attributes.get('data-text-x')).to.equal('-12')
expect(p.attributes.get("data-text-class")).to.equal( expect(p.attributes.get('data-text-y')).to.equal('-14')
"title-pattern fill-note" })
);
expect(p.attributes.get("data-text-x")).to.equal("-12");
expect(p.attributes.get("data-text-y")).to.equal("-14");
});
it("Should run the title macro with append flag", () => { it('Should run the title macro with append flag', () => {
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 }); let pattern = new freesewing.Pattern({ name: 'testPattern', version: 99 })
pattern.use(plugin); pattern.use(plugin)
pattern.draft = function() {}; pattern.draft = function () {}
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr( pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr('data-text', '#')
"data-text", let { macro } = pattern.parts.test.shorthand()
"#" macro('title', {
);
let { macro } = pattern.parts.test.shorthand();
macro("title", {
at: pattern.parts.test.points.anchor, at: pattern.parts.test.points.anchor,
nr: 3, nr: 3,
title: "unitTest", title: 'unitTest',
append: true append: true,
}); })
pattern.render(); pattern.render()
let p = pattern.parts.test.points.__titleNr; let p = pattern.parts.test.points.__titleNr
expect(p.x).to.equal(-12); expect(p.x).to.equal(-12)
expect(p.y).to.equal(-34); expect(p.y).to.equal(-34)
expect(p.attributes.get("data-text")).to.equal("# 3"); expect(p.attributes.get('data-text')).to.equal('# 3')
expect(p.attributes.get("data-text-class")).to.equal( expect(p.attributes.get('data-text-class')).to.equal('title-nr note fill-note')
"title-nr note fill-note" expect(p.attributes.get('data-text-x')).to.equal('-12')
); expect(p.attributes.get('data-text-y')).to.equal('-34')
expect(p.attributes.get("data-text-x")).to.equal("-12"); })
expect(p.attributes.get("data-text-y")).to.equal("-34");
});
it("Should run the title macro with point prefix", () => { it('Should run the title macro with point prefix', () => {
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 }); let pattern = new freesewing.Pattern({ name: 'testPattern', version: 99 })
pattern.draft = function() {}; pattern.draft = function () {}
pattern.use(plugin); pattern.use(plugin)
pattern.parts.test = new pattern.Part(); pattern.parts.test = new pattern.Part()
pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr( pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr('data-text', '#')
"data-text", let { macro } = pattern.parts.test.shorthand()
"#" macro('title', {
);
let { macro } = pattern.parts.test.shorthand();
macro("title", {
at: pattern.parts.test.points.anchor, at: pattern.parts.test.points.anchor,
nr: 3, nr: 3,
title: "unitTest", title: 'unitTest',
prefix: "foo" prefix: 'foo',
}); })
pattern.render(); pattern.render()
let p = pattern.parts.test.points._foo_titleNr; let p = pattern.parts.test.points._foo_titleNr
expect(p.x).to.equal(-12); expect(p.x).to.equal(-12)
expect(p.y).to.equal(-34); expect(p.y).to.equal(-34)
expect(p.attributes.get("data-text")).to.equal("3"); expect(p.attributes.get('data-text')).to.equal('3')
expect(p.attributes.get("data-text-class")).to.equal( expect(p.attributes.get('data-text-class')).to.equal('title-nr note fill-note')
"title-nr note fill-note" expect(p.attributes.get('data-text-x')).to.equal('-12')
); expect(p.attributes.get('data-text-y')).to.equal('-34')
expect(p.attributes.get("data-text-x")).to.equal("-12"); p = pattern.parts.test.points._foo_titleName
expect(p.attributes.get("data-text-y")).to.equal("-34"); expect(p.attributes.get('data-text')).to.equal('unitTest')
p = pattern.parts.test.points._foo_titleName; expect(p.attributes.get('data-text-class')).to.equal('title-name')
expect(p.attributes.get("data-text")).to.equal("unitTest"); expect(p.attributes.get('data-text-x')).to.equal('-12')
expect(p.attributes.get("data-text-class")).to.equal("title-name"); expect(p.attributes.get('data-text-y')).to.equal('-21')
expect(p.attributes.get("data-text-x")).to.equal("-12"); p = pattern.parts.test.points._foo_titlePattern
expect(p.attributes.get("data-text-y")).to.equal("-21"); expect(p.attributes.get('data-text')).to.equal('testPattern v99')
p = pattern.parts.test.points._foo_titlePattern; expect(p.attributes.get('data-text-class')).to.equal('title-pattern fill-note')
expect(p.attributes.get("data-text")).to.equal("testPattern v99"); expect(p.attributes.get('data-text-x')).to.equal('-12')
expect(p.attributes.get("data-text-class")).to.equal( expect(p.attributes.get('data-text-y')).to.equal('-14')
"title-pattern fill-note" })
); })
expect(p.attributes.get("data-text-x")).to.equal("-12");
expect(p.attributes.get("data-text-y")).to.equal("-14");
});
});