mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
IE compatibility and add unit tests
This commit is contained in:
parent
31654f12ec
commit
ca8ae50717
@ -74,11 +74,11 @@ export class History {
|
||||
if (local) {
|
||||
const idIndex = currentRoute.indexOf('?')
|
||||
path =
|
||||
(idIndex > 0 ? currentRoute.substr(0, idIndex) : currentRoute) + path
|
||||
(idIndex > 0 ? currentRoute.substring(0, idIndex) : currentRoute) + path
|
||||
}
|
||||
|
||||
if (this.config.relativePath && !path.startsWith('/')) {
|
||||
const currentDir = currentRoute.substr(0, currentRoute.lastIndexOf('/') + 1)
|
||||
if (this.config.relativePath && path.indexOf('/') !== 0) {
|
||||
const currentDir = currentRoute.substring(0, currentRoute.lastIndexOf('/') + 1)
|
||||
return cleanPath(resolvePath(currentDir + path))
|
||||
}
|
||||
return cleanPath('/' + path)
|
||||
|
||||
62
test/unit/base.js
Normal file
62
test/unit/base.js
Normal file
@ -0,0 +1,62 @@
|
||||
/* eslint-env node, chai, mocha */
|
||||
require = require('esm')(module/*, options*/)
|
||||
const {expect} = require('chai')
|
||||
const {History} = require('../../src/core/router/history/base')
|
||||
|
||||
class MockHistory extends History {
|
||||
parse(path) {
|
||||
return {path}
|
||||
}
|
||||
}
|
||||
|
||||
describe('router/history/base', function () {
|
||||
describe('relativePath true', function () {
|
||||
var history
|
||||
|
||||
beforeEach(function () {
|
||||
history = new MockHistory({relativePath: true})
|
||||
})
|
||||
|
||||
it('toURL', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('guide.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/zh-ch/guide')
|
||||
})
|
||||
|
||||
it('toURL with double dot', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('../README.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
|
||||
it('toURL child path', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('config/example.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/zh-ch/config/example')
|
||||
})
|
||||
|
||||
it('toURL absolute path', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('/README', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
})
|
||||
|
||||
it('toURL without relative path', function () {
|
||||
const history = new MockHistory({relativePath: false})
|
||||
|
||||
// WHEN
|
||||
const url = history.toURL('README', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
})
|
||||
30
test/unit/util.js
Normal file
30
test/unit/util.js
Normal file
@ -0,0 +1,30 @@
|
||||
/* eslint-env node, chai, mocha */
|
||||
require = require('esm')(module/*, options*/)
|
||||
const {expect} = require('chai')
|
||||
const {resolvePath} = require('../../src/core/router/util')
|
||||
|
||||
describe('router/util', function () {
|
||||
it('resolvePath', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
|
||||
it('resolvePath with dot', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('./hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
|
||||
it('resolvePath with two dots', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('test/../hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user