Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

BranchQualityGate-it.tsx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  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.
  10. *
  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.
  15. *
  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.
  19. */
  20. import * as React from 'react';
  21. import { mockPullRequest } from '../../../../helpers/mocks/branch-like';
  22. import { mockComponent } from '../../../../helpers/mocks/component';
  23. import { mockQualityGateStatusConditionEnhanced } from '../../../../helpers/mocks/quality-gates';
  24. import { mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks';
  25. import { renderComponent } from '../../../../helpers/testReactTestingUtils';
  26. import { byLabelText, byRole } from '../../../../helpers/testSelector';
  27. import { MetricKey, MetricType } from '../../../../types/metrics';
  28. import { FCProps } from '../../../../types/misc';
  29. import { Status } from '../../utils';
  30. import BranchQualityGate from '../BranchQualityGate';
  31. it('renders failed QG', () => {
  32. renderBranchQualityGate();
  33. // Maintainability rating condition
  34. const maintainabilityRatingLink = byRole('link', {
  35. name: 'overview.failed_condition.x_rating_requiredmetric_domain.Maintainability metric.type.ratingE A',
  36. }).get();
  37. expect(maintainabilityRatingLink).toBeInTheDocument();
  38. expect(maintainabilityRatingLink).toHaveAttribute(
  39. 'href',
  40. '/project/issues?issueStatuses=OPEN%2CCONFIRMED&types=CODE_SMELL&pullRequest=1001&sinceLeakPeriod=true&id=my-project',
  41. );
  42. // Security Hotspots rating condition
  43. const securityHotspotsRatingLink = byRole('link', {
  44. name: 'overview.failed_condition.x_rating_requiredmetric_domain.Security Review metric.type.ratingE A',
  45. }).get();
  46. expect(securityHotspotsRatingLink).toBeInTheDocument();
  47. expect(securityHotspotsRatingLink).toHaveAttribute(
  48. 'href',
  49. '/security_hotspots?id=my-project&pullRequest=1001',
  50. );
  51. // New code smells
  52. const codeSmellsLink = byRole('link', {
  53. name: 'overview.failed_condition.x_required 5 Code Smells ≤ 1',
  54. }).get();
  55. expect(codeSmellsLink).toBeInTheDocument();
  56. expect(codeSmellsLink).toHaveAttribute(
  57. 'href',
  58. '/project/issues?issueStatuses=OPEN%2CCONFIRMED&types=CODE_SMELL&pullRequest=1001&id=my-project',
  59. );
  60. // Conditions to cover
  61. const conditionToCoverLink = byRole('link', {
  62. name: 'overview.failed_condition.x_required 5 Conditions to cover ≥ 10',
  63. }).get();
  64. expect(conditionToCoverLink).toBeInTheDocument();
  65. expect(conditionToCoverLink).toHaveAttribute(
  66. 'href',
  67. '/component_measures?id=my-project&metric=conditions_to_cover&pullRequest=1001&view=list',
  68. );
  69. expect(byLabelText('overview.quality_gate_x.overview.gate.ERROR').get()).toBeInTheDocument();
  70. });
  71. it('renders passed QG', () => {
  72. renderBranchQualityGate({ failedConditions: [], status: Status.OK });
  73. expect(byLabelText('overview.quality_gate_x.overview.gate.OK').get()).toBeInTheDocument();
  74. expect(byRole('link').query()).not.toBeInTheDocument();
  75. });
  76. function renderBranchQualityGate(props: Partial<FCProps<typeof BranchQualityGate>> = {}) {
  77. return renderComponent(
  78. <BranchQualityGate
  79. status={Status.ERROR}
  80. branchLike={mockPullRequest()}
  81. component={mockComponent()}
  82. failedConditions={[
  83. mockQualityGateStatusConditionEnhanced({
  84. actual: '5.0',
  85. error: '1.0',
  86. metric: MetricKey.new_maintainability_rating,
  87. measure: mockMeasureEnhanced({
  88. metric: mockMetric({
  89. domain: 'Maintainability',
  90. key: MetricKey.new_maintainability_rating,
  91. name: 'Maintainability rating',
  92. type: MetricType.Rating,
  93. }),
  94. }),
  95. }),
  96. mockQualityGateStatusConditionEnhanced({
  97. actual: '5.0',
  98. error: '1.0',
  99. metric: MetricKey.new_security_review_rating,
  100. measure: mockMeasureEnhanced({
  101. metric: mockMetric({
  102. domain: 'Security Review',
  103. key: MetricKey.new_security_review_rating,
  104. name: 'Security Review Rating',
  105. type: MetricType.Rating,
  106. }),
  107. }),
  108. }),
  109. mockQualityGateStatusConditionEnhanced({
  110. actual: '5',
  111. error: '1',
  112. metric: MetricKey.new_code_smells,
  113. measure: mockMeasureEnhanced({
  114. metric: mockMetric({
  115. domain: 'Maintainability',
  116. key: MetricKey.new_code_smells,
  117. name: 'Code Smells',
  118. type: MetricType.ShortInteger,
  119. }),
  120. }),
  121. }),
  122. mockQualityGateStatusConditionEnhanced({
  123. actual: '5',
  124. error: '10',
  125. op: 'up',
  126. metric: MetricKey.conditions_to_cover,
  127. measure: mockMeasureEnhanced({
  128. metric: mockMetric({
  129. key: MetricKey.conditions_to_cover,
  130. name: 'Conditions to cover',
  131. type: MetricType.ShortInteger,
  132. }),
  133. }),
  134. }),
  135. ]}
  136. {...props}
  137. />,
  138. );
  139. }