summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/modifiers/summary/__tests__/insertPart.js60
-rw-r--r--lib/parse/lookupStructureFile.js2
2 files changed, 61 insertions, 1 deletions
diff --git a/lib/modifiers/summary/__tests__/insertPart.js b/lib/modifiers/summary/__tests__/insertPart.js
new file mode 100644
index 0000000..11c2cbc
--- /dev/null
+++ b/lib/modifiers/summary/__tests__/insertPart.js
@@ -0,0 +1,60 @@
+var Summary = require('../../../models/summary');
+var SummaryPart = require('../../../models/summaryPart');
+
+var File = require('../../../models/file');
+
+describe('insertPart', function() {
+ var insertPart = require('../insertPart');
+ var summary = Summary.createFromParts(File(), [
+ {
+ articles: [
+ {
+ title: '1.1',
+ path: '1.1'
+ }
+ ]
+ },
+ {
+ title: 'Part I',
+ articles: [
+ {
+ title: '2.1',
+ path: '2.1',
+ articles: []
+ },
+ {
+ title: '2.2',
+ path: '2.2'
+ }
+ ]
+ }
+ ]);
+
+ it('should insert an part at a given level', function() {
+ var part = SummaryPart.create({
+ title: 'Inserted'
+ }, 'meaningless.level');
+
+ var newSummary = insertPart(summary, part, 1);
+
+ var inserted = newSummary.getPart(1);
+ expect(inserted.getTitle()).toBe('Inserted');
+ expect(newSummary.getParts().count()).toBe(3);
+
+ var otherArticle = newSummary.getByLevel('3.1');
+ expect(otherArticle.getTitle()).toBe('2.1');
+ expect(otherArticle.getLevel()).toBe('3.1');
+ });
+
+ it('should insert an part in last position', function() {
+ var part = SummaryPart.create({
+ title: 'Inserted'
+ }, 'meaningless.level');
+
+ var newSummary = insertPart(summary, part, 2);
+
+ var inserted = newSummary.getPart(2);
+ expect(inserted.getTitle()).toBe('Inserted');
+ expect(newSummary.getParts().count()).toBe(3);
+ });
+});
diff --git a/lib/parse/lookupStructureFile.js b/lib/parse/lookupStructureFile.js
index d4a8f02..36b37f8 100644
--- a/lib/parse/lookupStructureFile.js
+++ b/lib/parse/lookupStructureFile.js
@@ -6,7 +6,7 @@ var findParsableFile = require('./findParsableFile');
@param {Book} book
@param {String} type: one of ["glossary", "readme", "summary", "langs"]
- @return {Promise<File>} The path of the file found, relative
+ @return {Promise<File | Undefined>} The path of the file found, relative
to the book content root.
*/
function lookupStructureFile(book, type) {