]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11100 fix documentation scope on sonarcloud (#584)
authorStas Vilchik <stas.vilchik@sonarsource.com>
Fri, 3 Aug 2018 11:08:37 +0000 (13:08 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 3 Aug 2018 18:21:25 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/documentation/components/__tests__/pages-test.ts [new file with mode: 0644]
server/sonar-web/src/main/js/apps/documentation/pages.ts

diff --git a/server/sonar-web/src/main/js/apps/documentation/components/__tests__/pages-test.ts b/server/sonar-web/src/main/js/apps/documentation/components/__tests__/pages-test.ts
new file mode 100644 (file)
index 0000000..45761c8
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import getPages from '../../pages';
+import { isSonarCloud } from '../../../../helpers/system';
+
+// mock `remark` and `remark-react` to work around the issue with cjs imports
+jest.mock('remark', () => {
+  const remark = require.requireActual('remark');
+  return { default: remark };
+});
+
+jest.mock('unist-util-visit', () => {
+  const exp = require.requireActual('unist-util-visit');
+  return { default: exp };
+});
+
+jest.mock('../../documentation.directory-loader', () => [
+  {
+    path: 'all',
+    content: `
+    ---
+    title: All
+    ---
+
+    all all all`
+  },
+  {
+    path: 'sonarqube-foo',
+    content: `
+    ---
+    title: Foo
+    scope: sonarqube
+    ---
+
+    foo foo foo`
+  },
+  {
+    path: 'sonarcloud-bar',
+    content: `
+    ---
+    title: Bar
+    scope: sonarcloud
+    ---
+
+    bar bar bar`
+  },
+  {
+    path: 'static-baz',
+    content: `
+    ---
+    title: Baz
+    scope: static
+    ---
+
+    baz baz baz`
+  }
+]);
+
+jest.mock('../../../../helpers/system', () => ({ isSonarCloud: jest.fn() }));
+
+it('should filter pages for SonarQube', () => {
+  (isSonarCloud as jest.Mock).mockReturnValue(false);
+  expect(getPages().map(page => page.title)).toEqual(['All', 'Foo']);
+});
+
+it('should filter pages for SonarCloud', () => {
+  (isSonarCloud as jest.Mock).mockReturnValue(true);
+  expect(getPages().map(page => page.title)).toEqual(['All', 'Bar']);
+});
index 246ea1c3b42107ac2c00759f4d446ef50d39d788..e377c21151cde056a76d2f9f266fdea1ec79b8d5 100644 (file)
@@ -40,10 +40,12 @@ export default function getPages(): DocumentationEntry[] {
       text,
       content: file.content
     };
-  }).filter(
-    (page: DocumentationEntry) =>
-      page.scope !== 'static' && (isSonarCloud() || page.scope !== 'sonarcloud')
-  );
+  }).filter((page: DocumentationEntry) => {
+    if (!page.scope) {
+      return true;
+    }
+    return isSonarCloud() ? page.scope === 'sonarcloud' : page.scope === 'sonarqube';
+  });
 }
 
 function getText(content: string) {