Browse Source

SONAR-12255 Fix navigation blocks no longer opening when navigating to a URL

tags/8.2.0.32929
Wouter Admiraal 4 years ago
parent
commit
230d3af0d9

+ 1
- 1
server/sonar-docs/src/components/__tests__/Sidebar-test.tsx View File

@@ -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: {

+ 6
- 6
server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap View File

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

+ 3
- 0
server/sonar-docs/src/components/__tests__/navTreeUtils-test.ts View File

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

+ 5
- 4
server/sonar-docs/src/components/navTreeUtils.ts View File

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

Loading…
Cancel
Save