diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-11 13:57:21 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-11 13:57:21 +0200 |
commit | 7bd49606e3aceb4078258c6693f53bc129eb5b93 (patch) | |
tree | b61d65f716c402c847973186c6f1dd7b78311827 /lib/modifiers/summary/__tests__/moveArticleAfter.js | |
parent | d7c86353503106b2672b7948661c1c0aa9e727bb (diff) | |
parent | 19e9ff81d2d118bb45d8245da3f1ba4cad95416b (diff) | |
download | gitbook-7bd49606e3aceb4078258c6693f53bc129eb5b93.zip gitbook-7bd49606e3aceb4078258c6693f53bc129eb5b93.tar.gz gitbook-7bd49606e3aceb4078258c6693f53bc129eb5b93.tar.bz2 |
Merge pull request #1291 from GitbookIO/summary-modifiers
Summary modifiers
Diffstat (limited to 'lib/modifiers/summary/__tests__/moveArticleAfter.js')
-rw-r--r-- | lib/modifiers/summary/__tests__/moveArticleAfter.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/modifiers/summary/__tests__/moveArticleAfter.js b/lib/modifiers/summary/__tests__/moveArticleAfter.js new file mode 100644 index 0000000..c380575 --- /dev/null +++ b/lib/modifiers/summary/__tests__/moveArticleAfter.js @@ -0,0 +1,82 @@ +var Immutable = require('immutable'); +var Summary = require('../../../models/summary'); +var File = require('../../../models/file'); + +describe('moveArticleAfter', function() { + var moveArticleAfter = require('../moveArticleAfter'); + 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('moving right after itself should be invariant', function() { + var newSummary = moveArticleAfter(summary, '2.1', '2.1'); + + expect(Immutable.is(summary, newSummary)).toBe(true); + }); + + it('moving after previous one should be invariant too', function() { + var newSummary = moveArticleAfter(summary, '2.1', '2.0'); + + expect(Immutable.is(summary, newSummary)).toBe(true); + }); + + it('should move an article after a previous level', function() { + var newSummary = moveArticleAfter(summary, '2.2', '2.0'); + var moved = newSummary.getByLevel('2.1'); + + expect(moved.getTitle()).toBe('2.2'); + expect(newSummary.getByLevel('2.2').getTitle()).toBe('2.1'); + }); + + it('should move an article after a previous and less deep level', function() { + var newSummary = moveArticleAfter(summary, '2.1.1', '2.0'); + var moved = newSummary.getByLevel('2.1'); + + expect(moved.getTitle()).toBe('2.1.1'); + expect(newSummary.getByLevel('2.2.1').getTitle()).toBe('2.1.2'); + expect(newSummary.getByLevel('2.2').getTitle()).toBe('2.1'); + }); + + it('should move an article after a next level', function() { + var newSummary = moveArticleAfter(summary, '2.1', '2.2'); + var moved = newSummary.getByLevel('2.2'); + + expect(moved.getTitle()).toBe('2.1'); + expect(newSummary.getByLevel('2.1').getTitle()).toBe('2.2'); + }); + +}); |