summaryrefslogtreecommitdiffstats
path: root/lib/modifiers/summary/__tests__/moveArticle.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-05-04 09:47:50 +0200
committerSamy Pessé <samypesse@gmail.com>2016-05-04 09:47:50 +0200
commit5d11641a5f4ff607068d871f48a842ecc1d65bf1 (patch)
treea04b4bc79fa6e5215f8b4934c6f9c8805a007468 /lib/modifiers/summary/__tests__/moveArticle.js
parent24d38e4fcfbbab2a42f49c6085f30f5d4544b217 (diff)
parent3fc90554f5e7e6ff2fb4f023319799e1e8f81454 (diff)
downloadgitbook-5d11641a5f4ff607068d871f48a842ecc1d65bf1.zip
gitbook-5d11641a5f4ff607068d871f48a842ecc1d65bf1.tar.gz
gitbook-5d11641a5f4ff607068d871f48a842ecc1d65bf1.tar.bz2
Merge pull request #1260 from GitbookIO/move-article
Adds move and remove article modifier.
Diffstat (limited to 'lib/modifiers/summary/__tests__/moveArticle.js')
-rw-r--r--lib/modifiers/summary/__tests__/moveArticle.js68
1 files changed, 68 insertions, 0 deletions
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');
+ });
+});