import { EditionKey } from '../../../types/editions';
import { GlobalFooter, GlobalFooterProps } from '../GlobalFooter';
-jest.mock('../../../helpers/system', () => ({ isSonarCloud: jest.fn() }));
-
it('should render the only logged in information', () => {
expect(getWrapper()).toMatchSnapshot();
});
import HomePageSelect from '../../../components/controls/HomePageSelect';
import PageShortcutsTooltip from '../../../components/ui/PageShortcutsTooltip';
import { translate } from '../../../helpers/l10n';
-import { isSonarCloud } from '../../../helpers/system';
import { Paging } from '../../../types/types';
import IssuesCounter from './IssuesCounter';
import TotalEffort from './TotalEffort';
</div>
{canSetHome && (
- <HomePageSelect
- className="huge-spacer-left"
- currentPage={isSonarCloud() ? { type: 'MY_ISSUES' } : { type: 'ISSUES' }}
- />
+ <HomePageSelect className="huge-spacer-left" currentPage={{ type: 'ISSUES' }} />
)}
</div>
);
import DateFromNow from '../../../components/intl/DateFromNow';
import TimeFormatter from '../../../components/intl/TimeFormatter';
import { translate } from '../../../helpers/l10n';
-import { getBaseUrl, isSonarCloud } from '../../../helpers/system';
+import { getBaseUrl } from '../../../helpers/system';
import { getReturnUrl } from '../../../helpers/urls';
import '../styles.css';
<h1 className="maintenance-title text-danger">
<InstanceMessage message={translate('maintenance.is_offline')} />
</h1>
- {!isSonarCloud() && (
- <p className="maintenance-text">
- {translate('maintenance.sonarqube_is_offline.text')}
- </p>
- )}
+ <p className="maintenance-text">
+ {translate('maintenance.sonarqube_is_offline.text')}
+ </p>
<p className="maintenance-text text-center">
<a href={getBaseUrl() + '/'}>{translate('maintenance.try_again')}</a>
</p>
*/
import { shallow } from 'enzyme';
import * as React from 'react';
-import { isSonarCloud } from '../../../../helpers/system';
import { mockAppState } from '../../../../helpers/testMocks';
import BranchOverview from '../../branches/BranchOverview';
import { App } from '../App';
-jest.mock('../../../../helpers/system', () => ({ isSonarCloud: jest.fn() }));
-
const component = {
key: 'foo',
analysisDate: '2016-01-01',
version: '0.0.1'
};
-beforeEach(() => {
- (isSonarCloud as jest.Mock<any>).mockClear();
- (isSonarCloud as jest.Mock<any>).mockReturnValue(false);
-});
-
it('should render BranchOverview', () => {
expect(
getWrapper()
import * as React from 'react';
import HelpTooltip from '../../../components/controls/HelpTooltip';
import { translate } from '../../../helpers/l10n';
-import { isSonarCloud } from '../../../helpers/system';
interface Props {
permission: {
{translate('permission_templates.project_creators')}
<HelpTooltip
className="little-spacer-left"
- overlay={translate(
- isSonarCloud()
- ? 'permission_templates.project_creators.explanation.sonarcloud'
- : 'permission_templates.project_creators.explanation'
- )}
+ overlay={translate('permission_templates.project_creators.explanation')}
/>
</li>
)}
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { isSonarCloud } from '../../../helpers/system';
import { convertToPermissionDefinitions } from '../utils';
-jest.mock('../../../helpers/system', () => ({ isSonarCloud: jest.fn() }));
-
jest.mock('../../../helpers/l10nBundle', () => ({
getMessages: jest.fn().mockReturnValue({})
}));
describe('convertToPermissionDefinitions', () => {
it('should convert and translate a permission definition', () => {
- (isSonarCloud as jest.Mock).mockImplementation(() => false);
-
const data = convertToPermissionDefinitions(['admin'], 'global_permissions');
const expected = [
{
expect(data).toEqual(expected);
});
-
- it('should convert and translate a permission definition for SonarCloud', () => {
- (isSonarCloud as jest.Mock).mockImplementation(() => true);
-
- const data = convertToPermissionDefinitions(['admin'], 'global_permissions');
- const expected = [
- {
- description: 'global_permissions.admin.desc.sonarcloud',
- key: 'admin',
- name: 'global_permissions.admin.sonarcloud'
- }
- ];
-
- expect(data).toEqual(expected);
- });
-
- it('should fallback to basic message when SonarCloud version does not exist', () => {
- (isSonarCloud as jest.Mock).mockImplementation(() => true);
-
- const data = convertToPermissionDefinitions(['admin'], 'global_permissions');
- const expected = [
- {
- description: 'global_permissions.admin.desc.sonarcloud',
- key: 'admin',
- name: 'global_permissions.admin.sonarcloud'
- }
- ];
-
- expect(data).toEqual(expected);
- });
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { hasMessage, translate } from '../../helpers/l10n';
-import { isSonarCloud } from '../../helpers/system';
+import { translate } from '../../helpers/l10n';
import { Dict, PermissionDefinition, PermissionDefinitionGroup } from '../../types/types';
export const PERMISSIONS_ORDER_FOR_PROJECT_TEMPLATE = [
};
function convertToPermissionDefinition(permission: string, l10nPrefix: string) {
- const getMessage = (messageKey: string) => {
- const cloudMessageKey = `${messageKey}.sonarcloud`;
- return isSonarCloud() && hasMessage(cloudMessageKey)
- ? translate(cloudMessageKey)
- : translate(messageKey);
- };
-
- const name = getMessage(`${l10nPrefix}.${permission}`);
- const description = getMessage(`${l10nPrefix}.${permission}.desc`);
+ const name = translate(`${l10nPrefix}.${permission}`);
+ const description = translate(`${l10nPrefix}.${permission}.desc`);
return {
key: permission,
import Header, { Props } from '../Header';
jest.mock('../../../helpers/system', () => ({
- getReactDomContainerSelector: jest.fn(() => '#content'),
- isSonarCloud: jest.fn().mockReturnValue(false)
+ getReactDomContainerSelector: jest.fn(() => '#content')
}));
it('renders', () => {
import { Link } from 'react-router';
import withAppStateContext from '../../app/components/app-state/withAppStateContext';
import DetachIcon from '../../components/icons/DetachIcon';
-import { isSonarCloud } from '../../helpers/system';
import { AppState } from '../../types/appstate';
interface OwnProps {
type Props = OwnProps & React.AnchorHTMLAttributes<HTMLAnchorElement>;
-const SONARCLOUD_LINK = '/#sonarcloud#/';
const SONARQUBE_LINK = '/#sonarqube#/';
const SONARQUBE_ADMIN_LINK = '/#sonarqube-admin#/';
}
if (href && href.startsWith('/')) {
- if (href.startsWith(SONARCLOUD_LINK)) {
- return <SonarCloudLink url={href}>{children}</SonarCloudLink>;
- } else if (href.startsWith(SONARQUBE_LINK)) {
+ if (href.startsWith(SONARQUBE_LINK)) {
return <SonarQubeLink url={href}>{children}</SonarQubeLink>;
} else if (href.startsWith(SONARQUBE_ADMIN_LINK)) {
return (
export default withAppStateContext(DocLink);
-interface SonarCloudLinkProps {
- children: React.ReactNode;
- url: string;
-}
-
-function SonarCloudLink({ children, url }: SonarCloudLinkProps) {
- if (!isSonarCloud()) {
- return <>{children}</>;
- }
- const to = `/${url.substr(SONARCLOUD_LINK.length)}`;
- return <Link to={to}>{children}</Link>;
-}
-
interface SonarQubeLinkProps {
children: React.ReactNode;
url: string;
}
function SonarQubeLink({ children, url }: SonarQubeLinkProps) {
- if (isSonarCloud()) {
- return <>{children}</>;
- }
const to = `/${url.substr(SONARQUBE_LINK.length)}`;
return (
<Link target="_blank" to={to}>
}
function SonarQubeAdminLink({ canAdmin, children, url }: SonarQubeAdminLinkProps) {
- if (isSonarCloud() || !canAdmin) {
+ if (!canAdmin) {
return <>{children}</>;
}
const to = `/${url.substr(SONARQUBE_ADMIN_LINK.length)}`;
type Props = OwnProps & React.AnchorHTMLAttributes<HTMLAnchorElement>;
-const SONARCLOUD_LINK = '/#sonarcloud#/';
-
export default function DocTooltipLink({ children, customProps, href, ...other }: Props) {
if (customProps) {
forEach(customProps, (value, key) => {
}
if (href && href.startsWith('/')) {
- if (href.startsWith(SONARCLOUD_LINK)) {
- href = `/${href.substr(SONARCLOUD_LINK.length)}`;
- } else {
- href = `/documentation/${href.substr(1)}`;
- }
+ href = `/documentation/${href.substr(1)}`;
return (
<Link rel="noopener noreferrer" target="_blank" to={href} {...other}>
*/
import { shallow } from 'enzyme';
import * as React from 'react';
-import { isSonarCloud } from '../../../helpers/system';
import { mockAppState } from '../../../helpers/testMocks';
import { DocLink } from '../DocLink';
-jest.mock('../../../helpers/system', () => ({
- isSonarCloud: jest.fn(() => false)
-}));
-
it('should render simple link', () => {
expect(
shallow(
).toMatchSnapshot();
});
-it('should render sonarcloud link on sonarcloud', () => {
- (isSonarCloud as jest.Mock).mockImplementationOnce(() => true);
- const wrapper = shallow(
- <DocLink appState={mockAppState({ canAdmin: false })} href="/#sonarcloud#/foo/bar">
- link text
- </DocLink>
- );
- expect(wrapper).toMatchSnapshot();
- expect(wrapper.find('SonarCloudLink').dive()).toMatchSnapshot();
-});
-
-it('should not render sonarcloud link on sonarcloud', () => {
- (isSonarCloud as jest.Mock).mockImplementationOnce(() => false);
- const wrapper = shallow(
- <DocLink appState={mockAppState({ canAdmin: false })} href="/#sonarcloud#/foo/bar">
- link text
- </DocLink>
- );
- expect(wrapper.find('SonarCloudLink').dive()).toMatchSnapshot();
-});
-
it('should render sonarqube link on sonarqube', () => {
const wrapper = shallow(
<DocLink appState={mockAppState({ canAdmin: false })} href="/#sonarqube#/foo/bar">
expect(wrapper.find('SonarQubeLink').dive()).toMatchSnapshot();
});
-it('should not render sonarqube link on sonarcloud', () => {
- (isSonarCloud as jest.Mock).mockImplementationOnce(() => true);
- const wrapper = shallow(
- <DocLink appState={mockAppState({ canAdmin: false })} href="/#sonarqube#/foo/bar">
- link text
- </DocLink>
- );
- expect(wrapper.find('SonarQubeLink').dive()).toMatchSnapshot();
-});
-
it('should render sonarqube admin link on sonarqube for admin', () => {
const wrapper = shallow(
<DocLink appState={mockAppState({ canAdmin: true })} href="/#sonarqube-admin#/foo/bar">
expect(wrapper.find('SonarQubeAdminLink').dive()).toMatchSnapshot();
});
-it('should not render sonarqube admin link on sonarcloud', () => {
- (isSonarCloud as jest.Mock).mockImplementationOnce(() => true);
- const wrapper = shallow(
- <DocLink appState={mockAppState({ canAdmin: true })} href="/#sonarqube-admin#/foo/bar">
- link text
- </DocLink>
- );
- expect(wrapper.find('SonarQubeAdminLink').dive()).toMatchSnapshot();
-});
-
it('should render documentation anchor', () => {
expect(
shallow(
it('should render links with custom props', () => {
expect(
- shallow(<DocTooltipLink customProps={{ bar: 'baz' }} href="/#sonarcloud#/foo/#bar#" />)
+ shallow(<DocTooltipLink customProps={{ bar: 'baz' }} href="/foo/#bar#" />)
).toMatchSnapshot();
});
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`should not render sonarcloud link on sonarcloud 1`] = `
-<Fragment>
- link text
-</Fragment>
-`;
-
-exports[`should not render sonarqube admin link on sonarcloud 1`] = `
-<Fragment>
- link text
-</Fragment>
-`;
-
exports[`should not render sonarqube admin link on sonarqube for non-admin 1`] = `
<Fragment>
link text
</Fragment>
`;
-exports[`should not render sonarqube link on sonarcloud 1`] = `
-<Fragment>
- link text
-</Fragment>
-`;
-
exports[`should render documentation anchor 1`] = `
<a
href="#"
</Fragment>
`;
-exports[`should render sonarcloud link on sonarcloud 1`] = `
-<SonarCloudLink
- url="/#sonarcloud#/foo/bar"
->
- link text
-</SonarCloudLink>
-`;
-
-exports[`should render sonarcloud link on sonarcloud 2`] = `
-<Link
- onlyActiveOnIndex={false}
- style={Object {}}
- to="/foo/bar"
->
- link text
-</Link>
-`;
-
exports[`should render sonarqube admin link on sonarqube for admin 1`] = `
<SonarQubeAdminLink
canAdmin={true}
rel="noopener noreferrer"
style={Object {}}
target="_blank"
- to="/foo/baz"
+ to="/documentation/foo/baz"
/>
`;
"
`;
-exports[`should cut sonarqube/sonarcloud/static content 2`] = `
-"
-This text has inline text for SonarCloud. Donec sed nulla magna.
-
-
-
-This is text for SonarCloud, multi-line. In hac habitasse platea dictumst. Duis sagittis semper sapien nec tempor. Nullam vehicula nisi vitae nisi interdum aliquam. Mauris volutpat nunc non fermentum rhoncus. Aenean laoreet, orci vitae tempor bibendum,
-metus nisl euismod neque, vitae euismod nibh nisl eu velit. Vivamus luctus suscipit elit vel semper.
-
-
-
-
-
-* In hac habitasse
-* Duis sagittis semper sapien nec tempor
-
-* This is a bullet point for SonarCloud
-* Platea dictumst
-
-Duis sagittis semper sapien nec tempor. Nullam vehicula nisi vitae nisi interdum aliquam.
-
-| Parameter Name | Description |
-| --------------------- | ------------------ |
-| sonar.pullrequest.github.repository | SLUG of the GitHub Repo |
-
-"
-`;
-
exports[`should not break when conditional tags are misused 1`] = `
"Random SC text
Break
*/
/* eslint-disable no-console */
import { filterContent, getFrontMatter, separateFrontMatter } from '../markdown';
-import { isSonarCloud } from '../system';
jest.mock('../system', () => ({
- getInstance: () => 'SonarQube',
- isSonarCloud: jest.fn().mockReturnValue(false)
+ getInstance: () => 'SonarQube'
}));
it('returns parsed frontmatter of one item', () => {
`;
expect(filterContent(content)).toMatchSnapshot();
-
- (isSonarCloud as jest.Mock).mockReturnValueOnce(true);
- expect(filterContent(content)).toMatchSnapshot();
});
it('should not break when conditional tags are misused', () => {
const frontmatter = parseFrontMatter(lines.slice(position.firstLine + 1, position.lastLine));
const content = lines.slice(position.lastLine + 1).join('\n');
return { frontmatter, content };
- } else {
- return { frontmatter: {}, content };
}
+ return { frontmatter: {}, content };
}
function getFrontMatterPosition(lines) {
function parseFrontMatter(lines) {
const data = {};
- for (let i = 0; i < lines.length; i++) {
- const tokens = lines[i].split(':').map(x => x.trim());
+ for (const element of lines) {
+ const tokens = element.split(':').map(x => x.trim());
if (tokens.length === 2) {
data[tokens[0]] = tokens[1];
}
*/
function filterContent(content) {
const regexBase = '<!-- \\/?(sonarqube|sonarcloud|static) -->';
- const { isSonarCloud, getInstance } = require('./system');
+ const { getInstance } = require('./system');
const contentWithInstance = content.replace(/{instance}/gi, getInstance());
const contentWithoutStatic = cutConditionalContent(contentWithInstance, 'static');
- const filteredContent = isSonarCloud()
- ? cutConditionalContent(contentWithoutStatic, 'sonarqube')
- : cutConditionalContent(contentWithoutStatic, 'sonarcloud');
+ const filteredContent = cutConditionalContent(contentWithoutStatic, 'sonarcloud');
return filteredContent
.replace(new RegExp(`^${regexBase}(\n|\r|\r\n|$)`, 'gm'), '') // First, remove single-line ones, including ending carriage-returns.
.replace(new RegExp(`${regexBase}`, 'g'), ''); // Now remove all remaining ones.
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { InstanceType } from '../types/system';
import { getEnhancedWindow } from './browser';
export function getBaseUrl() {
return getEnhancedWindow().official;
}
-export function isSonarCloud() {
- return getInstance() === InstanceType.SonarCloud;
-}
-
export function getReactDomContainerSelector() {
return '#content';
}