chore(v2): normalize url properly (#1105)

* refactor(v2): normalize url properly

* nits
This commit is contained in:
Endilie Yacop Sucipto 2018-11-12 00:25:13 +08:00 committed by GitHub
parent 34dcc0c22e
commit b84754dde8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 128 additions and 11 deletions

View file

@ -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);
});
});
});