fix(plugin-bundle): Unit tests
This commit is contained in:
parent
f735bb5e89
commit
a279e2b40f
1 changed files with 80 additions and 67 deletions
|
@ -1,12 +1,13 @@
|
|||
import freesewing from "@freesewing/core";
|
||||
import { version } from "../../plugin-scalebox/package.json";
|
||||
let round = freesewing.utils.round;
|
||||
let expect = require("chai").expect;
|
||||
let plugin = require("../dist/index.js");
|
||||
|
||||
const round = freesewing.utils.round;
|
||||
const expect = require("chai").expect;
|
||||
const plugin = require("../dist/index.js");
|
||||
|
||||
describe("plugin-scalebox", function() {
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().use(plugin);
|
||||
const pattern = new freesewing.Pattern().use(plugin);
|
||||
pattern.render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-scalebox")).to.equal(
|
||||
version
|
||||
|
@ -14,74 +15,92 @@ describe("plugin-scalebox", function() {
|
|||
});
|
||||
|
||||
it("Should run the default scalebox macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.use(plugin);
|
||||
const pattern = new freesewing.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();
|
||||
const { macro } = pattern.parts.test.shorthand();
|
||||
macro("scalebox", {
|
||||
at: pattern.parts.test.points.anchor
|
||||
});
|
||||
let p = pattern.parts.test.points;
|
||||
expect(p.__scaleboxMetricTopLeft.x).to.equal(50);
|
||||
expect(p.__scaleboxMetricTopLeft.y).to.equal(175);
|
||||
expect(p.__scaleboxMetricTopRight.x).to.equal(150);
|
||||
expect(p.__scaleboxMetricTopRight.y).to.equal(175);
|
||||
expect(p.__scaleboxMetricBottomLeft.x).to.equal(50);
|
||||
expect(p.__scaleboxMetricBottomLeft.y).to.equal(225);
|
||||
expect(p.__scaleboxMetricBottomRight.x).to.equal(150);
|
||||
expect(p.__scaleboxMetricBottomRight.y).to.equal(225);
|
||||
expect(p.__scaleboxImperialTopLeft.x).to.equal(49.2);
|
||||
expect(p.__scaleboxImperialTopLeft.y).to.equal(174.6);
|
||||
expect(p.__scaleboxImperialTopRight.x).to.equal(150.8);
|
||||
expect(p.__scaleboxImperialTopRight.y).to.equal(174.6);
|
||||
expect(p.__scaleboxImperialBottomLeft.x).to.equal(49.2);
|
||||
expect(p.__scaleboxImperialBottomLeft.y).to.equal(225.4);
|
||||
expect(p.__scaleboxImperialBottomRight.x).to.equal(150.8);
|
||||
expect(p.__scaleboxImperialBottomRight.y).to.equal(225.4);
|
||||
expect(p.__scaleboxLead.x).to.equal(55);
|
||||
expect(p.__scaleboxLead.y).to.equal(185);
|
||||
expect(p.__scaleboxTitle.x).to.equal(55);
|
||||
expect(p.__scaleboxTitle.y).to.equal(195);
|
||||
expect(p.__scaleboxText.x).to.equal(55);
|
||||
expect(p.__scaleboxText.y).to.equal(203);
|
||||
expect(p.__scaleboxLink.x).to.equal(55);
|
||||
expect(p.__scaleboxLink.y).to.equal(211);
|
||||
expect(p.__scaleboxMetric.x).to.equal(100);
|
||||
expect(p.__scaleboxMetric.y).to.equal(220);
|
||||
expect(p.__scaleboxImperial.x).to.equal(100);
|
||||
expect(p.__scaleboxImperial.y).to.equal(224);
|
||||
/*
|
||||
* {
|
||||
anchor: Point { x: 100, y: 200, attributes: Attributes { list: {} } },
|
||||
__scaleboxMetricTopLeft: Point { x: 50, y: 175, attributes: Attributes { list: {} } },
|
||||
__scaleboxMetricTopRight: Point { x: 150, y: 175, attributes: Attributes { list: {} } },
|
||||
__scaleboxMetricBottomLeft: Point { x: 50, y: 225, attributes: Attributes { list: {} } },
|
||||
__scaleboxMetricBottomRight: Point { x: 150, y: 225, attributes: Attributes { list: {} } },
|
||||
__scaleboxImperialTopLeft: Point { x: 49.2, y: 174.6, attributes: Attributes { list: {} } },
|
||||
__scaleboxImperialTopRight: Point { x: 150.8, y: 174.6, attributes: Attributes { list: {} } },
|
||||
__scaleboxImperialBottomLeft: Point { x: 49.2, y: 225.4, attributes: Attributes { list: {} } },
|
||||
__scaleboxImperialBottomRight: Point { x: 150.8, y: 225.4, attributes: Attributes { list: {} } },
|
||||
__scaleboxLead: Point { x: 55, y: 185, attributes: Attributes { list: [Object] } },
|
||||
__scaleboxTitle: Point { x: 55, y: 195, attributes: Attributes { list: [Object] } },
|
||||
__scaleboxText: Point { x: 55, y: 207, attributes: Attributes { list: [Object] } },
|
||||
__scaleboxLink: Point { x: 55, y: 212, attributes: Attributes { list: [Object] } },
|
||||
__scaleboxMetric: Point { x: 100, y: 220, attributes: Attributes { list: [Object] } },
|
||||
__scaleboxImperial: Point { x: 100, y: 224, attributes: Attributes { list: [Object] } }
|
||||
}
|
||||
|
||||
*/
|
||||
expect(round(p.__scaleboxMetricTopLeft.x)).to.equal(50);
|
||||
expect(round(p.__scaleboxMetricTopLeft.y)).to.equal(175);
|
||||
expect(round(p.__scaleboxMetricTopRight.x)).to.equal(150);
|
||||
expect(round(p.__scaleboxMetricTopRight.y)).to.equal(175);
|
||||
expect(round(p.__scaleboxMetricBottomLeft.x)).to.equal(50);
|
||||
expect(round(p.__scaleboxMetricBottomLeft.y)).to.equal(225);
|
||||
expect(round(p.__scaleboxMetricBottomRight.x)).to.equal(150);
|
||||
expect(round(p.__scaleboxMetricBottomRight.y)).to.equal(225);
|
||||
expect(round(p.__scaleboxImperialTopLeft.x)).to.equal(49.2);
|
||||
expect(round(p.__scaleboxImperialTopLeft.y)).to.equal(174.6);
|
||||
expect(round(p.__scaleboxImperialTopRight.x)).to.equal(150.8);
|
||||
expect(round(p.__scaleboxImperialTopRight.y)).to.equal(174.6);
|
||||
expect(round(p.__scaleboxImperialBottomLeft.x)).to.equal(49.2);
|
||||
expect(round(p.__scaleboxImperialBottomLeft.y)).to.equal(225.4);
|
||||
expect(round(p.__scaleboxImperialBottomRight.x)).to.equal(150.8);
|
||||
expect(round(p.__scaleboxImperialBottomRight.y)).to.equal(225.4);
|
||||
expect(round(p.__scaleboxLead.x)).to.equal(55);
|
||||
expect(round(p.__scaleboxLead.y)).to.equal(185);
|
||||
expect(round(p.__scaleboxTitle.x)).to.equal(55);
|
||||
expect(round(p.__scaleboxTitle.y)).to.equal(195);
|
||||
expect(round(p.__scaleboxText.x)).to.equal(55);
|
||||
expect(round(p.__scaleboxText.y)).to.equal(207);
|
||||
expect(round(p.__scaleboxLink.x)).to.equal(55);
|
||||
expect(round(p.__scaleboxLink.y)).to.equal(212);
|
||||
expect(round(p.__scaleboxMetric.x)).to.equal(100);
|
||||
expect(round(p.__scaleboxMetric.y)).to.equal(220);
|
||||
expect(round(p.__scaleboxImperial.x)).to.equal(100);
|
||||
expect(round(p.__scaleboxImperial.y)).to.equal(224);
|
||||
p = pattern.parts.test.paths.__scaleboxMetric;
|
||||
expect(p.attributes.get("style")).to.equal("fill: #FFF; stroke: none;");
|
||||
expect(p.attributes.get("class")).to.equal("scalebox metric");
|
||||
expect(p.ops[0].type).to.equal("move");
|
||||
expect(p.ops[1].type).to.equal("line");
|
||||
expect(p.ops[2].type).to.equal("line");
|
||||
expect(p.ops[3].type).to.equal("line");
|
||||
expect(p.ops[4].type).to.equal("close");
|
||||
expect(p.ops[0].to.x).to.equal(50);
|
||||
expect(p.ops[0].to.y).to.equal(175);
|
||||
expect(p.ops[1].to.x).to.equal(50);
|
||||
expect(p.ops[1].to.y).to.equal(225);
|
||||
expect(p.ops[2].to.x).to.equal(150);
|
||||
expect(p.ops[2].to.y).to.equal(225);
|
||||
expect(p.ops[3].to.x).to.equal(150);
|
||||
expect(p.ops[3].to.y).to.equal(175);
|
||||
expect(round(p.ops[0].to.x)).to.equal(50);
|
||||
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.y)).to.equal(225);
|
||||
expect(round(p.ops[2].to.x)).to.equal(150);
|
||||
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.y)).to.equal(175);
|
||||
p = pattern.parts.test.paths.__scaleboxImperial;
|
||||
expect(p.attributes.get("style")).to.equal("fill: #000; stroke: none;");
|
||||
expect(p.attributes.get("class")).to.equal("scalebox imperial");
|
||||
expect(p.ops[0].type).to.equal("move");
|
||||
expect(p.ops[1].type).to.equal("line");
|
||||
expect(p.ops[2].type).to.equal("line");
|
||||
expect(p.ops[3].type).to.equal("line");
|
||||
expect(p.ops[4].type).to.equal("close");
|
||||
expect(p.ops[0].to.x).to.equal(49.2);
|
||||
expect(p.ops[0].to.y).to.equal(174.6);
|
||||
expect(p.ops[1].to.x).to.equal(49.2);
|
||||
expect(p.ops[1].to.y).to.equal(225.4);
|
||||
expect(p.ops[2].to.x).to.equal(150.8);
|
||||
expect(p.ops[2].to.y).to.equal(225.4);
|
||||
expect(p.ops[3].to.x).to.equal(150.8);
|
||||
expect(p.ops[3].to.y).to.equal(174.6);
|
||||
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[1].to.x)).to.equal(49.2);
|
||||
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.y)).to.equal(225.4);
|
||||
expect(round(p.ops[3].to.x)).to.equal(150.8);
|
||||
expect(round(p.ops[3].to.y)).to.equal(174.6);
|
||||
});
|
||||
|
||||
it("Should run the scalebox macro with rotation", () => {
|
||||
|
@ -116,9 +135,9 @@ describe("plugin-scalebox", function() {
|
|||
expect(round(p.__scaleboxLead.y)).to.equal(245);
|
||||
expect(round(p.__scaleboxTitle.x)).to.equal(95);
|
||||
expect(round(p.__scaleboxTitle.y)).to.equal(245);
|
||||
expect(round(p.__scaleboxText.x)).to.equal(103);
|
||||
expect(round(p.__scaleboxText.x)).to.equal(107);
|
||||
expect(round(p.__scaleboxText.y)).to.equal(245);
|
||||
expect(round(p.__scaleboxLink.x)).to.equal(111);
|
||||
expect(round(p.__scaleboxLink.x)).to.equal(112);
|
||||
expect(round(p.__scaleboxLink.y)).to.equal(245);
|
||||
expect(round(p.__scaleboxMetric.x)).to.equal(120);
|
||||
expect(round(p.__scaleboxMetric.y)).to.equal(200);
|
||||
|
@ -148,13 +167,7 @@ describe("plugin-scalebox", function() {
|
|||
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(
|
||||
"freesewingIsMadeByJoostDeCockAndContributors"
|
||||
);
|
||||
expect(p.list["data-text"][1]).to.equal("\n");
|
||||
expect(p.list["data-text"][2]).to.equal(
|
||||
"withTheFinancialSupportOfOurPatrons"
|
||||
);
|
||||
expect(p.list["data-text"][0]).to.equal("supportFreesewingBecomeAPatron");
|
||||
});
|
||||
|
||||
it("Should run the scalebox macro with custom text", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue