mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-01 16:00:29 +02:00
chore(v2): normalize url properly (#1105)
* refactor(v2): normalize url properly * nits
This commit is contained in:
parent
34dcc0c22e
commit
b84754dde8
6 changed files with 128 additions and 11 deletions
|
@ -11,6 +11,7 @@ import {
|
|||
fileToComponentName,
|
||||
idx,
|
||||
getSubFolder,
|
||||
normalizeUrl,
|
||||
} from '@lib/load/utils';
|
||||
|
||||
describe('load utils', () => {
|
||||
|
@ -104,4 +105,48 @@ describe('load utils', () => {
|
|||
expect(getSubFolder(testD, 'docs')).toBe('ro');
|
||||
expect(getSubFolder(testE, 'docs')).toBeNull();
|
||||
});
|
||||
|
||||
test('normalizeUrl', () => {
|
||||
const asserts = [
|
||||
{
|
||||
input: ['/', '/'],
|
||||
output: '/',
|
||||
},
|
||||
{
|
||||
input: ['/', 'docs'],
|
||||
output: '/docs',
|
||||
},
|
||||
{
|
||||
input: ['/', 'docs', 'en', 'next', 'blog'],
|
||||
output: '/docs/en/next/blog',
|
||||
},
|
||||
{
|
||||
input: ['/test/', '/docs', 'ro', 'doc1'],
|
||||
output: '/test/docs/ro/doc1',
|
||||
},
|
||||
{
|
||||
input: ['', '/', 'ko', 'hello'],
|
||||
output: '/ko/hello',
|
||||
},
|
||||
{
|
||||
input: ['hello', 'world'],
|
||||
output: 'hello/world',
|
||||
},
|
||||
{
|
||||
input: ['http://www.google.com/', 'foo/bar', '?test=123'],
|
||||
output: 'http://www.google.com/foo/bar?test=123',
|
||||
},
|
||||
{
|
||||
input: ['http:', 'www.google.com///', 'foo/bar', '?test=123'],
|
||||
output: 'http://www.google.com/foo/bar?test=123',
|
||||
},
|
||||
{
|
||||
input: ['http://foobar.com', '', 'test'],
|
||||
output: 'http://foobar.com/test',
|
||||
},
|
||||
];
|
||||
asserts.forEach(testCase => {
|
||||
expect(normalizeUrl(testCase.input)).toBe(testCase.output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue