1
0
Fork 0
freesewing/packages/plugin-bundle/tests/cutonfold.test.js

62 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-11-17 22:18:52 +01:00
import freesewing from "@freesewing/core";
import { version } from "../../plugin-cutonfold/package.json";
2021-11-21 16:19:48 +01:00
const round = freesewing.utils.round;
const expect = require("chai").expect;
const plugin = require("../dist/index.js");
2021-11-17 22:18:52 +01:00
describe("plugin-cutonfold", function() {
it("Should set the plugin name:version attribute", () => {
2021-11-21 16:19:48 +01:00
const pattern = new freesewing.Pattern().use(plugin);
2021-11-20 13:58:40 +01:00
pattern.render();
2021-11-17 22:18:52 +01:00
expect(pattern.svg.attributes.get("freesewing:plugin-cutonfold")).to.equal(
version
);
});
2021-11-21 16:19:48 +01:00
2021-11-17 22:18:52 +01:00
it("Should run the default cutonfold macro", () => {
2021-11-21 16:19:48 +01:00
const pattern = new freesewing.Pattern().use(plugin);
2021-11-17 22:18:52 +01:00
pattern.parts.test = new pattern.Part();
pattern.parts.test.points.from = new pattern.Point(10, 20);
2021-11-21 16:19:48 +01:00
pattern.parts.test.points.to = new pattern.Point(10, 220);
const { macro } = pattern.parts.test.shorthand();
2021-11-17 22:18:52 +01:00
macro("cutonfold", {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to
});
2021-11-21 16:19:48 +01:00
const c = pattern.parts.test.paths.cutonfold;
2021-11-17 22:18:52 +01:00
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");
2021-11-21 16:19:48 +01:00
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);
2021-11-17 22:18:52 +01:00
});
2021-11-21 16:19:48 +01:00
2021-11-17 22:18:52 +01:00
it("Should run the cutonfold/grainline macro", () => {
2021-11-21 16:19:48 +01:00
const pattern = new freesewing.Pattern().use(plugin);
2021-11-17 22:18:52 +01:00
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);
2021-11-21 16:19:48 +01:00
const { macro } = pattern.parts.test.shorthand();
2021-11-17 22:18:52 +01:00
macro("cutonfold", {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to,
grainline: true
});
2021-11-21 16:19:48 +01:00
const c = pattern.parts.test.paths.cutonfold;
2021-11-17 22:18:52 +01:00
expect(c.attributes.get("data-text")).to.equal("cutOnFoldAndGrainline");
});
});