diff options
author | Soreine <nicolas@gitbook.com> | 2016-05-03 16:02:58 +0200 |
---|---|---|
committer | Soreine <nicolas@gitbook.com> | 2016-05-03 16:02:58 +0200 |
commit | 3fc90554f5e7e6ff2fb4f023319799e1e8f81454 (patch) | |
tree | dc34d87ba50d004c9fac610a370432ae340ad498 /lib/modifiers/summary/__tests__ | |
parent | 4ebe28faaebb8752107ef6cfa6253f7b6f8a2a86 (diff) | |
download | gitbook-3fc90554f5e7e6ff2fb4f023319799e1e8f81454.zip gitbook-3fc90554f5e7e6ff2fb4f023319799e1e8f81454.tar.gz gitbook-3fc90554f5e7e6ff2fb4f023319799e1e8f81454.tar.bz2 |
Add tests, and fixes.
Diffstat (limited to 'lib/modifiers/summary/__tests__')
-rw-r--r-- | lib/modifiers/summary/__tests__/mergeAtLevel.js | 45 | ||||
-rw-r--r-- | lib/modifiers/summary/__tests__/moveArticle.js | 68 |
2 files changed, 113 insertions, 0 deletions
diff --git a/lib/modifiers/summary/__tests__/mergeAtLevel.js b/lib/modifiers/summary/__tests__/mergeAtLevel.js new file mode 100644 index 0000000..e2635ec --- /dev/null +++ b/lib/modifiers/summary/__tests__/mergeAtLevel.js @@ -0,0 +1,45 @@ +var Immutable = require('immutable'); +var Summary = require('../../../models/summary'); +var File = require('../../../models/file'); + +describe('mergeAtLevel', function() { + var mergeAtLevel = require('../mergeAtLevel'); + var summary = Summary.createFromParts(File(), [ + { + articles: [ + { + title: '1.1', + path: '1.1' + }, + { + title: '1.2', + path: '1.2' + } + ] + }, + { + title: 'Part I', + articles: [] + } + ]); + + it('should edit a part', function() { + var beforeChildren = summary.getByLevel('1').getArticles(); + var newSummary = mergeAtLevel(summary, '1', {title: 'Part O'}); + var edited = newSummary.getByLevel('1'); + + expect(edited.getTitle()).toBe('Part O'); + // Same children + expect(Immutable.is(beforeChildren, edited.getArticles())).toBe(true); + }); + + it('should edit a part', function() { + var beforePath = summary.getByLevel('1.2').getPath(); + var newSummary = mergeAtLevel(summary, '1.2', {title: 'Renamed article'}); + var edited = newSummary.getByLevel('1.2'); + + expect(edited.getTitle()).toBe('Renamed article'); + // Same children + expect(Immutable.is(beforePath, edited.getPath())).toBe(true); + }); +}); diff --git a/lib/modifiers/summary/__tests__/moveArticle.js b/lib/modifiers/summary/__tests__/moveArticle.js new file mode 100644 index 0000000..9a101f6 --- /dev/null +++ b/lib/modifiers/summary/__tests__/moveArticle.js @@ -0,0 +1,68 @@ +var Immutable = require('immutable'); +var Summary = require('../../../models/summary'); +var File = require('../../../models/file'); + +describe('moveArticle', function() { + var moveArticle = require('../moveArticle'); + var summary = Summary.createFromParts(File(), [ + { + articles: [ + { + title: '1.1', + path: '1.1' + }, + { + title: '1.2', + path: '1.2' + } + ] + }, + { + title: 'Part I', + articles: [ + { + title: '2.1', + path: '2.1', + articles: [ + { + title: '2.1.1', + path: '2.1.1' + }, + { + title: '2.1.2', + path: '2.1.2' + } + ] + }, + { + title: '2.2', + path: '2.2' + } + ] + } + ]); + + it('should move an article at in place', function() { + var newSummary = moveArticle(summary, '2.1', '2.1'); + + expect(Immutable.is(summary, newSummary)).toBe(true); + }); + + it('should move an article to an previous level', function() { + var newSummary = moveArticle(summary, '2.2', '2.1'); + var moved = newSummary.getByLevel('2.1'); + var other = newSummary.getByLevel('2.2'); + + expect(moved.getTitle()).toBe('2.2'); + expect(other.getTitle()).toBe('2.1'); + }); + + it('should move an article to a next level', function() { + var newSummary = moveArticle(summary, '2.1', '2.2'); + var moved = newSummary.getByLevel('2.1'); + var other = newSummary.getByLevel('2.2'); + + expect(moved.getTitle()).toBe('2.2'); + expect(other.getTitle()).toBe('2.1'); + }); +}); |