2017-03-09 19:50:33 +01:00
|
|
|
import { expect } from "chai";
|
2016-04-03 20:00:30 +01:00
|
|
|
|
2017-03-09 19:50:33 +01:00
|
|
|
import { Formatter } from "../export/formatter";
|
|
|
|
import { Properties } from "../properties";
|
2016-04-03 20:00:30 +01:00
|
|
|
|
|
|
|
describe("Properties", () => {
|
|
|
|
|
|
|
|
describe("#constructor()", () => {
|
2017-03-09 19:50:33 +01:00
|
|
|
it("sets the appropriate attributes on the top-level", () => {
|
|
|
|
const properties = new Properties({});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]);
|
|
|
|
expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array);
|
|
|
|
expect(tree["cp:coreProperties"][0]).to.deep.equal({
|
|
|
|
_attr: {
|
|
|
|
"xmlns:cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
|
|
|
|
"xmlns:dc": "http://purl.org/dc/elements/1.1/",
|
|
|
|
"xmlns:dcmitype": "http://purl.org/dc/dcmitype/",
|
|
|
|
"xmlns:dcterms": "http://purl.org/dc/terms/",
|
|
|
|
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-03 20:00:30 +01:00
|
|
|
it("should create properties with a title", () => {
|
2017-03-09 19:50:33 +01:00
|
|
|
const properties = new Properties({title: "test document"});
|
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]);
|
|
|
|
expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array);
|
|
|
|
expect(Object.keys(tree["cp:coreProperties"][0])).to.deep.equal(["_attr"]);
|
|
|
|
expect(tree["cp:coreProperties"][1]).to.deep.equal(
|
|
|
|
{"dc:title": ["test document"]},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create properties with all the attributes given", () => {
|
|
|
|
const properties = new Properties({
|
|
|
|
title: "test document",
|
|
|
|
subject: "test subject",
|
|
|
|
creator: "me",
|
|
|
|
keywords: "test docx",
|
|
|
|
description: "testing document",
|
|
|
|
lastModifiedBy: "the author",
|
|
|
|
revision: "123",
|
2016-04-03 20:00:30 +01:00
|
|
|
});
|
2017-03-09 19:50:33 +01:00
|
|
|
const tree = new Formatter().format(properties);
|
|
|
|
expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]);
|
|
|
|
expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array);
|
|
|
|
const key = (obj) => Object.keys(obj)[0];
|
|
|
|
const props = tree["cp:coreProperties"].map(key).sort();
|
|
|
|
expect(props).to.deep.equal([
|
|
|
|
"_attr",
|
|
|
|
"cp:keywords",
|
|
|
|
"cp:lastModifiedBy",
|
|
|
|
"cp:revision",
|
|
|
|
"dc:creator",
|
|
|
|
"dc:description",
|
|
|
|
"dc:subject",
|
|
|
|
"dc:title",
|
|
|
|
"dcterms:created",
|
|
|
|
"dcterms:modified",
|
|
|
|
]);
|
|
|
|
expect(tree["cp:coreProperties"].slice(1, -2).sort((a, b) => key(a) < key(b) ? -1 : 1)).to.deep.equal([
|
|
|
|
{"cp:keywords": ["test docx"]},
|
|
|
|
{"cp:lastModifiedBy": ["the author"]},
|
|
|
|
{"cp:revision": ["123"]},
|
|
|
|
{"dc:creator": ["me"]},
|
|
|
|
{"dc:description": ["testing document"]},
|
|
|
|
{"dc:subject": ["test subject"]},
|
|
|
|
{"dc:title": ["test document"]},
|
|
|
|
]);
|
2016-04-03 20:00:30 +01:00
|
|
|
});
|
2016-05-26 15:08:34 +01:00
|
|
|
});
|
2017-03-09 19:50:33 +01:00
|
|
|
});
|