diff options
| author | Craig Leinoff <leinoff@un.org> | 2014-01-07 14:31:41 -0500 |
|---|---|---|
| committer | Craig Leinoff <leinoff@un.org> | 2014-01-07 14:31:41 -0500 |
| commit | 51c625fb8474bcf790a0341ae5bbabb1316a2583 (patch) | |
| tree | ea21f928d428099dc6f8a1efe28993a725d229bd /tests | |
| parent | 05e67a227cabe6e2b0ddefae13570465b5de7ce4 (diff) | |
Fixing unit tests for style application.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/style-applicator.tests.js | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/tests/style-applicator.tests.js b/tests/style-applicator.tests.js index 26e00e0..3164fa2 100644 --- a/tests/style-applicator.tests.js +++ b/tests/style-applicator.tests.js @@ -1,39 +1,57 @@ var assert = require("assert");
-var StyleApplicator = require("../lib/style-applicator").StyleApplicator;
var documents = require("../lib/documents");
var testing = require("./testing");
var test = testing.test;
-var testData = testing.testData;
+var style = require("../lib/style-reader").readStyle;
describe("style-applicator", function() {
- test("can process styleless document with single, center-aligned paragraph", function() {
+ test("can use custom documentTransform to process styleless center-aligned paragraph into h2.centerAlign", function() {
var testOptions = {
- styleMap: [],
- styleApplicator: {
- alignment: true
- }
+ styleMap: [
+ style("p.centerAligned => h2.sectionHeader:fresh")
+ ],
+ transformDocument: transformDocument
};
var testDocument = documents.Document([
documents.Paragraph([
documents.Run([
- documents.Text("Test document with centered paragraph.")
+ documents.Text("Test.")
])
], {alignment: 'center'})
]);
var expectedDocument = documents.Document([
documents.Paragraph([
documents.Run([
- documents.Text("Test document with centered paragraph.")
+ documents.Text("Test.")
])
], {styleName: 'centerAligned', alignment: 'center'})
]);
- var styleApplicator = new StyleApplicator(testOptions);
- return styleApplicator.processDocumentStyles(testDocument).then(function(result) {
- assert.deepEqual(expectedDocument, result);
- });
+ assert.deepEqual(expectedDocument, transformDocument(testDocument));
});
-});
\ No newline at end of file +});
+
+function transformDocument(document) {
+ if (document.children) {
+ for (var i = 0; i < document.children.length; i++) {
+ var element = document.children[i];
+ switch (element.type) {
+ case 'paragraph':
+ document.children[i] = processParagraphStyles(document.children[i]);
+ break;
+ }
+ }
+ }
+ return document;
+}
+function processParagraphStyles(element) {
+ if (!element.styleName) {
+ if (element.alignment) {
+ element.styleName = element.alignment+"Aligned";
+ }
+ }
+ return element;
+}
\ No newline at end of file |
