summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-18 14:47:53 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-18 14:47:53 +0100
commit709b388dfcc641fab25d297618b6ffe49f5cd677 (patch)
tree661973ac5d7de4bb32db33648ecb23e9bba6b00e /test
parent6e83240233e6168aa6567eb6fcac62508fe7fd0e (diff)
downloadgitbook-709b388dfcc641fab25d297618b6ffe49f5cd677.zip
gitbook-709b388dfcc641fab25d297618b6ffe49f5cd677.tar.gz
gitbook-709b388dfcc641fab25d297618b6ffe49f5cd677.tar.bz2
Fix path calcul to be coherant
Diffstat (limited to 'test')
-rw-r--r--test/location.js16
-rw-r--r--test/page.js102
2 files changed, 95 insertions, 23 deletions
diff --git a/test/location.js b/test/location.js
index 4d949fa..2f209e0 100644
--- a/test/location.js
+++ b/test/location.js
@@ -16,7 +16,21 @@ describe('Location', function() {
location.isAnchor('test.md#test').should.be.exactly(false);
});
- describe('toAbsolute', function() {
+ describe('.relative', function() {
+ it('should resolve to a relative path (same folder)', function() {
+ location.relative('links/', 'links/test.md').should.equal('test.md');
+ });
+
+ it('should resolve to a relative path (parent folder)', function() {
+ location.relative('links/', 'test.md').should.equal('../test.md');
+ });
+
+ it('should resolve to a relative path (child folder)', function() {
+ location.relative('links/', 'links/hello/test.md').should.equal('hello/test.md');
+ });
+ });
+
+ describe('.toAbsolute', function() {
it('should correctly transform as absolute', function() {
location.toAbsolute('http://google.fr').should.be.equal('http://google.fr');
location.toAbsolute('test.md', './', './').should.be.equal('test.md');
diff --git a/test/page.js b/test/page.js
index b68e894..41a0893 100644
--- a/test/page.js
+++ b/test/page.js
@@ -7,7 +7,9 @@ describe('Page', function() {
before(function() {
return mock.setupDefaultBook({
'heading.md': '# Hello\n\n## World',
+
'links.md': '[link](hello.md) [link 2](variables/page/next.md) [readme](README.md)',
+ 'links/relative.md': '[link](../hello.md) [link 2](/variables/page/next.md) [readme](../README.md)',
'annotations/simple.md': 'A magicien say abracadabra!',
'annotations/code.md': 'A magicien say `abracadabra`!',
@@ -71,12 +73,12 @@ describe('Page', function() {
describe('.relative', function() {
it('should correctly resolve absolute path in the book', function() {
var page = book.addPage('heading.md');
- var page2 = book.addPage('folder/paths.md');
-
page.relative('/test.png').should.equal('test.png');
page.relative('test.png').should.equal('test.png');
+
+ var page2 = book.addPage('folder/paths.md');
page2.relative('/test.png').should.equal('../test.png');
- page2.relative('test.png').should.equal('test.png');
+ page2.relative('test.png').should.equal('../test.png');
});
});
@@ -126,35 +128,91 @@ describe('Page', function() {
});
});
- describe('Links', function() {
+ describe('.resolve', function() {
var page;
before(function() {
- page = book.addPage('links.md');
- return page.toHTML(output);
+ page = book.addPage('links/relative.md');
});
- it('should replace links to page to .html', function() {
- page.content.should.be.html({
- 'a[href="./"]': {
- count: 1
- }
- });
+ it('should resolve to a relative path (same folder)', function() {
+ page.relative('links/test.md').should.equal('test.md');
});
- it('should use directory urls when file is a README', function() {
- page.content.should.be.html({
- 'a[href="./"]': {
- count: 1
- }
+ it('should resolve to a relative path (parent folder)', function() {
+ page.relative('test.md').should.equal('../test.md');
+ page.relative('hello/test.md').should.equal('../hello/test.md');
+ });
+
+ it('should resolve to a relative path (child folder)', function() {
+ page.relative('links/hello/test.md').should.equal('hello/test.md');
+ });
+ });
+
+ describe('Links', function() {
+ describe('From base directory', function() {
+ var page;
+
+ before(function() {
+ page = book.addPage('links.md');
+ return page.toHTML(output);
+ });
+
+ it('should replace links to page to .html', function() {
+ page.content.should.be.html({
+ 'a[href="variables/page/next.html"]': {
+ count: 1
+ }
+ });
+ });
+
+ it('should use directory urls when file is a README', function() {
+ page.content.should.be.html({
+ 'a[href="./"]': {
+ count: 1
+ }
+ });
+ });
+
+ it('should not replace links to file not in SUMMARY', function() {
+ page.content.should.be.html({
+ 'a[href="hello.md"]': {
+ count: 1
+ }
+ });
});
});
- it('should not replace links to file not in SUMMARY', function() {
- page.content.should.be.html({
- 'a[href="hello.md"]': {
- count: 1
- }
+ describe('From sub-directory', function() {
+ var page;
+
+ before(function() {
+ page = book.addPage('links/relative.md');
+ return page.toHTML(output);
+ });
+
+ it('should replace links to page to .html', function() {
+ page.content.should.be.html({
+ 'a[href="../variables/page/next.html"]': {
+ count: 1
+ }
+ });
+ });
+
+ it('should use directory urls when file is a README', function() {
+ page.content.should.be.html({
+ 'a[href="../"]': {
+ count: 1
+ }
+ });
+ });
+
+ it('should not replace links to file not in SUMMARY', function() {
+ page.content.should.be.html({
+ 'a[href="../hello.md"]': {
+ count: 1
+ }
+ });
});
});
});