Add tests for SummaryModifier.editPartTitle

This commit is contained in:
Samy Pessé
2016-04-28 11:35:30 +02:00
parent e62bc31e63
commit 78e00db018
4 changed files with 57 additions and 6 deletions
-1
View File
@@ -1,4 +1,3 @@
jest.autoMockOff();
describe('Summary', function() {
var File = require('../file');
+11
View File
@@ -19,6 +19,17 @@ Summary.prototype.getParts = function() {
return this.get('parts');
};
/**
Return a part by its index
@param {Number}
@return {Part}
*/
Summary.prototype.getPart = function(i) {
var parts = this.getParts();
return parts.get(i);
};
/**
Return an article using an iterator to find it.
if "partIter" is set, it can also return a Part.
@@ -0,0 +1,44 @@
var Summary = require('../../../models/summary');
var File = require('../../../models/file');
describe('editPartTitle', function() {
var editPartTitle = require('../editPartTitle');
var summary = Summary.createFromParts(File(), [
{
articles: [
{
title: 'My First Article',
path: 'README.md'
},
{
title: 'My Second Article',
path: 'article.md'
}
]
},
{
title: 'Test'
}
]);
it('should correctly set title of first part', function() {
var newSummary = editPartTitle(summary, 0, 'Hello World');
var part = newSummary.getPart(0);
expect(part.getTitle()).toBe('Hello World');
});
it('should correctly set title of second part', function() {
var newSummary = editPartTitle(summary, 1, 'Hello');
var part = newSummary.getPart(1);
expect(part.getTitle()).toBe('Hello');
});
it('should not fail if part doesn\'t exist', function() {
var newSummary = editPartTitle(summary, 3, 'Hello');
expect(newSummary.getParts().size).toBe(2);
});
});
+2 -5
View File
@@ -16,10 +16,6 @@ function parseSummary(book) {
var logger = book.getLogger();
var readmeFile = readme.getFile();
if (!readmeFile.exists()) {
return Promise.reject(new Error('Summary parsing should be done after readme parsing'));
}
return parseStructureFile(book, 'summary')
.spread(function(file, result) {
if (!file) {
@@ -32,7 +28,8 @@ function parseSummary(book) {
// Insert readme as first entry
var firstArticle = summary.getFirstArticle();
if (!firstArticle || firstArticle.getRef() !== readmeFile.getPath()) {
if (readmeFile.exists() &&
(!firstArticle || firstArticle.getRef() !== readmeFile.getPath())) {
summary = SummaryModifier.unshiftArticle(summary, {
title: 'Introduction',
ref: readmeFile.getPath()