2018-08-12 17:02:49 +02:00
|
|
|
let expect = require("chai").expect;
|
2018-08-16 11:58:20 +02:00
|
|
|
let freesewing = require("./dist/index.js");
|
2018-08-12 17:02:49 +02:00
|
|
|
|
|
|
|
it("Svg constructor should initialize object", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
|
|
|
expect(part.paths).to.eql({});
|
|
|
|
expect(part.snippets).to.eql({});
|
|
|
|
expect(part.freeId).to.equal(0);
|
|
|
|
expect(part.topLeft).to.equal(false);
|
|
|
|
expect(part.bottomRight).to.equal(false);
|
|
|
|
expect(part.width).to.equal(false);
|
|
|
|
expect(part.height).to.equal(false);
|
|
|
|
expect(part.render).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should return a function from macroClosure", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
|
|
|
expect(typeof part.macroClosure()).to.equal("function");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should no run an unknown macro", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
|
|
|
let macro = part.macroClosure();
|
|
|
|
expect(macro("unknown")).to.equal(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should register and run a macro", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let plugin = {
|
|
|
|
name: "test",
|
|
|
|
version: "0.1-test",
|
|
|
|
macros: {
|
|
|
|
test: function(so) {
|
|
|
|
let points = this.points;
|
|
|
|
points.macro = new this.Point(so.x, so.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
pattern.with(plugin);
|
|
|
|
let part = new pattern.Part();
|
|
|
|
let macro = part.macroClosure();
|
|
|
|
macro("test", { x: 123, y: 456 });
|
|
|
|
expect(part.points.macro.x).to.equal(123);
|
|
|
|
expect(part.points.macro.y).to.equal(456);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should run debug", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
|
|
|
let debug = part.debugClosure();
|
|
|
|
expect(typeof debug).to.equal("function");
|
|
|
|
let d = 1;
|
|
|
|
let e = 11;
|
|
|
|
let b = 111;
|
|
|
|
let u = 1111;
|
|
|
|
let g = 11111;
|
|
|
|
expect(debug(d, e, b, u, g)).to.equal(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should return a free ID", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
2018-08-23 15:57:23 +02:00
|
|
|
let free = part.getId();
|
|
|
|
expect(part.getId()).to.equal("" + (parseInt(free) + 1));
|
2018-08-12 17:02:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Should return a function from unitsClosure", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
|
|
|
expect(typeof part.unitsClosure()).to.equal("function");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should convert units", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
|
|
|
let units = part.unitsClosure();
|
|
|
|
expect(units(123.456)).to.equal("12.35cm");
|
|
|
|
expect(part.units(123.456)).to.equal("12.35cm");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should set part attributes", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
|
|
|
part.attr("foo", "bar");
|
|
|
|
expect(part.attributes.get("foo")).to.equal("bar");
|
|
|
|
part.attr("foo", "baz");
|
|
|
|
expect(part.attributes.get("foo")).to.equal("bar baz");
|
|
|
|
part.attr("foo", "schmoo", true);
|
|
|
|
expect(part.attributes.get("foo")).to.equal("schmoo");
|
|
|
|
});
|
|
|
|
|
2018-08-16 11:58:20 +02:00
|
|
|
it("Should copy a part", () => {
|
2018-08-12 17:02:49 +02:00
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
let part = new pattern.Part();
|
|
|
|
part.points.foo = new part.Point(12, 23);
|
|
|
|
let test = new pattern.Part();
|
|
|
|
test.copy(part);
|
|
|
|
expect(test.points.foo.x).to.equal(12);
|
2018-08-31 09:44:12 +02:00
|
|
|
expect(test.points.foo.y).to.equal(23);
|
2018-08-12 17:02:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Should return shorthand", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
pattern.settings.mode = "draft";
|
|
|
|
pattern.settings.paperless = true;
|
|
|
|
let part = new pattern.Part();
|
|
|
|
let short = part.shorthand();
|
2018-09-12 17:34:53 +02:00
|
|
|
expect(short.complete).to.equal(true);
|
2018-08-12 17:02:49 +02:00
|
|
|
expect(short.paperless).to.equal(true);
|
|
|
|
});
|
2018-08-16 11:58:20 +02:00
|
|
|
|
|
|
|
it("Should calculate the part boundary", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
pattern.settings.mode = "draft";
|
|
|
|
let part = new pattern.Part();
|
|
|
|
let short = part.shorthand();
|
|
|
|
part.points.from = new short.Point(123, 456);
|
|
|
|
part.points.to = new short.Point(19, 76);
|
|
|
|
part.paths.test = new short.Path()
|
|
|
|
.move(part.points.from)
|
|
|
|
.line(part.points.to);
|
|
|
|
let boundary = part.boundary();
|
2018-09-11 11:39:50 +02:00
|
|
|
expect(boundary.topLeft.x).to.equal(17);
|
|
|
|
expect(boundary.topLeft.y).to.equal(74);
|
|
|
|
expect(boundary.bottomRight.x).to.equal(125);
|
|
|
|
expect(boundary.bottomRight.y).to.equal(458);
|
2018-08-16 11:58:20 +02:00
|
|
|
boundary = part.boundary();
|
2018-09-11 11:39:50 +02:00
|
|
|
expect(boundary.width).to.equal(108);
|
|
|
|
expect(boundary.height).to.equal(384);
|
2018-08-16 11:58:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Should stack a part", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
pattern.settings.mode = "draft";
|
|
|
|
let part = new pattern.Part();
|
|
|
|
let short = part.shorthand();
|
|
|
|
part.points.from = new short.Point(123, 456);
|
|
|
|
part.points.to = new short.Point(19, 76);
|
|
|
|
part.paths.test = new short.Path()
|
|
|
|
.move(part.points.from)
|
|
|
|
.line(part.points.to);
|
|
|
|
part.stack();
|
2018-09-11 11:39:50 +02:00
|
|
|
expect(part.attributes.get("transform")).to.equal("translate(-17, -74)");
|
2018-08-16 11:58:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Should only stack a part if needed", () => {
|
|
|
|
let pattern = new freesewing.Pattern();
|
|
|
|
pattern.settings.mode = "draft";
|
|
|
|
let part = new pattern.Part();
|
|
|
|
let short = part.shorthand();
|
2018-09-11 11:39:50 +02:00
|
|
|
part.points.from = new short.Point(2, 2);
|
2018-08-16 11:58:20 +02:00
|
|
|
part.points.to = new short.Point(19, 76);
|
|
|
|
part.paths.test = new short.Path()
|
|
|
|
.move(part.points.from)
|
|
|
|
.line(part.points.to);
|
|
|
|
part.stack();
|
|
|
|
expect(part.attributes.get("transform")).to.equal(false);
|
|
|
|
part.stack();
|
|
|
|
expect(part.attributes.get("transform")).to.equal(false);
|
|
|
|
});
|