2018-08-03 01:53:19 +01:00
|
|
|
// tslint:disable:object-literal-key-quotes
|
2018-08-03 01:28:20 +01:00
|
|
|
import { assert, expect } from "chai";
|
|
|
|
|
2018-10-26 01:04:07 +01:00
|
|
|
import { Formatter } from "export/formatter";
|
|
|
|
|
2018-08-09 02:53:28 +01:00
|
|
|
import { ImageParagraph } from "./image";
|
2018-08-03 01:28:20 +01:00
|
|
|
|
|
|
|
describe("Image", () => {
|
2018-08-09 02:56:23 +01:00
|
|
|
let image: ImageParagraph;
|
2018-08-03 01:28:20 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-08-09 02:56:23 +01:00
|
|
|
image = new ImageParagraph({
|
2018-08-03 01:28:20 +01:00
|
|
|
stream: new Buffer(""),
|
|
|
|
path: "",
|
2018-12-24 16:50:53 +00:00
|
|
|
fileName: "test.png",
|
2018-08-03 01:28:20 +01:00
|
|
|
dimensions: {
|
|
|
|
pixels: {
|
|
|
|
x: 10,
|
|
|
|
y: 10,
|
|
|
|
},
|
|
|
|
emus: {
|
|
|
|
x: 10,
|
|
|
|
y: 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#constructor()", () => {
|
|
|
|
it("should create valid JSON", () => {
|
|
|
|
const stringifiedJson = JSON.stringify(image);
|
|
|
|
|
|
|
|
try {
|
|
|
|
JSON.parse(stringifiedJson);
|
|
|
|
} catch (e) {
|
|
|
|
assert.isTrue(false);
|
|
|
|
}
|
|
|
|
assert.isTrue(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#scale()", () => {
|
|
|
|
it("should set the scale of the object properly", () => {
|
|
|
|
image.scale(2);
|
|
|
|
const tree = new Formatter().format(image);
|
|
|
|
expect(tree).to.deep.equal({
|
|
|
|
"w:p": [
|
|
|
|
{
|
|
|
|
"w:r": [
|
|
|
|
{
|
|
|
|
"w:drawing": [
|
|
|
|
{
|
|
|
|
"wp:inline": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
distB: 0,
|
|
|
|
distL: 0,
|
|
|
|
distR: 0,
|
|
|
|
distT: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"wp:extent": {
|
|
|
|
_attr: {
|
|
|
|
cx: 20,
|
|
|
|
cy: 20,
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"wp:effectExtent": {
|
|
|
|
_attr: {
|
|
|
|
b: 0,
|
|
|
|
l: 0,
|
|
|
|
r: 0,
|
|
|
|
t: 0,
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"wp:docPr": {
|
|
|
|
_attr: {
|
|
|
|
descr: "",
|
|
|
|
id: 0,
|
|
|
|
name: "",
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"wp:cNvGraphicFramePr": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"a:graphicFrameLocks": {
|
|
|
|
_attr: {
|
|
|
|
noChangeAspect: 1,
|
|
|
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"a:graphic": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"a:graphicData": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pic:pic": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
"xmlns:pic":
|
|
|
|
"http://schemas.openxmlformats.org/drawingml/2006/picture",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pic:nvPicPr": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"pic:cNvPr": {
|
|
|
|
_attr: {
|
|
|
|
desc: "",
|
|
|
|
id: 0,
|
|
|
|
name: "",
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"pic:cNvPicPr": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"a:picLocks": {
|
|
|
|
_attr: {
|
|
|
|
noChangeArrowheads: 1,
|
|
|
|
noChangeAspect: 1,
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pic:blipFill": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"a:blip": {
|
|
|
|
_attr: {
|
|
|
|
cstate: "none",
|
|
|
|
"r:embed": "rId{test.png}",
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
{
|
2019-04-10 01:28:37 -04:00
|
|
|
"a:srcRect": {},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"a:stretch": [
|
|
|
|
{
|
2019-04-10 01:28:37 -04:00
|
|
|
"a:fillRect": {},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pic:spPr": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
bwMode: "auto",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"a:xfrm": [
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"a:ext": {
|
|
|
|
_attr: {
|
|
|
|
cx: 10,
|
|
|
|
cy: 10,
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
{
|
2019-04-09 05:27:18 -04:00
|
|
|
"a:off": {
|
|
|
|
_attr: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
2019-04-09 05:27:18 -04:00
|
|
|
},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"a:prstGeom": [
|
|
|
|
{
|
|
|
|
_attr: {
|
|
|
|
prst: "rect",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-04-10 01:28:37 -04:00
|
|
|
"a:avLst": {},
|
2018-08-03 01:28:20 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|