From c608d035569e16c81ea29ecf2a904e227379cecd Mon Sep 17 00:00:00 2001 From: jaceyshome Date: Thu, 21 May 2015 21:14:15 +1000 Subject: styles names should be null by default --- lib/docx/styles-reader.js | 7 ++++++- tests/docx/styles-reader.tests.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js index dc90bc1..fec1cf2 100644 --- a/lib/docx/styles-reader.js +++ b/lib/docx/styles-reader.js @@ -36,6 +36,11 @@ function readStylesXml(xml) { function readStyleElement(styleElement) { var type = styleElement.attributes["w:type"]; var styleId = styleElement.attributes["w:styleId"]; - var name = styleElement.first("w:name").attributes["w:val"]; + var name = styleName(styleElement); return {type: type, styleId: styleId, name: name}; } + +function styleName(styleElement) { + var nameElement = styleElement.first("w:name"); + return nameElement ? nameElement.attributes["w:val"] : null; +} diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index 7899b1b..f76dfc2 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -59,6 +59,17 @@ describe('readStylesXml', function() { }); assert.equal(styles.findParagraphStyleById("Heading1").name, "Heading 1"); }); + + test('styles names should be null by default', function() { + var styles = readStylesXml({ + root: new XmlElement("w:styles", {}, [ + paragraphStyleElement("Heading1", null), + characterStyleElement("Heading1Char", null) + ]) + }); + assert.equal(styles.findParagraphStyleById("Heading1Char"), null); + assert.equal(styles.findCharacterStyleById("Heading1"), null); + }); }); function paragraphStyleElement(id, name) { -- cgit v1.2.3 From 68350464a52e38e3e1b32132195a7b7ea2427b42 Mon Sep 17 00:00:00 2001 From: jaceyshome Date: Fri, 22 May 2015 23:17:43 +1000 Subject: change indent to 4 spaces --- lib/docx/styles-reader.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js index fec1cf2..3419ac4 100644 --- a/lib/docx/styles-reader.js +++ b/lib/docx/styles-reader.js @@ -41,6 +41,6 @@ function readStyleElement(styleElement) { } function styleName(styleElement) { - var nameElement = styleElement.first("w:name"); - return nameElement ? nameElement.attributes["w:val"] : null; + var nameElement = styleElement.first("w:name"); + return nameElement ? nameElement.attributes["w:val"] : null; } -- cgit v1.2.3 From 429af29e958c8084d27f39a3c9685c043d1f6df3 Mon Sep 17 00:00:00 2001 From: jaceyshome Date: Sat, 23 May 2015 11:55:25 +1000 Subject: fixed styles reader text case: 'styles names should be null by default' --- tests/docx/styles-reader.tests.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index f76dfc2..bd28673 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -61,15 +61,16 @@ describe('readStylesXml', function() { }); test('styles names should be null by default', function() { - var styles = readStylesXml({ - root: new XmlElement("w:styles", {}, [ - paragraphStyleElement("Heading1", null), - characterStyleElement("Heading1Char", null) - ]) - }); - assert.equal(styles.findParagraphStyleById("Heading1Char"), null); - assert.equal(styles.findCharacterStyleById("Heading1"), null); + var styles = readStylesXml({ + root: new XmlElement("w:styles", {}, [ + unusualStyleElement("paragraph", "Heading1", "Heading 1"), + unusualStyleElement("character", "Heading1Char", "Heading1Char 1") + ]) + }); + assert.equal(styles.findParagraphStyleById("Heading1").name, null); + assert.equal(styles.findCharacterStyleById("Heading1Char").name, null); }); + }); function paragraphStyleElement(id, name) { @@ -85,3 +86,9 @@ function styleElement(type, id, name) { new XmlElement("w:name", {"w:val": name}, []) ]); } + +function unusualStyleElement(type, id, name) { + return new XmlElement("w:style", {"w:type": type, "w:styleId": id}, [ + new XmlElement("w:notName", {"w:val": name}, []) + ]); +} -- cgit v1.2.3 From 6c2286b03121712112c0d8a1e7379d524c9a8cdd Mon Sep 17 00:00:00 2001 From: jaceyshome Date: Sat, 23 May 2015 12:33:25 +1000 Subject: rename the styles-reader.tests last case to 'style name is null if w:name element does not exist' --- tests/docx/styles-reader.tests.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index bd28673..0bbc8ff 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -60,11 +60,11 @@ describe('readStylesXml', function() { assert.equal(styles.findParagraphStyleById("Heading1").name, "Heading 1"); }); - test('styles names should be null by default', function() { + test('style name is null if w:name element does not exist', function() { var styles = readStylesXml({ root: new XmlElement("w:styles", {}, [ - unusualStyleElement("paragraph", "Heading1", "Heading 1"), - unusualStyleElement("character", "Heading1Char", "Heading1Char 1") + styleWithoutWNameElement("paragraph", "Heading1", "Heading 1"), + styleWithoutWNameElement("character", "Heading1Char", "Heading1Char 1") ]) }); assert.equal(styles.findParagraphStyleById("Heading1").name, null); @@ -87,7 +87,7 @@ function styleElement(type, id, name) { ]); } -function unusualStyleElement(type, id, name) { +function styleWithoutWNameElement(type, id, name) { return new XmlElement("w:style", {"w:type": type, "w:styleId": id}, [ new XmlElement("w:notName", {"w:val": name}, []) ]); -- cgit v1.2.3 From 499eb4cec34350f3e62c4e09ce3b791eb38b334d Mon Sep 17 00:00:00 2001 From: jaceyshome Date: Sat, 23 May 2015 12:33:25 +1000 Subject: rename the styles-reader.tests last case to 'style name is null if w:name element does not exist' --- tests/docx/styles-reader.tests.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index bd28673..0bbc8ff 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -60,11 +60,11 @@ describe('readStylesXml', function() { assert.equal(styles.findParagraphStyleById("Heading1").name, "Heading 1"); }); - test('styles names should be null by default', function() { + test('style name is null if w:name element does not exist', function() { var styles = readStylesXml({ root: new XmlElement("w:styles", {}, [ - unusualStyleElement("paragraph", "Heading1", "Heading 1"), - unusualStyleElement("character", "Heading1Char", "Heading1Char 1") + styleWithoutWNameElement("paragraph", "Heading1", "Heading 1"), + styleWithoutWNameElement("character", "Heading1Char", "Heading1Char 1") ]) }); assert.equal(styles.findParagraphStyleById("Heading1").name, null); @@ -87,7 +87,7 @@ function styleElement(type, id, name) { ]); } -function unusualStyleElement(type, id, name) { +function styleWithoutWNameElement(type, id, name) { return new XmlElement("w:style", {"w:type": type, "w:styleId": id}, [ new XmlElement("w:notName", {"w:val": name}, []) ]); -- cgit v1.2.3 From 60d6d9e584c44c3beae16110b6685a0a86bc38b4 Mon Sep 17 00:00:00 2001 From: jaceyshome Date: Sun, 24 May 2015 09:42:02 +1000 Subject: remove redundant code in styles-reader test case 'style name is null if w:name element does not exist' --- tests/docx/styles-reader.tests.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/docx/styles-reader.tests.js b/tests/docx/styles-reader.tests.js index 0bbc8ff..73a9050 100644 --- a/tests/docx/styles-reader.tests.js +++ b/tests/docx/styles-reader.tests.js @@ -63,8 +63,8 @@ describe('readStylesXml', function() { test('style name is null if w:name element does not exist', function() { var styles = readStylesXml({ root: new XmlElement("w:styles", {}, [ - styleWithoutWNameElement("paragraph", "Heading1", "Heading 1"), - styleWithoutWNameElement("character", "Heading1Char", "Heading1Char 1") + styleWithoutWNameElement("paragraph", "Heading1"), + styleWithoutWNameElement("character", "Heading1Char") ]) }); assert.equal(styles.findParagraphStyleById("Heading1").name, null); @@ -87,8 +87,6 @@ function styleElement(type, id, name) { ]); } -function styleWithoutWNameElement(type, id, name) { - return new XmlElement("w:style", {"w:type": type, "w:styleId": id}, [ - new XmlElement("w:notName", {"w:val": name}, []) - ]); +function styleWithoutWNameElement(type, id) { + return new XmlElement("w:style", {"w:type": type, "w:styleId": id}, []); } -- cgit v1.2.3