1
0
Fork 0

chore(plugin-grainline): Using new attributes.setIfUnset() method

This commit is contained in:
Joost De Cock 2021-11-21 17:43:13 +01:00
parent 677c199d4f
commit 81f9e391d3
2 changed files with 16 additions and 16 deletions

View file

@ -5,7 +5,7 @@ export default {
name: name,
version: version,
hooks: {
preRender: function (svg) {
preRender: svg => {
if (svg.attributes.get('freesewing:plugin-grainline') === false) {
svg.attributes.set('freesewing:plugin-grainline', version)
svg.defs += markers

View file

@ -1,31 +1,31 @@
import freesewing from "freesewing";
import freesewing from '@freesewing/core'
import { version } from "../package.json";
let expect = require("chai").expect;
let plugin = require("../dist/index.js");
const expect = require("chai").expect;
const plugin = require("../dist/index.js");
const round = freesewing.utils.round
it("Should set the plugin name:version attribute", () => {
let pattern = new freesewing.Pattern().with(plugin);
pattern.render();
const pattern = new freesewing.Pattern().use(plugin);
pattern.draft().render();
expect(pattern.svg.attributes.get("freesewing:plugin-grainline")).to.equal(
version
);
});
it("Should run the default grainline macro", () => {
let pattern = new freesewing.Pattern();
pattern.draft = function() {};
pattern.with(plugin);
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);
let { macro } = pattern.parts.test.shorthand();
const { macro } = pattern.parts.test.shorthand();
macro("grainline", {
from: pattern.parts.test.points.from,
to: pattern.parts.test.points.to
});
console.log(pattern.parts.test.paths);
let c = pattern.parts.test.paths.grainline;
const 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)");
@ -33,8 +33,8 @@ it("Should run the default grainline macro", () => {
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);
expect(round(c.ops[0].to.x)).to.equal(10);
expect(round(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.y)).to.equal(219.5);
});