diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-04-22 11:33:59 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-04-22 11:33:59 +0100 |
| commit | 15bf7ff1863049a7cad09719fa90b0e416b7715b (patch) | |
| tree | d4281becce7ef2e7f62a7dc93717f306bc312909 /tests | |
| parent | 7cad7ca1dcdf48ac826c54e33629bb961c7380dd (diff) | |
Read character styles from styles.xml
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/docx/styles-reader.tests.js | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index dd82602..274f822 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -18,11 +18,43 @@ describe('readStylesXml', function() { test('paragraph style can be found by ID', function() { var styles = readStylesXml({ root: new XmlElement("w:styles", {}, [ - new XmlElement("w:style", {"w:styleId": "Heading1"}, [ - new XmlElement("w:name", {"w:val": "Heading 1"}, []) - ]) + paragraphStyleElement("Heading1", "Heading 1") ]) }); assert.equal(styles.findParagraphStyleById("Heading1").styleId, "Heading1"); }); + + test('character style can be found by ID', function() { + var styles = readStylesXml({ + root: new XmlElement("w:styles", {}, [ + characterStyleElement("Heading1Char", "Heading 1 Char") + ]) + }); + assert.equal(styles.findCharacterStyleById("Heading1Char").styleId, "Heading1Char"); + }); + + test('paragraph and character styles are distinct', function() { + var styles = readStylesXml({ + root: new XmlElement("w:styles", {}, [ + paragraphStyleElement("Heading1", "Heading 1"), + characterStyleElement("Heading1Char", "Heading 1 Char") + ]) + }); + assert.equal(styles.findCharacterStyleById("Heading1"), null); + assert.equal(styles.findParagraphStyleById("Heading1Char"), null); + }); }); + +function paragraphStyleElement(id, name) { + return styleElement("paragraph", id, name); +} + +function characterStyleElement(id, name) { + return styleElement("character", id, name); +} + +function styleElement(type, id, name) { + return new XmlElement("w:style", {"w:type": type, "w:styleId": id}, [ + new XmlElement("w:name", {"w:val": name}, []) + ]); +} |
