]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12255 Fix navigation blocks no longer opening when navigating to a URL
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Mon, 30 Dec 2019 15:00:54 +0000 (16:00 +0100)
committerSonarTech <sonartech@sonarsource.com>
Wed, 8 Jan 2020 19:46:11 +0000 (20:46 +0100)
server/sonar-docs/src/components/__tests__/Sidebar-test.tsx
server/sonar-docs/src/components/__tests__/__snapshots__/Sidebar-test.tsx.snap
server/sonar-docs/src/components/__tests__/navTreeUtils-test.ts
server/sonar-docs/src/components/navTreeUtils.ts

index b0ce00807d2fcc4761860c9ab7efc9e674d6d9f9..4ea1e61dcb2fda503fdecf25cb5285501425ac17 100644 (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: {
index eb4f5d4325cb8e562b6a14ec9def7dc5b15fd89d..5a05f9b2671be08c31a449facab8fc47642f06dc 100644 (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}
index 689a1ba3682e04f4a3c6611e62f242c07707d712..e28d4106d14327791afd7540be70ae851ee65b2a 100644 (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);
   });
 });
index a7663086ecc4ff36b52be1ab707ba7a4ffc20e34..f8e42dda9e46e94942d014a4600d2a69746ef88f 100644 (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, '');
 }