1
0
Fork 0

add plugin-bundle tests

This commit is contained in:
Chris Barrett 2021-11-17 22:18:52 +01:00
parent f45e1df1bf
commit 83c68f7dac
10 changed files with 590 additions and 572 deletions

View file

@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"]
}

View file

@ -31,7 +31,7 @@
"clean": "rimraf dist", "clean": "rimraf dist",
"build": "rollup -c", "build": "rollup -c",
"lernabuild": "rollup -c", "lernabuild": "rollup -c",
"test": "echo \"plugin-bundle: No tests configured. Perhaps you'd like to do this?\" && exit 0", "test": "BABEL_ENV=production ../../node_modules/.bin/mocha tests/*.test.js --require @babel/register",
"pubtest": "npm publish --registry http://localhost:6662", "pubtest": "npm publish --registry http://localhost:6662",
"pubforce": "npm publish", "pubforce": "npm publish",
"symlink": "mkdir -p ./node_modules/@freesewing && cd ./node_modules/@freesewing && ln -s -f ../../../* . && cd -", "symlink": "mkdir -p ./node_modules/@freesewing && cd ./node_modules/@freesewing && ln -s -f ../../../* . && cd -",

View file

@ -1,4 +1,4 @@
import freesewing from "freesewing"; 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 = [

View file

@ -1,62 +1,64 @@
import freesewing from "freesewing"; import freesewing from "@freesewing/core";
import { version } from "../node_modules/@freesewing/plugin-cutonfold/package.json"; import { version } from "../../plugin-cutonfold/package.json";
let expect = require("chai").expect; let expect = require("chai").expect;
let plugin = require("../dist/index.js"); let plugin = require("../dist/index.js");
it("Should set the plugin name:version attribute", () => { describe("plugin-cutonfold", function() {
let pattern = new freesewing.Pattern().use(plugin); it("Should set the plugin name:version attribute", () => {
pattern.render(); let pattern = new freesewing.Pattern().use(plugin);
expect(pattern.svg.attributes.get("freesewing:plugin-cutonfold")).to.equal( pattern.render();
version expect(pattern.svg.attributes.get("freesewing:plugin-cutonfold")).to.equal(
); version
}); );
it("Should run the default cutonfold macro", () => {
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(10, 230);
let { macro } = pattern.parts.test.shorthand();
macro("cutonfold", {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to
}); });
let c = pattern.parts.test.paths.cutonfold;
console.log(c.ops); it("Should run the default cutonfold macro", () => {
expect(c.attributes.get("class")).to.equal("note"); let pattern = new freesewing.Pattern();
expect(c.attributes.get("marker-start")).to.equal("url(#cutonfoldFrom)"); pattern.draft = function() {};
expect(c.attributes.get("marker-end")).to.equal("url(#cutonfoldTo)"); pattern.use(plugin);
expect(c.attributes.get("data-text")).to.equal("cutOnFold"); pattern.parts.test = new pattern.Part();
expect(c.attributes.get("data-text-class")).to.equal("center fill-note"); pattern.parts.test.points.from = new pattern.Point(10, 20);
expect(c.ops[0].type).to.equal("move"); pattern.parts.test.points.to = new pattern.Point(10, 230);
expect(c.ops[1].type).to.equal("line"); let { macro } = pattern.parts.test.shorthand();
expect(c.ops[2].type).to.equal("line"); macro("cutonfold", {
expect(c.ops[3].type).to.equal("line"); from: pattern.parts.test.points.from,
expect(c.ops[0].to.x).to.equal(10); to: pattern.parts.test.points.to
expect(c.ops[0].to.y).to.equal(200); });
expect(c.ops[1].to.x).to.equal(30); let c = pattern.parts.test.paths.cutonfold;
expect(c.ops[1].to.y).to.equal(200); console.log(c.ops);
expect(c.ops[2].to.x).to.equal(30); expect(c.attributes.get("class")).to.equal("note");
expect(c.ops[2].to.y).to.equal(50); expect(c.attributes.get("marker-start")).to.equal("url(#cutonfoldFrom)");
expect(c.ops[3].to.x).to.equal(10); expect(c.attributes.get("marker-end")).to.equal("url(#cutonfoldTo)");
expect(c.ops[3].to.y).to.equal(50); 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");
it("Should run the cutonfold/grainline macro", () => { expect(c.ops[1].type).to.equal("line");
let pattern = new freesewing.Pattern(); expect(c.ops[2].type).to.equal("line");
pattern.draft = function() {}; expect(c.ops[3].type).to.equal("line");
pattern.use(plugin); expect(c.ops[0].to.x).to.equal(10); //needs to be rounded
pattern.parts.test = new pattern.Part(); expect(c.ops[0].to.y).to.equal(200);
pattern.parts.test.points.from = new pattern.Point(10, 20); expect(c.ops[1].to.x).to.equal(30);
pattern.parts.test.points.to = new pattern.Point(10, 230); expect(c.ops[1].to.y).to.equal(200);
let { macro } = pattern.parts.test.shorthand(); expect(c.ops[2].to.x).to.equal(30);
macro("cutonfold", { expect(c.ops[2].to.y).to.equal(50);
from: pattern.parts.test.points.from, expect(c.ops[3].to.x).to.equal(10);
to: pattern.parts.test.points.to, expect(c.ops[3].to.y).to.equal(50);
grainline: true });
it("Should run the cutonfold/grainline macro", () => {
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(10, 230);
let { macro } = pattern.parts.test.shorthand();
macro("cutonfold", {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to,
grainline: true
});
let c = pattern.parts.test.paths.cutonfold;
expect(c.attributes.get("data-text")).to.equal("cutOnFoldAndGrainline");
}); });
let c = pattern.parts.test.paths.cutonfold;
expect(c.attributes.get("data-text")).to.equal("cutOnFoldAndGrainline");
}); });

View file

@ -1,185 +1,187 @@
import freesewing from "freesewing"; import freesewing from "@freesewing/core";
import { version } from "../node_modules/@freesewing/plugin-dimension/package.json"; import { version } from "../../plugin-dimension/package.json";
let expect = require("chai").expect; let expect = require("chai").expect;
let plugin = require("../dist/index.js"); let plugin = require("../dist/index.js");
it("Should set the plugin name:version attribute", () => { describe("plugin-dimension", function() {
let pattern = new freesewing.Pattern().use(plugin); it("Should set the plugin name:version attribute", () => {
pattern.render(); let pattern = new freesewing.Pattern().use(plugin);
expect(pattern.svg.attributes.get("freesewing:plugin-dimension")).to.equal( pattern.render();
version expect(pattern.svg.attributes.get("freesewing:plugin-dimension")).to.equal(
); version
}); );
it("Should run the hd macro", () => {
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,
to: pattern.parts.test.points.to,
y: 35
}); });
let c = pattern.parts.test.paths[1];
expect(c.attributes.get("class")).to.equal("mark"); it("Should run the hd macro", () => {
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)"); let pattern = new freesewing.Pattern();
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)"); pattern.draft = function() {};
expect(c.attributes.get("data-text")).to.equal("19cm"); pattern.use(plugin);
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center"); pattern.parts.test = new pattern.Part();
expect(c.ops[0].type).to.equal("move"); pattern.parts.test.points.from = new pattern.Point(10, 20);
expect(c.ops[1].type).to.equal("line"); pattern.parts.test.points.to = new pattern.Point(200, 20);
expect(c.ops[0].to.x).to.equal(10); let { macro } = pattern.parts.test.shorthand();
expect(c.ops[0].to.y).to.equal(35); macro("hd", {
expect(c.ops[1].to.x).to.equal(200); from: pattern.parts.test.points.from,
expect(c.ops[1].to.y).to.equal(35); to: pattern.parts.test.points.to,
c = pattern.parts.test.paths["1_ls"]; y: 35
expect(c.attributes.get("class")).to.equal("mark dotted"); });
expect(c.ops[0].type).to.equal("move"); let c = pattern.parts.test.paths[1];
expect(c.ops[1].type).to.equal("line"); expect(c.attributes.get("class")).to.equal("mark");
expect(c.ops[0].to.x).to.equal(10); expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
expect(c.ops[0].to.y).to.equal(20); expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
expect(c.ops[1].to.x).to.equal(10); expect(c.attributes.get("data-text")).to.equal("19cm");
expect(c.ops[1].to.y).to.equal(35); expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
c = pattern.parts.test.paths["1_le"]; expect(c.ops[0].type).to.equal("move");
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.ops[1].type).to.equal("line");
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].to.x).to.equal(10);
expect(c.ops[1].type).to.equal("line"); expect(c.ops[0].to.y).to.equal(35);
expect(c.ops[0].to.x).to.equal(200); expect(c.ops[1].to.x).to.equal(200);
expect(c.ops[0].to.y).to.equal(20); expect(c.ops[1].to.y).to.equal(35);
expect(c.ops[1].to.x).to.equal(200); c = pattern.parts.test.paths["1_ls"];
expect(c.ops[1].to.y).to.equal(35); 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");
it("Should run the vd macro", () => { expect(c.ops[0].to.x).to.equal(10);
let pattern = new freesewing.Pattern(); expect(c.ops[0].to.y).to.equal(20);
pattern.draft = function() {}; expect(c.ops[1].to.x).to.equal(10);
pattern.use(plugin); expect(c.ops[1].to.y).to.equal(35);
pattern.parts.test = new pattern.Part(); c = pattern.parts.test.paths["1_le"];
pattern.parts.test.points.from = new pattern.Point(10, 20); expect(c.attributes.get("class")).to.equal("mark dotted");
pattern.parts.test.points.to = new pattern.Point(10, 200); expect(c.ops[0].type).to.equal("move");
let { macro } = pattern.parts.test.shorthand(); expect(c.ops[1].type).to.equal("line");
macro("vd", { expect(c.ops[0].to.x).to.equal(200);
from: pattern.parts.test.points.from, expect(c.ops[0].to.y).to.equal(20);
to: pattern.parts.test.points.to, expect(c.ops[1].to.x).to.equal(200);
x: 25 expect(c.ops[1].to.y).to.equal(35);
}); });
let c = pattern.parts.test.paths[1];
expect(c.attributes.get("class")).to.equal("mark"); it("Should run the vd macro", () => {
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)"); let pattern = new freesewing.Pattern();
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)"); pattern.draft = function() {};
expect(c.attributes.get("data-text")).to.equal("18cm"); pattern.use(plugin);
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center"); pattern.parts.test = new pattern.Part();
expect(c.ops[0].type).to.equal("move"); pattern.parts.test.points.from = new pattern.Point(10, 20);
expect(c.ops[1].type).to.equal("line"); pattern.parts.test.points.to = new pattern.Point(10, 200);
expect(c.ops[0].to.x).to.equal(25); let { macro } = pattern.parts.test.shorthand();
expect(c.ops[0].to.y).to.equal(20); macro("vd", {
expect(c.ops[1].to.x).to.equal(25); from: pattern.parts.test.points.from,
expect(c.ops[1].to.y).to.equal(200); to: pattern.parts.test.points.to,
c = pattern.parts.test.paths["1_ls"]; x: 25
expect(c.attributes.get("class")).to.equal("mark dotted"); });
expect(c.ops[0].type).to.equal("move"); let c = pattern.parts.test.paths[1];
expect(c.ops[1].type).to.equal("line"); expect(c.attributes.get("class")).to.equal("mark");
expect(c.ops[0].to.x).to.equal(10); expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
expect(c.ops[0].to.y).to.equal(20); expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
expect(c.ops[1].to.x).to.equal(25); expect(c.attributes.get("data-text")).to.equal("18cm");
expect(c.ops[1].to.y).to.equal(20); expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
c = pattern.parts.test.paths["1_le"]; expect(c.ops[0].type).to.equal("move");
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.ops[1].type).to.equal("line");
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].to.x).to.equal(25);
expect(c.ops[1].type).to.equal("line"); expect(c.ops[0].to.y).to.equal(20);
expect(c.ops[0].to.x).to.equal(10); expect(c.ops[1].to.x).to.equal(25);
expect(c.ops[0].to.y).to.equal(200); expect(c.ops[1].to.y).to.equal(200);
expect(c.ops[1].to.x).to.equal(25); c = pattern.parts.test.paths["1_ls"];
expect(c.ops[1].to.y).to.equal(200); 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");
it("Should run the ld macro", () => { expect(c.ops[0].to.x).to.equal(10);
let pattern = new freesewing.Pattern(); expect(c.ops[0].to.y).to.equal(20);
pattern.draft = function() {}; expect(c.ops[1].to.x).to.equal(25);
pattern.use(plugin); expect(c.ops[1].to.y).to.equal(20);
pattern.parts.test = new pattern.Part(); c = pattern.parts.test.paths["1_le"];
pattern.parts.test.points.from = new pattern.Point(10, 10); expect(c.attributes.get("class")).to.equal("mark dotted");
pattern.parts.test.points.to = new pattern.Point(100, 100); expect(c.ops[0].type).to.equal("move");
let { macro } = pattern.parts.test.shorthand(); expect(c.ops[1].type).to.equal("line");
macro("ld", { expect(c.ops[0].to.x).to.equal(10);
from: pattern.parts.test.points.from, expect(c.ops[0].to.y).to.equal(200);
to: pattern.parts.test.points.to, expect(c.ops[1].to.x).to.equal(25);
d: 15 expect(c.ops[1].to.y).to.equal(200);
}); });
let c = pattern.parts.test.paths[1];
expect(c.attributes.get("class")).to.equal("mark"); it("Should run the ld macro", () => {
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)"); let pattern = new freesewing.Pattern();
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)"); pattern.draft = function() {};
expect(c.attributes.get("data-text")).to.equal("12.73cm"); pattern.use(plugin);
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center"); pattern.parts.test = new pattern.Part();
expect(c.ops[0].type).to.equal("move"); pattern.parts.test.points.from = new pattern.Point(10, 10);
expect(c.ops[1].type).to.equal("line"); pattern.parts.test.points.to = new pattern.Point(100, 100);
expect(c.ops[0].to.x).to.equal(20.61); let { macro } = pattern.parts.test.shorthand();
expect(c.ops[0].to.y).to.equal(-0.61); macro("ld", {
expect(c.ops[1].to.x).to.equal(110.61); from: pattern.parts.test.points.from,
expect(c.ops[1].to.y).to.equal(89.39); to: pattern.parts.test.points.to,
c = pattern.parts.test.paths["1_ls"]; d: 15
expect(c.attributes.get("class")).to.equal("mark dotted"); });
expect(c.ops[0].type).to.equal("move"); let c = pattern.parts.test.paths[1];
expect(c.ops[1].type).to.equal("line"); expect(c.attributes.get("class")).to.equal("mark");
expect(c.ops[0].to.x).to.equal(10); expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
expect(c.ops[0].to.y).to.equal(10); expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
expect(c.ops[1].to.x).to.equal(20.61); expect(c.attributes.get("data-text")).to.equal("12.73cm");
expect(c.ops[1].to.y).to.equal(-0.61); expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
c = pattern.parts.test.paths["1_le"]; expect(c.ops[0].type).to.equal("move");
expect(c.attributes.get("class")).to.equal("mark dotted"); expect(c.ops[1].type).to.equal("line");
expect(c.ops[0].type).to.equal("move"); expect(c.ops[0].to.x).to.equal(20.61);
expect(c.ops[1].type).to.equal("line"); expect(c.ops[0].to.y).to.equal(-0.61);
expect(c.ops[0].to.x).to.equal(100); expect(c.ops[1].to.x).to.equal(110.61);
expect(c.ops[0].to.y).to.equal(100); expect(c.ops[1].to.y).to.equal(89.39);
expect(c.ops[1].to.x).to.equal(110.61); c = pattern.parts.test.paths["1_ls"];
expect(c.ops[1].to.y).to.equal(89.39); 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");
it("Should run the pd macro", () => { expect(c.ops[0].to.x).to.equal(10);
let pattern = new freesewing.Pattern(); expect(c.ops[0].to.y).to.equal(10);
pattern.draft = function() {}; expect(c.ops[1].to.x).to.equal(20.61);
pattern.use(plugin); expect(c.ops[1].to.y).to.equal(-0.61);
pattern.parts.test = new pattern.Part(); c = pattern.parts.test.paths["1_le"];
let from = new pattern.Point(10, 10); expect(c.attributes.get("class")).to.equal("mark dotted");
let cp1 = new pattern.Point(100, 10); expect(c.ops[0].type).to.equal("move");
let cp2 = new pattern.Point(10, 100); expect(c.ops[1].type).to.equal("line");
let to = new pattern.Point(100, 100); expect(c.ops[0].to.x).to.equal(100);
let { macro } = pattern.parts.test.shorthand(); expect(c.ops[0].to.y).to.equal(100);
macro("pd", { expect(c.ops[1].to.x).to.equal(110.61);
path: new pattern.Path().move(from).curve(cp1, cp2, to), expect(c.ops[1].to.y).to.equal(89.39);
d: 15 });
it("Should run the pd macro", () => {
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),
d: 15
});
let c = pattern.parts.test.paths[1];
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(c.ops[0].to.x).to.equal(10);
expect(c.ops[0].to.y).to.equal(25);
expect(c.ops[1].to.x).to.equal(37.15);
expect(c.ops[1].to.y).to.equal(32.79);
c = pattern.parts.test.paths["1_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);
c = pattern.parts.test.paths["1_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);
}); });
let c = pattern.parts.test.paths[1];
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(c.ops[0].to.x).to.equal(10);
expect(c.ops[0].to.y).to.equal(25);
expect(c.ops[1].to.x).to.equal(37.15);
expect(c.ops[1].to.y).to.equal(32.79);
c = pattern.parts.test.paths["1_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);
c = pattern.parts.test.paths["1_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,38 +1,40 @@
import freesewing from "freesewing"; import freesewing from "@freesewing/core";
import { version } from "../node_modules/@freesewing/plugin-grainline/package.json"; import { version } from "../../plugin-grainline/package.json";
let expect = require("chai").expect; let expect = require("chai").expect;
let plugin = require("../dist/index.js"); let plugin = require("../dist/index.js");
it("Should set the plugin name:version attribute", () => { describe("plugin-grainline", function() {
let pattern = new freesewing.Pattern().use(plugin); it("Should set the plugin name:version attribute", () => {
pattern.render(); let pattern = new freesewing.Pattern().use(plugin);
expect(pattern.svg.attributes.get("freesewing:plugin-grainline")).to.equal( pattern.render();
version expect(pattern.svg.attributes.get("freesewing:plugin-grainline")).to.equal(
); 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();
from: pattern.parts.test.points.from, macro("grainline", {
to: pattern.parts.test.points.to from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to
});
let c = pattern.parts.test.paths.grainline;
expect(c.attributes.get("class")).to.equal("note");
expect(c.attributes.get("marker-start")).to.equal("url(#grainlineFrom)");
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-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[0].to.x).to.equal(10);
expect(c.ops[0].to.y).to.equal(30.5);
expect(c.ops[1].to.x).to.equal(10);
expect(c.ops[1].to.y).to.equal(219.5);
}); });
let c = pattern.parts.test.paths.grainline;
expect(c.attributes.get("class")).to.equal("note");
expect(c.attributes.get("marker-start")).to.equal("url(#grainlineFrom)");
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-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[0].to.x).to.equal(10);
expect(c.ops[0].to.y).to.equal(30.5);
expect(c.ops[1].to.x).to.equal(10);
expect(c.ops[1].to.y).to.equal(219.5);
}); });

View file

@ -1,12 +1,14 @@
import freesewing from "freesewing"; import freesewing from "@freesewing/core";
import { version } from "../node_modules/@freesewing/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");
it("Should set the plugin name:version attribute", () => { describe("plugin-round", function() {
let pattern = new freesewing.Pattern().use(plugin); it("Should set the plugin name:version attribute", () => {
pattern.render(); let pattern = new freesewing.Pattern().use(plugin);
expect(pattern.svg.attributes.get("freesewing:plugin-round")).to.equal( pattern.render();
version expect(pattern.svg.attributes.get("freesewing:plugin-round")).to.equal(
); version
);
});
}); });

View file

@ -1,184 +1,186 @@
import freesewing from "freesewing"; import freesewing from "@freesewing/core";
import { version } from "../node_modules/@freesewing/plugin-scalebox/package.json"; import { version } from "../../plugin-scalebox/package.json";
let expect = require("chai").expect; let expect = require("chai").expect;
let plugin = require("../dist/index.js"); let plugin = require("../dist/index.js");
it("Should set the plugin name:version attribute", () => { describe("plugin-scalebox", function() {
let pattern = new freesewing.Pattern().use(plugin); it("Should set the plugin name:version attribute", () => {
pattern.render(); let pattern = new freesewing.Pattern().use(plugin);
expect(pattern.svg.attributes.get("freesewing:plugin-scalebox")).to.equal( pattern.render();
version expect(pattern.svg.attributes.get("freesewing:plugin-scalebox")).to.equal(
); version
}); );
});
it("Should run the default scalebox macro", () => {
let pattern = new freesewing.Pattern(); it("Should run the default scalebox 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.anchor = new pattern.Point(100, 200); pattern.parts.test = new pattern.Part();
let { macro } = pattern.parts.test.shorthand(); pattern.parts.test.points.anchor = new pattern.Point(100, 200);
macro("scalebox", { let { macro } = pattern.parts.test.shorthand();
at: pattern.parts.test.points.anchor macro("scalebox", {
}); at: pattern.parts.test.points.anchor
let p = pattern.parts.test.points; });
expect(p.__scaleboxMetricTopLeft.x).to.equal(50); let p = pattern.parts.test.points;
expect(p.__scaleboxMetricTopLeft.y).to.equal(175); expect(p.__scaleboxMetricTopLeft.x).to.equal(50);
expect(p.__scaleboxMetricTopRight.x).to.equal(150); expect(p.__scaleboxMetricTopLeft.y).to.equal(175);
expect(p.__scaleboxMetricTopRight.y).to.equal(175); expect(p.__scaleboxMetricTopRight.x).to.equal(150);
expect(p.__scaleboxMetricBottomLeft.x).to.equal(50); expect(p.__scaleboxMetricTopRight.y).to.equal(175);
expect(p.__scaleboxMetricBottomLeft.y).to.equal(225); expect(p.__scaleboxMetricBottomLeft.x).to.equal(50);
expect(p.__scaleboxMetricBottomRight.x).to.equal(150); expect(p.__scaleboxMetricBottomLeft.y).to.equal(225);
expect(p.__scaleboxMetricBottomRight.y).to.equal(225); expect(p.__scaleboxMetricBottomRight.x).to.equal(150);
expect(p.__scaleboxImperialTopLeft.x).to.equal(49.2); expect(p.__scaleboxMetricBottomRight.y).to.equal(225);
expect(p.__scaleboxImperialTopLeft.y).to.equal(174.6); expect(p.__scaleboxImperialTopLeft.x).to.equal(49.2);
expect(p.__scaleboxImperialTopRight.x).to.equal(150.8); expect(p.__scaleboxImperialTopLeft.y).to.equal(174.6);
expect(p.__scaleboxImperialTopRight.y).to.equal(174.6); expect(p.__scaleboxImperialTopRight.x).to.equal(150.8);
expect(p.__scaleboxImperialBottomLeft.x).to.equal(49.2); expect(p.__scaleboxImperialTopRight.y).to.equal(174.6);
expect(p.__scaleboxImperialBottomLeft.y).to.equal(225.4); expect(p.__scaleboxImperialBottomLeft.x).to.equal(49.2);
expect(p.__scaleboxImperialBottomRight.x).to.equal(150.8); expect(p.__scaleboxImperialBottomLeft.y).to.equal(225.4);
expect(p.__scaleboxImperialBottomRight.y).to.equal(225.4); expect(p.__scaleboxImperialBottomRight.x).to.equal(150.8);
expect(p.__scaleboxLead.x).to.equal(55); expect(p.__scaleboxImperialBottomRight.y).to.equal(225.4);
expect(p.__scaleboxLead.y).to.equal(185); expect(p.__scaleboxLead.x).to.equal(55);
expect(p.__scaleboxTitle.x).to.equal(55); expect(p.__scaleboxLead.y).to.equal(185);
expect(p.__scaleboxTitle.y).to.equal(195); expect(p.__scaleboxTitle.x).to.equal(55);
expect(p.__scaleboxText.x).to.equal(55); expect(p.__scaleboxTitle.y).to.equal(195);
expect(p.__scaleboxText.y).to.equal(203); expect(p.__scaleboxText.x).to.equal(55);
expect(p.__scaleboxLink.x).to.equal(55); expect(p.__scaleboxText.y).to.equal(203);
expect(p.__scaleboxLink.y).to.equal(211); expect(p.__scaleboxLink.x).to.equal(55);
expect(p.__scaleboxMetric.x).to.equal(100); expect(p.__scaleboxLink.y).to.equal(211);
expect(p.__scaleboxMetric.y).to.equal(220); expect(p.__scaleboxMetric.x).to.equal(100);
expect(p.__scaleboxImperial.x).to.equal(100); expect(p.__scaleboxMetric.y).to.equal(220);
expect(p.__scaleboxImperial.y).to.equal(224); expect(p.__scaleboxImperial.x).to.equal(100);
p = pattern.parts.test.paths.__scaleboxMetric; expect(p.__scaleboxImperial.y).to.equal(224);
expect(p.attributes.get("style")).to.equal("fill: #FFF; stroke: none;"); p = pattern.parts.test.paths.__scaleboxMetric;
expect(p.ops[0].type).to.equal("move"); expect(p.attributes.get("style")).to.equal("fill: #FFF; stroke: none;");
expect(p.ops[1].type).to.equal("line"); expect(p.ops[0].type).to.equal("move");
expect(p.ops[2].type).to.equal("line"); expect(p.ops[1].type).to.equal("line");
expect(p.ops[3].type).to.equal("line"); expect(p.ops[2].type).to.equal("line");
expect(p.ops[4].type).to.equal("close"); expect(p.ops[3].type).to.equal("line");
expect(p.ops[0].to.x).to.equal(50); expect(p.ops[4].type).to.equal("close");
expect(p.ops[0].to.y).to.equal(175); expect(p.ops[0].to.x).to.equal(50);
expect(p.ops[1].to.x).to.equal(50); expect(p.ops[0].to.y).to.equal(175);
expect(p.ops[1].to.y).to.equal(225); expect(p.ops[1].to.x).to.equal(50);
expect(p.ops[2].to.x).to.equal(150); expect(p.ops[1].to.y).to.equal(225);
expect(p.ops[2].to.y).to.equal(225); expect(p.ops[2].to.x).to.equal(150);
expect(p.ops[3].to.x).to.equal(150); expect(p.ops[2].to.y).to.equal(225);
expect(p.ops[3].to.y).to.equal(175); expect(p.ops[3].to.x).to.equal(150);
p = pattern.parts.test.paths.__scaleboxImperial; expect(p.ops[3].to.y).to.equal(175);
expect(p.attributes.get("style")).to.equal("fill: #000; stroke: none;"); p = pattern.parts.test.paths.__scaleboxImperial;
expect(p.ops[0].type).to.equal("move"); expect(p.attributes.get("style")).to.equal("fill: #000; stroke: none;");
expect(p.ops[1].type).to.equal("line"); expect(p.ops[0].type).to.equal("move");
expect(p.ops[2].type).to.equal("line"); expect(p.ops[1].type).to.equal("line");
expect(p.ops[3].type).to.equal("line"); expect(p.ops[2].type).to.equal("line");
expect(p.ops[4].type).to.equal("close"); expect(p.ops[3].type).to.equal("line");
expect(p.ops[0].to.x).to.equal(49.2); expect(p.ops[4].type).to.equal("close");
expect(p.ops[0].to.y).to.equal(174.6); expect(p.ops[0].to.x).to.equal(49.2);
expect(p.ops[1].to.x).to.equal(49.2); expect(p.ops[0].to.y).to.equal(174.6);
expect(p.ops[1].to.y).to.equal(225.4); expect(p.ops[1].to.x).to.equal(49.2);
expect(p.ops[2].to.x).to.equal(150.8); expect(p.ops[1].to.y).to.equal(225.4);
expect(p.ops[2].to.y).to.equal(225.4); expect(p.ops[2].to.x).to.equal(150.8);
expect(p.ops[3].to.x).to.equal(150.8); expect(p.ops[2].to.y).to.equal(225.4);
expect(p.ops[3].to.y).to.equal(174.6); expect(p.ops[3].to.x).to.equal(150.8);
}); expect(p.ops[3].to.y).to.equal(174.6);
});
it("Should run the scalebox macro with rotation", () => {
let pattern = new freesewing.Pattern(); it("Should run the scalebox macro with rotation", () => {
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.anchor = new pattern.Point(100, 200); pattern.parts.test = new pattern.Part();
let { macro } = pattern.parts.test.shorthand(); pattern.parts.test.points.anchor = new pattern.Point(100, 200);
macro("scalebox", { let { macro } = pattern.parts.test.shorthand();
at: pattern.parts.test.points.anchor, macro("scalebox", {
rotate: 90 at: pattern.parts.test.points.anchor,
}); rotate: 90
let p = pattern.parts.test.points; });
expect(p.__scaleboxMetricTopLeft.x).to.equal(75); let p = pattern.parts.test.points;
expect(p.__scaleboxMetricTopLeft.y).to.equal(250); expect(p.__scaleboxMetricTopLeft.x).to.equal(75);
expect(p.__scaleboxMetricTopRight.x).to.equal(75); expect(p.__scaleboxMetricTopLeft.y).to.equal(250);
expect(p.__scaleboxMetricTopRight.y).to.equal(150); expect(p.__scaleboxMetricTopRight.x).to.equal(75);
expect(p.__scaleboxMetricBottomLeft.x).to.equal(125); expect(p.__scaleboxMetricTopRight.y).to.equal(150);
expect(p.__scaleboxMetricBottomLeft.y).to.equal(250); expect(p.__scaleboxMetricBottomLeft.x).to.equal(125);
expect(p.__scaleboxMetricBottomRight.x).to.equal(125); expect(p.__scaleboxMetricBottomLeft.y).to.equal(250);
expect(p.__scaleboxMetricBottomRight.y).to.equal(150); expect(p.__scaleboxMetricBottomRight.x).to.equal(125);
expect(p.__scaleboxImperialTopLeft.x).to.equal(74.6); expect(p.__scaleboxMetricBottomRight.y).to.equal(150);
expect(p.__scaleboxImperialTopLeft.y).to.equal(250.8); expect(p.__scaleboxImperialTopLeft.x).to.equal(74.6);
expect(p.__scaleboxImperialTopRight.x).to.equal(74.6); expect(p.__scaleboxImperialTopLeft.y).to.equal(250.8);
expect(p.__scaleboxImperialTopRight.y).to.equal(149.2); expect(p.__scaleboxImperialTopRight.x).to.equal(74.6);
expect(p.__scaleboxImperialBottomLeft.x).to.equal(125.4); expect(p.__scaleboxImperialTopRight.y).to.equal(149.2);
expect(p.__scaleboxImperialBottomLeft.y).to.equal(250.8); expect(p.__scaleboxImperialBottomLeft.x).to.equal(125.4);
expect(p.__scaleboxImperialBottomRight.x).to.equal(125.4); expect(p.__scaleboxImperialBottomLeft.y).to.equal(250.8);
expect(p.__scaleboxImperialBottomRight.y).to.equal(149.2); expect(p.__scaleboxImperialBottomRight.x).to.equal(125.4);
expect(p.__scaleboxLead.x).to.equal(85); expect(p.__scaleboxImperialBottomRight.y).to.equal(149.2);
expect(p.__scaleboxLead.y).to.equal(245); expect(p.__scaleboxLead.x).to.equal(85);
expect(p.__scaleboxTitle.x).to.equal(95); expect(p.__scaleboxLead.y).to.equal(245);
expect(p.__scaleboxTitle.y).to.equal(245); expect(p.__scaleboxTitle.x).to.equal(95);
expect(p.__scaleboxText.x).to.equal(103); expect(p.__scaleboxTitle.y).to.equal(245);
expect(p.__scaleboxText.y).to.equal(245); expect(p.__scaleboxText.x).to.equal(103);
expect(p.__scaleboxLink.x).to.equal(111); expect(p.__scaleboxText.y).to.equal(245);
expect(p.__scaleboxLink.y).to.equal(245); expect(p.__scaleboxLink.x).to.equal(111);
expect(p.__scaleboxMetric.x).to.equal(120); expect(p.__scaleboxLink.y).to.equal(245);
expect(p.__scaleboxMetric.y).to.equal(200); expect(p.__scaleboxMetric.x).to.equal(120);
expect(p.__scaleboxImperial.x).to.equal(124); expect(p.__scaleboxMetric.y).to.equal(200);
expect(p.__scaleboxImperial.y).to.equal(200); expect(p.__scaleboxImperial.x).to.equal(124);
}); expect(p.__scaleboxImperial.y).to.equal(200);
});
it("Should run the scalebox macro with default text", () => {
let pattern = new freesewing.Pattern({ it("Should run the scalebox macro with default text", () => {
name: "unitTest", let pattern = new freesewing.Pattern({
version: 99 name: "unitTest",
}); version: 99
pattern.draft = function() {}; });
pattern.use(plugin); pattern.draft = function() {};
pattern.parts.test = new pattern.Part(); pattern.use(plugin);
pattern.parts.test.points.anchor = new pattern.Point(100, 200); pattern.parts.test = new pattern.Part();
let { macro } = pattern.parts.test.shorthand(); pattern.parts.test.points.anchor = new pattern.Point(100, 200);
macro("scalebox", { let { macro } = pattern.parts.test.shorthand();
at: pattern.parts.test.points.anchor macro("scalebox", {
}); at: pattern.parts.test.points.anchor
let p = pattern.parts.test.points.__scaleboxLead.attributes; });
expect(p.get("data-text")).to.equal("freesewing"); let p = pattern.parts.test.points.__scaleboxLead.attributes;
expect(p.get("data-text-class")).to.equal("text-sm"); expect(p.get("data-text")).to.equal("freesewing");
p = pattern.parts.test.points.__scaleboxTitle.attributes; expect(p.get("data-text-class")).to.equal("text-sm");
expect(p.get("data-text")).to.equal("unitTest v99"); p = pattern.parts.test.points.__scaleboxTitle.attributes;
expect(p.get("data-text-class")).to.equal("text-lg"); expect(p.get("data-text")).to.equal("unitTest v99");
p = pattern.parts.test.points.__scaleboxText.attributes; expect(p.get("data-text-class")).to.equal("text-lg");
expect(p.get("data-text-class")).to.equal("text-xs"); p = pattern.parts.test.points.__scaleboxText.attributes;
expect(p.get("data-text-lineheight")).to.equal("4"); expect(p.get("data-text-class")).to.equal("text-xs");
expect(p.list["data-text"][0]).to.equal( expect(p.get("data-text-lineheight")).to.equal("4");
"freesewingIsMadeByJoostDeCockAndContributors" expect(p.list["data-text"][0]).to.equal(
); "freesewingIsMadeByJoostDeCockAndContributors"
expect(p.list["data-text"][1]).to.equal("\n"); );
expect(p.list["data-text"][2]).to.equal( expect(p.list["data-text"][1]).to.equal("\n");
"withTheFinancialSupportOfOurPatrons" expect(p.list["data-text"][2]).to.equal(
); "withTheFinancialSupportOfOurPatrons"
}); );
});
it("Should run the scalebox macro with custom text", () => {
let pattern = new freesewing.Pattern({ it("Should run the scalebox macro with custom text", () => {
name: "unitTest", let pattern = new freesewing.Pattern({
version: 99 name: "unitTest",
}); version: 99
pattern.draft = function() {}; });
pattern.use(plugin); pattern.draft = function() {};
pattern.parts.test = new pattern.Part(); pattern.use(plugin);
pattern.parts.test.points.anchor = new pattern.Point(100, 200); pattern.parts.test = new pattern.Part();
let { macro } = pattern.parts.test.shorthand(); pattern.parts.test.points.anchor = new pattern.Point(100, 200);
macro("scalebox", { let { macro } = pattern.parts.test.shorthand();
at: pattern.parts.test.points.anchor, macro("scalebox", {
lead: "theLead", at: pattern.parts.test.points.anchor,
title: "theTitle", lead: "theLead",
text: "theText" title: "theTitle",
}); text: "theText"
let p = pattern.parts.test.points.__scaleboxLead.attributes; });
expect(p.get("data-text")).to.equal("theLead"); let p = pattern.parts.test.points.__scaleboxLead.attributes;
expect(p.get("data-text-class")).to.equal("text-sm"); expect(p.get("data-text")).to.equal("theLead");
p = pattern.parts.test.points.__scaleboxTitle.attributes; expect(p.get("data-text-class")).to.equal("text-sm");
expect(p.get("data-text")).to.equal("theTitle"); p = pattern.parts.test.points.__scaleboxTitle.attributes;
expect(p.get("data-text-class")).to.equal("text-lg"); expect(p.get("data-text")).to.equal("theTitle");
p = pattern.parts.test.points.__scaleboxText.attributes; expect(p.get("data-text-class")).to.equal("text-lg");
expect(p.get("data-text")).to.equal("theText"); p = pattern.parts.test.points.__scaleboxText.attributes;
expect(p.get("data-text-class")).to.equal("text-xs"); expect(p.get("data-text")).to.equal("theText");
expect(p.get("data-text-lineheight")).to.equal("4"); expect(p.get("data-text-class")).to.equal("text-xs");
expect(p.get("data-text-lineheight")).to.equal("4");
});
}); });

View file

@ -1,12 +1,14 @@
import freesewing from "freesewing"; import freesewing from "@freesewing/core";
import { version } from "../node_modules/@freesewing/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");
it("Should set the plugin name:version attribute", () => { describe('plugin-sprinkle', function() {
let pattern = new freesewing.Pattern().use(plugin); it("Should set the plugin name:version attribute", () => {
pattern.render(); let pattern = new freesewing.Pattern().use(plugin);
expect(pattern.svg.attributes.get("freesewing:plugin-sprinkle")).to.equal( pattern.render();
version expect(pattern.svg.attributes.get("freesewing:plugin-sprinkle")).to.equal(
); version
);
});
}); });

View file

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