Skip to content

Commit

Permalink
Add method "createChildLevel" to SummaryPart
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Jun 10, 2016
1 parent 59be32a commit 50a132c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
23 changes: 23 additions & 0 deletions lib/models/__tests__/summaryPart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var SummaryPart = require('../summaryPart');

describe('SummaryPart', function() {
describe('createChildLevel', function() {
it('must create the right level', function() {
var article = SummaryPart.create({}, '1');
expect(article.createChildLevel()).toBe('1.1');
});

it('must create the right level when has articles', function() {
var article = SummaryPart.create({
articles: [
{
title: 'Test'
}
]
}, '1');
expect(article.createChildLevel()).toBe('1.2');
});
});
});


21 changes: 17 additions & 4 deletions lib/models/summaryPart.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,24 @@ SummaryPart.prototype.getArticles = function() {
};

/**
Create a SummaryPart
* Create a new level for a new child article
*
* @return {String}
*/
SummaryPart.prototype.createChildLevel = function() {
var level = this.getLevel();
var subArticles = this.getArticles();
var childLevel = level + '.' + (subArticles.size + 1);

return childLevel;
};

@param {Object} def
@return {SummaryPart}
*/
/**
* Create a SummaryPart
*
* @param {Object} def
* @return {SummaryPart}
*/
SummaryPart.create = function(def, level) {
var articles = (def.articles || []).map(function(article, i) {
if (article instanceof SummaryArticle) {
Expand Down

0 comments on commit 50a132c

Please sign in to comment.