2021-11-27 16:46:38 +01:00
|
|
|
import chai from 'chai'
|
2022-08-28 14:06:01 +02:00
|
|
|
import { Pattern } from '@freesewing/core'
|
|
|
|
import { plugin } from './dist/index.mjs'
|
2021-11-27 16:46:38 +01:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Title Plugin Tests', () => {
|
2022-08-28 14:06:01 +02:00
|
|
|
const pattern = new Pattern().use(plugin)
|
2021-11-27 16:46:38 +01:00
|
|
|
pattern.draft().render()
|
|
|
|
|
|
|
|
it("Should run the title macro", () => {
|
2022-08-28 14:06:01 +02:00
|
|
|
let pattern = new Pattern({ name: "testPattern", version: 99 });
|
2021-11-27 16:46:38 +01:00
|
|
|
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(
|
2021-12-29 09:17:04 +01:00
|
|
|
"text-4xl fill-note font-bold"
|
2021-11-27 16:46:38 +01:00
|
|
|
);
|
|
|
|
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");
|
2021-12-29 09:17:04 +01:00
|
|
|
expect(p.attributes.get("data-text-class")).to.equal("text-lg fill-current font-bold");
|
2021-11-27 16:46:38 +01:00
|
|
|
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
2022-01-18 18:49:54 +01:00
|
|
|
expect(p.attributes.get("data-text-y")).to.equal("-26");
|
2021-11-27 16:46:38 +01:00
|
|
|
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(
|
2021-12-29 09:17:04 +01:00
|
|
|
"fill-note"
|
2021-11-27 16:46:38 +01:00
|
|
|
);
|
|
|
|
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
2022-01-18 18:49:54 +01:00
|
|
|
expect(p.attributes.get("data-text-y")).to.equal("-18");
|
2021-11-27 16:46:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Should run the title macro with append flag", () => {
|
2022-08-28 14:06:01 +02:00
|
|
|
let pattern = new Pattern({ name: "testPattern", version: 99 });
|
2021-11-27 16:46:38 +01:00
|
|
|
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",
|
|
|
|
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(
|
2021-12-29 09:17:04 +01:00
|
|
|
"text-4xl fill-note font-bold"
|
2021-11-27 16:46:38 +01:00
|
|
|
);
|
|
|
|
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", () => {
|
2022-08-28 14:06:01 +02:00
|
|
|
let pattern = new Pattern({ name: "testPattern", version: 99 });
|
2021-11-27 16:46:38 +01:00
|
|
|
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(
|
2021-12-29 09:17:04 +01:00
|
|
|
"text-4xl fill-note font-bold"
|
2021-11-27 16:46:38 +01:00
|
|
|
);
|
|
|
|
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");
|
2021-12-29 09:17:04 +01:00
|
|
|
expect(p.attributes.get("data-text-class")).to.equal("text-lg fill-current font-bold");
|
2021-11-27 16:46:38 +01:00
|
|
|
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
2022-01-18 18:49:54 +01:00
|
|
|
expect(p.attributes.get("data-text-y")).to.equal("-26");
|
2021-11-27 16:46:38 +01:00
|
|
|
p = pattern.parts.test.points._foo_titlePattern;
|
|
|
|
expect(p.attributes.get("data-text")).to.equal("testPattern v99");
|
2021-12-29 09:17:04 +01:00
|
|
|
expect(p.attributes.get("data-text-class")).to.equal("fill-note");
|
2021-11-27 16:46:38 +01:00
|
|
|
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
2022-01-18 18:49:54 +01:00
|
|
|
expect(p.attributes.get("data-text-y")).to.equal("-18");
|
2021-11-27 16:46:38 +01:00
|
|
|
});
|
|
|
|
});
|