From: Stas Vilchik Date: Fri, 3 Aug 2018 11:08:37 +0000 (+0200) Subject: SONAR-11100 fix documentation scope on sonarcloud (#584) X-Git-Tag: 7.5~656 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=75aa5f3882c913fe5e145640ebe9b2b18d2b7895;p=sonarqube.git SONAR-11100 fix documentation scope on sonarcloud (#584) --- 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) {