@@ -72,7 +72,7 @@ it('should render correctly', () => { | |||
function shallowRender(props: Partial<Sidebar['props']> = {}) { | |||
return shallow( | |||
<Sidebar | |||
location={{ pathname: '/foo/baz/foo/bar' } as Location} | |||
location={{ pathname: '/2.0/foo/baz/foo/bar' } as Location} | |||
pages={[ | |||
{ | |||
fields: { |
@@ -105,7 +105,7 @@ exports[`should render correctly 1`] = ` | |||
key="/foo/" | |||
location={ | |||
Object { | |||
"pathname": "/foo/baz/foo/bar", | |||
"pathname": "/2.0/foo/baz/foo/bar", | |||
} | |||
} | |||
node={ | |||
@@ -123,7 +123,7 @@ exports[`should render correctly 1`] = ` | |||
key="Foo subs" | |||
location={ | |||
Object { | |||
"pathname": "/foo/baz/foo/bar", | |||
"pathname": "/2.0/foo/baz/foo/bar", | |||
} | |||
} | |||
openByDefault={true} | |||
@@ -133,7 +133,7 @@ exports[`should render correctly 1`] = ` | |||
key="Foo Baz subs" | |||
location={ | |||
Object { | |||
"pathname": "/foo/baz/foo/bar", | |||
"pathname": "/2.0/foo/baz/foo/bar", | |||
} | |||
} | |||
openByDefault={true} | |||
@@ -144,7 +144,7 @@ exports[`should render correctly 1`] = ` | |||
key="Foo Baz Foo subs" | |||
location={ | |||
Object { | |||
"pathname": "/foo/baz/foo/bar", | |||
"pathname": "/2.0/foo/baz/foo/bar", | |||
} | |||
} | |||
openByDefault={true} | |||
@@ -157,7 +157,7 @@ exports[`should render correctly 1`] = ` | |||
key="/bar/" | |||
location={ | |||
Object { | |||
"pathname": "/foo/baz/foo/bar", | |||
"pathname": "/2.0/foo/baz/foo/bar", | |||
} | |||
} | |||
node={ | |||
@@ -175,7 +175,7 @@ exports[`should render correctly 1`] = ` | |||
key="Bar subs" | |||
location={ | |||
Object { | |||
"pathname": "/foo/baz/foo/bar", | |||
"pathname": "/2.0/foo/baz/foo/bar", | |||
} | |||
} | |||
openByDefault={false} |
@@ -67,6 +67,7 @@ describe('getUrlsList', () => { | |||
describe('getOpenChainFromPath', () => { | |||
it('should correctly fetch the chain of open elements for a given path', () => { | |||
expect(getOpenChainFromPath('path/value/', navTree)).toEqual([navTree[0]]); | |||
expect(getOpenChainFromPath('latest/path/value/', navTree)).toEqual([navTree[0]]); | |||
expect(getOpenChainFromPath('sub/child/path/3', navTree)).toEqual([ | |||
navTree[1], | |||
(navTree as any)[1].children[1], | |||
@@ -83,5 +84,7 @@ describe('testPathAgainstUrl', () => { | |||
expect(testPathAgainstUrl('path/foo', 'path/foo/')).toBe(true); | |||
expect(testPathAgainstUrl('/path/foo/', 'path/foo')).toBe(true); | |||
expect(testPathAgainstUrl('path/foo', '/path/foo/')).toBe(true); | |||
expect(testPathAgainstUrl('/path/foo', '/1.0/path/foo/')).toBe(true); | |||
expect(testPathAgainstUrl('/path/foo', '/latest/path/foo/')).toBe(true); | |||
}); | |||
}); |
@@ -85,10 +85,11 @@ export function isDocsNavigationExternalLink( | |||
} | |||
export function testPathAgainstUrl(path: string, url: string) { | |||
return trimSlashes(url).replace(/^(latest|\d+\.\d+)\//, '') === trimSlashes(path); | |||
} | |||
function trimSlashes(string: string) { | |||
const leadingRegEx = /^\//; | |||
const trailingRegEx = /\/$/; | |||
return ( | |||
path.replace(leadingRegEx, '').replace(trailingRegEx, '') === | |||
url.replace(leadingRegEx, '').replace(trailingRegEx, '') | |||
); | |||
return string.replace(leadingRegEx, '').replace(trailingRegEx, ''); | |||
} |