aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-docs/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-docs/src')
-rw-r--r--server/sonar-docs/src/components/__tests__/Sidebar-test.tsx2
-rw-r--r--server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap12
-rw-r--r--server/sonar-docs/src/components/__tests__/navTreeUtils-test.ts3
-rw-r--r--server/sonar-docs/src/components/navTreeUtils.ts9
4 files changed, 15 insertions, 11 deletions
diff --git a/server/sonar-docs/src/components/__tests__/Sidebar-test.tsx b/server/sonar-docs/src/components/__tests__/Sidebar-test.tsx
index b0ce00807d2..4ea1e61dcb2 100644
--- a/server/sonar-docs/src/components/__tests__/Sidebar-test.tsx
+++ b/server/sonar-docs/src/components/__tests__/Sidebar-test.tsx
@@ -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: {
diff --git a/server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap b/server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap
index eb4f5d4325c..5a05f9b2671 100644
--- a/server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap
+++ b/server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap
@@ -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}
diff --git a/server/sonar-docs/src/components/__tests__/navTreeUtils-test.ts b/server/sonar-docs/src/components/__tests__/navTreeUtils-test.ts
index 689a1ba3682..e28d4106d14 100644
--- a/server/sonar-docs/src/components/__tests__/navTreeUtils-test.ts
+++ b/server/sonar-docs/src/components/__tests__/navTreeUtils-test.ts
@@ -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);
});
});
diff --git a/server/sonar-docs/src/components/navTreeUtils.ts b/server/sonar-docs/src/components/navTreeUtils.ts
index a7663086ecc..f8e42dda9e4 100644
--- a/server/sonar-docs/src/components/navTreeUtils.ts
+++ b/server/sonar-docs/src/components/navTreeUtils.ts
@@ -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, '');
}