3 * Copyright (C) 2009-2021 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 import { Location } from '../../../../../../../helpers/urls';
21 import { BadgeOptions, BadgeType, getBadgeSnippet, getBadgeUrl } from '../utils';
23 jest.mock('../../../../../../../helpers/urls', () => ({
24 ...jest.requireActual('../../../../../../../helpers/urls'),
25 getHostUrl: () => 'host',
26 getPathUrlAsString: (o: Location) =>
27 `host${o.pathname}?id=${o.query ? o.query.id : ''}&branch=${o.query ? o.query.branch : ''}`
30 const options: BadgeOptions = {
33 metric: 'alert_status',
37 describe('#getBadgeUrl', () => {
38 it('should generate correct marketing badge links', () => {
39 expect(getBadgeUrl(BadgeType.marketing, options)).toBe(
40 'host/images/project_badges/sonarcloud-white.svg'
42 expect(getBadgeUrl(BadgeType.marketing, { ...options, color: 'orange' })).toBe(
43 'host/images/project_badges/sonarcloud-orange.svg'
47 it('should generate correct quality gate badge links', () => {
48 expect(getBadgeUrl(BadgeType.qualityGate, options)).toBe(
49 'host/api/project_badges/quality_gate?branch=master&project=foo'
53 it('should generate correct measures badge links', () => {
54 expect(getBadgeUrl(BadgeType.measure, options)).toBe(
55 'host/api/project_badges/measure?branch=master&project=foo&metric=alert_status'
59 it('should ignore undefined parameters', () => {
60 expect(getBadgeUrl(BadgeType.measure, { color: 'white', metric: 'alert_status' })).toBe(
61 'host/api/project_badges/measure?metric=alert_status'
66 describe('#getBadgeSnippet', () => {
67 it('should generate a correct markdown image', () => {
68 expect(getBadgeSnippet(BadgeType.marketing, { ...options, format: 'md' })).toBe(
69 '[![SonarCloud](host/images/project_badges/sonarcloud-white.svg)](host/dashboard?id=foo&branch=master)'