aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/documentation
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-08-03 13:08:37 +0200
committerSonarTech <sonartech@sonarsource.com>2018-08-03 20:21:25 +0200
commit75aa5f3882c913fe5e145640ebe9b2b18d2b7895 (patch)
tree7d0629e69919bdb842d674317111883c1bf7ced4 /server/sonar-web/src/main/js/apps/documentation
parent86937350807da2beb38dcd4216eafea0009fb99f (diff)
downloadsonarqube-75aa5f3882c913fe5e145640ebe9b2b18d2b7895.tar.gz
sonarqube-75aa5f3882c913fe5e145640ebe9b2b18d2b7895.zip
SONAR-11100 fix documentation scope on sonarcloud (#584)
Diffstat (limited to 'server/sonar-web/src/main/js/apps/documentation')
-rw-r--r--server/sonar-web/src/main/js/apps/documentation/components/__tests__/pages-test.ts86
-rw-r--r--server/sonar-web/src/main/js/apps/documentation/pages.ts10
2 files changed, 92 insertions, 4 deletions
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
index 00000000000..45761c89a3a
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/documentation/components/__tests__/pages-test.ts
@@ -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']);
+});
diff --git a/server/sonar-web/src/main/js/apps/documentation/pages.ts b/server/sonar-web/src/main/js/apps/documentation/pages.ts
index 246ea1c3b42..e377c21151c 100644
--- a/server/sonar-web/src/main/js/apps/documentation/pages.ts
+++ b/server/sonar-web/src/main/js/apps/documentation/pages.ts
@@ -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) {