From: Wouter Admiraal Date: Tue, 11 Oct 2022 10:23:02 +0000 (+0200) Subject: [NO JIRA] Cleanup project activity types, mocks, and components X-Git-Tag: 9.7.0.61563~23 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f0dc1938077a3bf4b4e8ba6baf9687404b6c8f5f;p=sonarqube.git [NO JIRA] Cleanup project activity types, mocks, and components --- diff --git a/server/sonar-web/src/main/js/api/projectActivity.ts b/server/sonar-web/src/main/js/api/projectActivity.ts index 9fde41ead19..06e8e582e43 100644 --- a/server/sonar-web/src/main/js/api/projectActivity.ts +++ b/server/sonar-web/src/main/js/api/projectActivity.ts @@ -20,7 +20,8 @@ import { throwGlobalError } from '../helpers/error'; import { getJSON, post, postJSON, RequestData } from '../helpers/request'; import { BranchParameters } from '../types/branch-like'; -import { Analysis, Paging } from '../types/types'; +import { Analysis } from '../types/project-activity'; +import { Paging } from '../types/types'; export enum ProjectActivityStatuses { STATUS_PROCESSED = 'P', diff --git a/server/sonar-web/src/main/js/apps/overview/branches/ActivityPanel.tsx b/server/sonar-web/src/main/js/apps/overview/branches/ActivityPanel.tsx index c894d53d819..8fb7721b7d6 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/ActivityPanel.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/ActivityPanel.tsx @@ -32,8 +32,12 @@ import { parseDate } from '../../../helpers/dates'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { localizeMetric } from '../../../helpers/measures'; import { BranchLike } from '../../../types/branch-like'; -import { GraphType, MeasureHistory } from '../../../types/project-activity'; -import { Analysis as AnalysisType, Component, Metric } from '../../../types/types'; +import { + Analysis as AnalysisType, + GraphType, + MeasureHistory +} from '../../../types/project-activity'; +import { Component, Metric } from '../../../types/types'; import Analysis from './Analysis'; export interface ActivityPanelProps { diff --git a/server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx b/server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx index 945256ccac5..6a8f47d9001 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx @@ -22,7 +22,7 @@ import * as React from 'react'; import DateTimeFormatter from '../../../components/intl/DateTimeFormatter'; import { translate } from '../../../helpers/l10n'; import { ComponentQualifier } from '../../../types/component'; -import { Analysis as TypeAnalysis } from '../../../types/types'; +import { Analysis as TypeAnalysis } from '../../../types/project-activity'; import Event from './Event'; export interface AnalysisProps { diff --git a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx index 706194c36ce..cafc0f47fc1 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx @@ -47,9 +47,9 @@ import { ApplicationPeriod } from '../../../types/application'; import { Branch, BranchLike } from '../../../types/branch-like'; import { ComponentQualifier } from '../../../types/component'; import { MetricKey } from '../../../types/metrics'; -import { GraphType, MeasureHistory } from '../../../types/project-activity'; +import { Analysis, GraphType, MeasureHistory } from '../../../types/project-activity'; import { QualityGateStatus, QualityGateStatusCondition } from '../../../types/quality-gates'; -import { Analysis, Component, MeasureEnhanced, Metric, Period } from '../../../types/types'; +import { Component, MeasureEnhanced, Metric, Period } from '../../../types/types'; import '../styles.css'; import { HISTORY_METRICS_LIST, METRICS } from '../utils'; import BranchOverviewRenderer from './BranchOverviewRenderer'; diff --git a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverviewRenderer.tsx b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverviewRenderer.tsx index c718f5b4658..969790a0bfb 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverviewRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverviewRenderer.tsx @@ -24,9 +24,9 @@ import { ProjectAlmBindingResponse } from '../../../types/alm-settings'; import { ApplicationPeriod } from '../../../types/application'; import { Branch } from '../../../types/branch-like'; import { ComponentQualifier } from '../../../types/component'; -import { GraphType, MeasureHistory } from '../../../types/project-activity'; +import { Analysis, GraphType, MeasureHistory } from '../../../types/project-activity'; import { QualityGateStatus } from '../../../types/quality-gates'; -import { Analysis, Component, MeasureEnhanced, Metric, Period } from '../../../types/types'; +import { Component, MeasureEnhanced, Metric, Period } from '../../../types/types'; import ActivityPanel from './ActivityPanel'; import FirstAnalysisNextStepsNotif from './FirstAnalysisNextStepsNotif'; import MeasuresPanel from './MeasuresPanel'; diff --git a/server/sonar-web/src/main/js/apps/overview/branches/Event.tsx b/server/sonar-web/src/main/js/apps/overview/branches/Event.tsx index 3b01c1f19dd..b10845593df 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/Event.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/Event.tsx @@ -19,11 +19,11 @@ */ import * as React from 'react'; import { FormattedMessage } from 'react-intl'; +import { isDefinitionChangeEvent } from '../../../components/activity-graph/DefinitionChangeEventInner'; +import { isRichQualityGateEvent } from '../../../components/activity-graph/RichQualityGateEventInner'; import Level from '../../../components/ui/Level'; import { translate } from '../../../helpers/l10n'; -import { AnalysisEvent } from '../../../types/types'; -import { isDefinitionChangeEvent } from '../../projectActivity/components/DefinitionChangeEventInner'; -import { isRichQualityGateEvent } from '../../projectActivity/components/RichQualityGateEventInner'; +import { AnalysisEvent } from '../../../types/project-activity'; interface Props { event: AnalysisEvent; diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/ActivityPanel-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/ActivityPanel-test.tsx index 65ebd44f574..93f43fa5705 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/ActivityPanel-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/ActivityPanel-test.tsx @@ -23,12 +23,8 @@ import GraphsHistory from '../../../../components/activity-graph/GraphsHistory'; import { parseDate } from '../../../../helpers/dates'; import { mockMainBranch } from '../../../../helpers/mocks/branch-like'; import { mockComponent } from '../../../../helpers/mocks/component'; -import { - mockAnalysis, - mockAnalysisEvent, - mockMeasure, - mockMetric -} from '../../../../helpers/testMocks'; +import { mockAnalysis, mockAnalysisEvent } from '../../../../helpers/mocks/project-activity'; +import { mockMeasure, mockMetric } from '../../../../helpers/testMocks'; import { GraphType } from '../../../../types/project-activity'; import { ActivityPanel, ActivityPanelProps } from '../ActivityPanel'; diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx index 75734f2c670..d5d1e9fd151 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx @@ -19,7 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockAnalysis } from '../../../../helpers/testMocks'; +import { mockAnalysis } from '../../../../helpers/mocks/project-activity'; import { ComponentQualifier } from '../../../../types/component'; import { Analysis, AnalysisProps } from '../Analysis'; diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx index 1ce696193a0..11d5e0b9054 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx @@ -31,7 +31,7 @@ import { getActivityGraph, saveActivityGraph } from '../../../../components/acti import { isDiffMetric } from '../../../../helpers/measures'; import { mockBranch, mockMainBranch } from '../../../../helpers/mocks/branch-like'; import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockAnalysis } from '../../../../helpers/testMocks'; +import { mockAnalysis } from '../../../../helpers/mocks/project-activity'; import { waitAndUpdate } from '../../../../helpers/testUtils'; import { ComponentQualifier } from '../../../../types/component'; import { MetricKey } from '../../../../types/metrics'; @@ -144,7 +144,7 @@ jest.mock('../../../../api/time-machine', () => { }); jest.mock('../../../../api/projectActivity', () => { - const { mockAnalysis } = jest.requireActual('../../../../helpers/testMocks'); + const { mockAnalysis } = jest.requireActual('../../../../helpers/mocks/project-activity'); return { getProjectActivity: jest.fn().mockResolvedValue({ analyses: [ diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Event-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Event-test.tsx index eeab19b971c..9426d128179 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Event-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Event-test.tsx @@ -19,7 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { AnalysisEvent } from '../../../../types/types'; +import { AnalysisEvent } from '../../../../types/project-activity'; import { Event } from '../Event'; it('should render an event correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/actions.ts b/server/sonar-web/src/main/js/apps/projectActivity/actions.ts index df14281e683..52b46181dfc 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/actions.ts +++ b/server/sonar-web/src/main/js/apps/projectActivity/actions.ts @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { AnalysisEvent } from '../../types/types'; +import { AnalysisEvent } from '../../types/project-activity'; import { State } from './components/ProjectActivityApp'; export function addCustomEvent(analysis: string, event: AnalysisEvent) { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/DefinitionChangeEventInner.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/DefinitionChangeEventInner.tsx deleted file mode 100644 index 41c393a3b3f..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/DefinitionChangeEventInner.tsx +++ /dev/null @@ -1,169 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 * as React from 'react'; -import { FormattedMessage } from 'react-intl'; -import Link from '../../../components/common/Link'; -import { ButtonLink } from '../../../components/controls/buttons'; -import BranchIcon from '../../../components/icons/BranchIcon'; -import DropdownIcon from '../../../components/icons/DropdownIcon'; -import { isMainBranch } from '../../../helpers/branch-like'; -import { translate } from '../../../helpers/l10n'; -import { limitComponentName } from '../../../helpers/path'; -import { getProjectUrl } from '../../../helpers/urls'; -import { BranchLike } from '../../../types/branch-like'; -import { AnalysisEvent } from '../../../types/types'; - -export type DefinitionChangeEvent = AnalysisEvent & - Required>; - -export function isDefinitionChangeEvent(event: AnalysisEvent): event is DefinitionChangeEvent { - return event.category === 'DEFINITION_CHANGE' && event.definitionChange !== undefined; -} - -interface Props { - branchLike: BranchLike | undefined; - event: DefinitionChangeEvent; - readonly?: boolean; -} - -interface State { - expanded: boolean; -} - -export class DefinitionChangeEventInner extends React.PureComponent { - state: State = { expanded: false }; - - stopPropagation = (event: React.MouseEvent) => { - event.stopPropagation(); - }; - - toggleProjectsList = () => { - this.setState(state => ({ expanded: !state.expanded })); - }; - - renderProjectLink = (project: { key: string; name: string }, branch: string | undefined) => ( - - {limitComponentName(project.name, 28)} - - ); - - renderBranch = (branch = translate('branches.main_branch')) => ( - - - {branch} - - ); - - renderProjectChange(project: { - changeType: string; - key: string; - name: string; - branch?: string; - newBranch?: string; - oldBranch?: string; - }) { - const mainBranch = !this.props.branchLike || isMainBranch(this.props.branchLike); - - if (project.changeType === 'ADDED') { - const message = mainBranch - ? 'event.definition_change.added' - : 'event.definition_change.branch_added'; - return ( -
- -
- ); - } else if (project.changeType === 'REMOVED') { - const message = mainBranch - ? 'event.definition_change.removed' - : 'event.definition_change.branch_removed'; - return ( -
- -
- ); - } else if (project.changeType === 'BRANCH_CHANGED') { - return ( - - ); - } - return null; - } - - render() { - const { event, readonly } = this.props; - const { expanded } = this.state; - return ( - <> - - {translate('event.category', event.category)} - {!readonly && ':'} - - - {!readonly && ( -
- - {expanded ? translate('hide') : translate('more')} - - -
- )} - - {expanded && ( -
    - {event.definitionChange.projects.map(project => ( -
  • - {this.renderProjectChange(project)} -
  • - ))} -
- )} - - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/Event.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/Event.tsx index 9e984bbc47d..0b9a7ec252f 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/Event.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/Event.tsx @@ -18,10 +18,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import EventInner from '../../../components/activity-graph/EventInner'; import { DeleteButton, EditButton } from '../../../components/controls/buttons'; import { translate } from '../../../helpers/l10n'; -import { AnalysisEvent } from '../../../types/types'; -import EventInner from './EventInner'; +import { AnalysisEvent } from '../../../types/project-activity'; import ChangeEventForm from './forms/ChangeEventForm'; import RemoveEventForm from './forms/RemoveEventForm'; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/EventInner.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/EventInner.tsx deleted file mode 100644 index 8b636c67b47..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/EventInner.tsx +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 * as React from 'react'; -import { ComponentContext } from '../../../app/components/componentContext/ComponentContext'; -import Tooltip from '../../../components/controls/Tooltip'; -import { translate } from '../../../helpers/l10n'; -import { AnalysisEvent } from '../../../types/types'; -import { DefinitionChangeEventInner, isDefinitionChangeEvent } from './DefinitionChangeEventInner'; -import { isRichQualityGateEvent, RichQualityGateEventInner } from './RichQualityGateEventInner'; - -export interface EventInnerProps { - event: AnalysisEvent; - readonly?: boolean; -} - -export default function EventInner({ event, readonly }: EventInnerProps) { - if (isRichQualityGateEvent(event)) { - return ; - } else if (isDefinitionChangeEvent(event)) { - return ( - - {({ branchLike }) => ( - - )} - - ); - } - - return ( - - - - {translate('event.category', event.category)}: - - {event.name} - - - ); -} diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/Events.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/Events.tsx index d201d7366fe..df33ccca603 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/Events.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/Events.tsx @@ -19,7 +19,7 @@ */ import { sortBy } from 'lodash'; import * as React from 'react'; -import { AnalysisEvent } from '../../../types/types'; +import { AnalysisEvent } from '../../../types/project-activity'; import Event from './Event'; export interface EventsProps { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAnalysesList.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAnalysesList.tsx index 3a6966eecc3..3e8b7b2ba4a 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAnalysesList.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAnalysesList.tsx @@ -26,7 +26,7 @@ import DateFormatter from '../../../components/intl/DateFormatter'; import { toShortNotSoISOString } from '../../../helpers/dates'; import { translate } from '../../../helpers/l10n'; import { ComponentQualifier } from '../../../types/component'; -import { ParsedAnalysis } from '../../../types/types'; +import { ParsedAnalysis } from '../../../types/project-activity'; import { activityQueryChanged, getAnalysesByVersionByDay, Query } from '../utils'; import ProjectActivityAnalysis from './ProjectActivityAnalysis'; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAnalysis.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAnalysis.tsx index 3988b78c7b6..a38c2459ba2 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAnalysis.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAnalysis.tsx @@ -30,7 +30,7 @@ import { PopupPlacement } from '../../../components/ui/popups'; import { parseDate } from '../../../helpers/dates'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { scrollToElement } from '../../../helpers/scrolling'; -import { ParsedAnalysis } from '../../../types/types'; +import { ParsedAnalysis } from '../../../types/project-activity'; import Events from './Events'; import AddEventForm from './forms/AddEventForm'; import RemoveAnalysisForm from './forms/RemoveAnalysisForm'; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx index 46099ce9b07..59bb31c2d52 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityApp.tsx @@ -42,8 +42,8 @@ import { parseDate } from '../../../helpers/dates'; import { serializeStringArray } from '../../../helpers/query'; import { BranchLike } from '../../../types/branch-like'; import { MetricKey } from '../../../types/metrics'; -import { GraphType, MeasureHistory } from '../../../types/project-activity'; -import { Component, Metric, Paging, ParsedAnalysis, RawQuery } from '../../../types/types'; +import { GraphType, MeasureHistory, ParsedAnalysis } from '../../../types/project-activity'; +import { Component, Metric, Paging, RawQuery } from '../../../types/types'; import * as actions from '../actions'; import { customMetricsChanged, diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppRenderer.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppRenderer.tsx index f7dc79249f3..9a7108ad441 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppRenderer.tsx @@ -23,8 +23,8 @@ import A11ySkipTarget from '../../../components/a11y/A11ySkipTarget'; import Suggestions from '../../../components/embed-docs-modal/Suggestions'; import { parseDate } from '../../../helpers/dates'; import { translate } from '../../../helpers/l10n'; -import { MeasureHistory } from '../../../types/project-activity'; -import { Component, Metric, ParsedAnalysis } from '../../../types/types'; +import { MeasureHistory, ParsedAnalysis } from '../../../types/project-activity'; +import { Component, Metric } from '../../../types/types'; import { Query } from '../utils'; import './projectActivity.css'; import ProjectActivityAnalysesList from './ProjectActivityAnalysesList'; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.tsx index b11760e1926..ed7fa1f675c 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityGraphs.tsx @@ -31,8 +31,14 @@ import { saveActivityGraph, splitSeriesInGraphs } from '../../../components/activity-graph/utils'; -import { GraphType, MeasureHistory, Point, Serie } from '../../../types/project-activity'; -import { Metric, ParsedAnalysis } from '../../../types/types'; +import { + GraphType, + MeasureHistory, + ParsedAnalysis, + Point, + Serie +} from '../../../types/project-activity'; +import { Metric } from '../../../types/types'; import { datesQueryChanged, historyQueryChanged, Query } from '../utils'; import { PROJECT_ACTIVITY_GRAPH } from './ProjectActivityApp'; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/RichQualityGateEventInner.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/RichQualityGateEventInner.tsx deleted file mode 100644 index 37c6333c3a7..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/RichQualityGateEventInner.tsx +++ /dev/null @@ -1,111 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 * as React from 'react'; -import { FormattedMessage } from 'react-intl'; -import Link from '../../../components/common/Link'; -import { ResetButtonLink } from '../../../components/controls/buttons'; -import DropdownIcon from '../../../components/icons/DropdownIcon'; -import Level from '../../../components/ui/Level'; -import { translate, translateWithParameters } from '../../../helpers/l10n'; -import { getProjectUrl } from '../../../helpers/urls'; -import { AnalysisEvent } from '../../../types/types'; - -export type RichQualityGateEvent = AnalysisEvent & Required>; - -export function isRichQualityGateEvent(event: AnalysisEvent): event is RichQualityGateEvent { - return event.category === 'QUALITY_GATE' && event.qualityGate !== undefined; -} - -interface Props { - event: RichQualityGateEvent; - readonly?: boolean; -} - -interface State { - expanded: boolean; -} - -export class RichQualityGateEventInner extends React.PureComponent { - state: State = { expanded: false }; - - stopPropagation = (event: React.MouseEvent) => { - event.stopPropagation(); - }; - - toggleProjectsList = () => { - this.setState(state => ({ expanded: !state.expanded })); - }; - - render() { - const { event, readonly } = this.props; - const { expanded } = this.state; - return ( - <> - {translate('event.category', event.category)}: - {event.qualityGate.stillFailing ? ( - }} - /> - ) : ( - - )} - -
- {!readonly && event.qualityGate.failing.length > 0 && ( - - {expanded ? translate('hide') : translate('more')} - - - )} -
- - {expanded && ( -
    - {event.qualityGate.failing.map(project => ( -
  • - -
    - - - {project.name} - - -
    -
  • - ))} -
- )} - - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/DefinitionChangeEventInner-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/DefinitionChangeEventInner-test.tsx deleted file mode 100644 index 527588b20a7..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/DefinitionChangeEventInner-test.tsx +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockBranch } from '../../../../helpers/mocks/branch-like'; -import { click } from '../../../../helpers/testUtils'; -import { DefinitionChangeEvent, DefinitionChangeEventInner } from '../DefinitionChangeEventInner'; - -it('should render', () => { - const event: DefinitionChangeEvent = { - category: 'DEFINITION_CHANGE', - key: 'foo1234', - name: '', - definitionChange: { - projects: [ - { changeType: 'ADDED', key: 'foo', name: 'Foo', branch: 'master' }, - { changeType: 'REMOVED', key: 'bar', name: 'Bar', branch: 'master' } - ] - } - }; - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - - click(wrapper.find('.project-activity-event-inner-more-link')); - wrapper.update(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should render for a branch', () => { - const branch = mockBranch({ name: 'feature-x' }); - const event: DefinitionChangeEvent = { - category: 'DEFINITION_CHANGE', - key: 'foo1234', - name: '', - definitionChange: { - projects: [ - { changeType: 'ADDED', key: 'foo', name: 'Foo', branch: 'feature-x' }, - { - changeType: 'BRANCH_CHANGED', - key: 'bar', - name: 'Bar', - oldBranch: 'master', - newBranch: 'feature-y' - } - ] - } - }; - const wrapper = shallow(); - click(wrapper.find('.project-activity-event-inner-more-link')); - wrapper.update(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should render when readonly', () => { - const event: DefinitionChangeEvent = { - category: 'DEFINITION_CHANGE', - key: 'foo1234', - name: '', - definitionChange: { - projects: [ - { changeType: 'ADDED', key: 'foo', name: 'Foo', branch: 'master' }, - { changeType: 'REMOVED', key: 'bar', name: 'Bar', branch: 'master' } - ] - } - }; - const wrapper = shallow( - - ); - expect(wrapper).toMatchSnapshot(); - expect(wrapper.find('.project-activity-event-inner-more-link').exists()).toBe(false); -}); diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/Event-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/Event-test.tsx index 88d65875d7e..b70d0efbd6b 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/Event-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/Event-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { DeleteButton, EditButton } from '../../../../components/controls/buttons'; -import { mockAnalysisEvent } from '../../../../helpers/testMocks'; +import { mockAnalysisEvent } from '../../../../helpers/mocks/project-activity'; import { click } from '../../../../helpers/testUtils'; import { Event, EventProps } from '../Event'; import ChangeEventForm from '../forms/ChangeEventForm'; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/EventInner-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/EventInner-test.tsx deleted file mode 100644 index e83d18c993f..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/EventInner-test.tsx +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockAnalysisEvent } from '../../../../helpers/testMocks'; -import { BranchLike } from '../../../../types/branch-like'; -import EventInner, { EventInnerProps } from '../EventInner'; - -jest.mock('../../../../app/components/componentContext/ComponentContext', () => { - const { mockBranch } = jest.requireActual('../../../../helpers/mocks/branch-like'); - return { - ComponentContext: { - Consumer: ({ - children - }: { - children: (props: { branchLike: BranchLike }) => React.ReactNode; - }) => { - return children({ branchLike: mockBranch() }); - } - } - }; -}); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('default'); - expect( - shallowRender({ - event: mockAnalysisEvent({ - category: 'VERSION', - description: undefined, - qualityGate: undefined - }) - }) - ).toMatchSnapshot('no description'); - expect(shallowRender({ event: mockAnalysisEvent() })).toMatchSnapshot('rich quality gate'); - expect( - shallowRender({ - event: mockAnalysisEvent({ - category: 'DEFINITION_CHANGE', - definitionChange: { - projects: [{ changeType: 'ADDED', key: 'foo', name: 'Foo' }] - }, - qualityGate: undefined - }) - }) - .find('Consumer') - .dive() - ).toMatchSnapshot('definition change'); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/Events-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/Events-test.tsx index cc8fda1845a..a581ab44e67 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/Events-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/Events-test.tsx @@ -19,7 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockAnalysisEvent } from '../../../../helpers/testMocks'; +import { mockAnalysisEvent } from '../../../../helpers/mocks/project-activity'; import { Events, EventsProps } from '../Events'; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysesList-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysesList-test.tsx index 85b756aad12..c0ca44e0f9a 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysesList-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysesList-test.tsx @@ -21,7 +21,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { DEFAULT_GRAPH } from '../../../../components/activity-graph/utils'; import { parseDate } from '../../../../helpers/dates'; -import { mockParsedAnalysis } from '../../../../helpers/testMocks'; +import { mockParsedAnalysis } from '../../../../helpers/mocks/project-activity'; import { ComponentQualifier } from '../../../../types/component'; import ProjectActivityAnalysesList from '../ProjectActivityAnalysesList'; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx index 46d7b55ce75..7abfc29b774 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx @@ -21,8 +21,8 @@ import { mount, shallow } from 'enzyme'; import * as React from 'react'; import { IntlProvider } from 'react-intl'; import TimeFormatter from '../../../../components/intl/TimeFormatter'; +import { mockAnalysisEvent, mockParsedAnalysis } from '../../../../helpers/mocks/project-activity'; import { scrollToElement } from '../../../../helpers/scrolling'; -import { mockAnalysisEvent, mockParsedAnalysis } from '../../../../helpers/testMocks'; import { click } from '../../../../helpers/testUtils'; import AddEventForm from '../forms/AddEventForm'; import RemoveAnalysisForm from '../forms/RemoveAnalysisForm'; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-it.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-it.tsx index 06feb27b153..377f26c8032 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-it.tsx @@ -50,7 +50,8 @@ jest.mock('../../../../api/metrics', () => { }); jest.mock('../../../../api/projectActivity', () => { - const { mockAnalysis, mockPaging } = jest.requireActual('../../../../helpers/testMocks'); + const { mockPaging } = jest.requireActual('../../../../helpers/testMocks'); + const { mockAnalysis } = jest.requireActual('../../../../helpers/mocks/project-activity'); return { ...jest.requireActual('../../../../api/projectActivity'), createEvent: jest.fn(), diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-test.tsx index 851afd4f53e..6d5034e75fa 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityApp-test.tsx @@ -21,12 +21,8 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { changeEvent, createEvent } from '../../../../api/projectActivity'; import { mockComponent } from '../../../../helpers/mocks/component'; -import { - mockAnalysisEvent, - mockLocation, - mockMetric, - mockRouter -} from '../../../../helpers/testMocks'; +import { mockAnalysisEvent } from '../../../../helpers/mocks/project-activity'; +import { mockLocation, mockMetric, mockRouter } from '../../../../helpers/testMocks'; import { waitAndUpdate } from '../../../../helpers/testUtils'; import { ComponentQualifier } from '../../../../types/component'; import { MetricKey } from '../../../../types/metrics'; @@ -59,7 +55,8 @@ jest.mock('../../../../api/metrics', () => { }); jest.mock('../../../../api/projectActivity', () => { - const { mockAnalysis, mockPaging } = jest.requireActual('../../../../helpers/testMocks'); + const { mockPaging } = jest.requireActual('../../../../helpers/testMocks'); + const { mockAnalysis } = jest.requireActual('../../../../helpers/mocks/project-activity'); return { ...jest.requireActual('../../../../api/projectActivity'), createEvent: jest.fn(), diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/RichQualityGateEventInner-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/RichQualityGateEventInner-test.tsx deleted file mode 100644 index 5add1f46689..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/RichQualityGateEventInner-test.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { click } from '../../../../helpers/testUtils'; -import { RichQualityGateEvent, RichQualityGateEventInner } from '../RichQualityGateEventInner'; - -const event: RichQualityGateEvent = { - category: 'QUALITY_GATE', - key: 'foo1234', - name: '', - qualityGate: { - failing: [ - { branch: 'master', key: 'foo', name: 'Foo' }, - { branch: 'master', key: 'bar', name: 'Bar' } - ], - status: 'ERROR', - stillFailing: true - } -}; - -it('should render', () => { - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - - click(wrapper.find('.project-activity-event-inner-more-link')); - wrapper.update(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should not expand', () => { - const wrapper = shallow( - - ); - expect(wrapper.find('.project-activity-event-inner-more-link').exists()).toBe(false); -}); - -it('should not expand when readonly', () => { - const wrapper = shallow(); - expect(wrapper.find('.project-activity-event-inner-more-link').exists()).toBe(false); -}); diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/DefinitionChangeEventInner-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/DefinitionChangeEventInner-test.tsx.snap deleted file mode 100644 index ce770c6fcd3..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/DefinitionChangeEventInner-test.tsx.snap +++ /dev/null @@ -1,248 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render 1`] = ` - - - event.category.DEFINITION_CHANGE - : - -
- - more - - -
-
-`; - -exports[`should render 2`] = ` - - - event.category.DEFINITION_CHANGE - : - -
- - hide - - -
-
    -
  • -
    - - - master - , - "project": - Foo - , - } - } - /> -
    -
  • -
  • -
    - - - master - , - "project": - Bar - , - } - } - /> -
    -
  • -
-
-`; - -exports[`should render for a branch 1`] = ` - - - event.category.DEFINITION_CHANGE - : - -
- - hide - - -
-
    -
  • -
    - - - feature-x - , - "project": - Foo - , - } - } - /> -
    -
  • -
  • - - - feature-y - , - "oldBranch": - - master - , - "project": - Bar - , - } - } - /> -
  • -
-
-`; - -exports[`should render when readonly 1`] = ` - - - event.category.DEFINITION_CHANGE - - -`; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/EventInner-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/EventInner-test.tsx.snap deleted file mode 100644 index 639a2bb4f5d..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/EventInner-test.tsx.snap +++ /dev/null @@ -1,105 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: default 1`] = ` - - - - event.category.VERSION - : - - - Lorem ipsum - - - -`; - -exports[`should render correctly: definition change 1`] = ` - -`; - -exports[`should render correctly: no description 1`] = ` - - - - event.category.VERSION - : - - - Lorem ipsum - - - -`; - -exports[`should render correctly: rich quality gate 1`] = ` - -`; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/RichQualityGateEventInner-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/RichQualityGateEventInner-test.tsx.snap deleted file mode 100644 index cd9373673f2..00000000000 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/RichQualityGateEventInner-test.tsx.snap +++ /dev/null @@ -1,139 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render 1`] = ` - - - event.category.QUALITY_GATE - : - - , - } - } - /> -
- - more - - -
-
-`; - -exports[`should render 2`] = ` - - - event.category.QUALITY_GATE - : - - , - } - } - /> -
- - hide - - -
-
    -
  • - -
    - - - Foo - - -
    -
  • -
  • - -
    - - - Bar - - -
    -
  • -
-
-`; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddEventForm.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddEventForm.tsx index 24299b9be1c..e6e655466bc 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddEventForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/AddEventForm.tsx @@ -20,7 +20,7 @@ import * as React from 'react'; import ConfirmModal from '../../../../components/controls/ConfirmModal'; import { translate } from '../../../../helpers/l10n'; -import { ParsedAnalysis } from '../../../../types/types'; +import { ParsedAnalysis } from '../../../../types/project-activity'; interface Props { addEvent: (analysis: string, name: string, category?: string) => Promise; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/ChangeEventForm.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/ChangeEventForm.tsx index 189da0bf9c1..177e1878486 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/ChangeEventForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/ChangeEventForm.tsx @@ -20,7 +20,7 @@ import * as React from 'react'; import ConfirmModal from '../../../../components/controls/ConfirmModal'; import { translate } from '../../../../helpers/l10n'; -import { AnalysisEvent } from '../../../../types/types'; +import { AnalysisEvent } from '../../../../types/project-activity'; interface Props { changeEvent: (event: string, name: string) => Promise; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/RemoveAnalysisForm.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/RemoveAnalysisForm.tsx index 8eab959af3f..f8548fd77c8 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/RemoveAnalysisForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/RemoveAnalysisForm.tsx @@ -20,7 +20,7 @@ import * as React from 'react'; import ConfirmModal from '../../../../components/controls/ConfirmModal'; import { translate } from '../../../../helpers/l10n'; -import { ParsedAnalysis } from '../../../../types/types'; +import { ParsedAnalysis } from '../../../../types/project-activity'; interface Props { analysis: ParsedAnalysis; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/RemoveEventForm.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/RemoveEventForm.tsx index 9f7af825d2d..947b2ba65cd 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/RemoveEventForm.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/RemoveEventForm.tsx @@ -20,7 +20,7 @@ import * as React from 'react'; import ConfirmModal from '../../../../components/controls/ConfirmModal'; import { translate } from '../../../../helpers/l10n'; -import { AnalysisEvent } from '../../../../types/types'; +import { AnalysisEvent } from '../../../../types/project-activity'; export interface RemoveEventFormProps { analysisKey: string; diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/__tests__/RemoveEventForm-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/__tests__/RemoveEventForm-test.tsx index 99d8d97e8da..f0133209832 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/__tests__/RemoveEventForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/__tests__/RemoveEventForm-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import ConfirmModal from '../../../../../components/controls/ConfirmModal'; -import { mockAnalysisEvent } from '../../../../../helpers/testMocks'; +import { mockAnalysisEvent } from '../../../../../helpers/mocks/project-activity'; import RemoveEventForm, { RemoveEventFormProps } from '../RemoveEventForm'; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/utils.ts b/server/sonar-web/src/main/js/apps/projectActivity/utils.ts index cd2c864eefc..679b47ac194 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/utils.ts +++ b/server/sonar-web/src/main/js/apps/projectActivity/utils.ts @@ -30,8 +30,8 @@ import { serializeString, serializeStringArray } from '../../helpers/query'; -import { GraphType } from '../../types/project-activity'; -import { Dict, ParsedAnalysis, RawQuery } from '../../types/types'; +import { GraphType, ParsedAnalysis } from '../../types/project-activity'; +import { Dict, RawQuery } from '../../types/types'; export interface Query { category: string; diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx index a68bf11ed8f..17f9c960606 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx @@ -34,12 +34,8 @@ import { translate } from '../../../helpers/l10n'; import { AppState } from '../../../types/appstate'; import { Branch, BranchLike } from '../../../types/branch-like'; import { Feature } from '../../../types/features'; -import { - Component, - NewCodePeriod, - NewCodePeriodSettingType, - ParsedAnalysis -} from '../../../types/types'; +import { ParsedAnalysis } from '../../../types/project-activity'; +import { Component, NewCodePeriod, NewCodePeriodSettingType } from '../../../types/types'; import '../styles.css'; import { getSettingValue } from '../utils'; import AppHeader from './AppHeader'; diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisList.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisList.tsx index c133dee8f1f..ac39e3d3279 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisList.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisList.tsx @@ -23,7 +23,8 @@ import * as React from 'react'; import { getProjectActivity } from '../../../api/projectActivity'; import { parseDate, toShortNotSoISOString } from '../../../helpers/dates'; import { scrollToElement } from '../../../helpers/scrolling'; -import { Analysis, Dict, ParsedAnalysis } from '../../../types/types'; +import { Analysis, ParsedAnalysis } from '../../../types/project-activity'; +import { Dict } from '../../../types/types'; import BranchAnalysisListRenderer from './BranchAnalysisListRenderer'; interface Props { diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisListRenderer.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisListRenderer.tsx index f33c1ddb72a..59e9734ab6c 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisListRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchAnalysisListRenderer.tsx @@ -27,7 +27,7 @@ import TimeFormatter from '../../../components/intl/TimeFormatter'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { parseDate, toShortNotSoISOString } from '../../../helpers/dates'; import { translate } from '../../../helpers/l10n'; -import { ParsedAnalysis } from '../../../types/types'; +import { ParsedAnalysis } from '../../../types/project-activity'; import Events from '../../projectActivity/components/Events'; import { getAnalysesByVersionByDay } from '../../projectActivity/utils'; diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchBaselineSettingModal.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchBaselineSettingModal.tsx index b3b074509f4..30fcb1080c0 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchBaselineSettingModal.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchBaselineSettingModal.tsx @@ -25,7 +25,8 @@ import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { toNotSoISOString } from '../../../helpers/dates'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { Branch, BranchWithNewCodePeriod } from '../../../types/branch-like'; -import { NewCodePeriod, NewCodePeriodSettingType, ParsedAnalysis } from '../../../types/types'; +import { ParsedAnalysis } from '../../../types/project-activity'; +import { NewCodePeriod, NewCodePeriodSettingType } from '../../../types/types'; import { getSettingValue, validateSetting } from '../utils'; import BaselineSettingAnalysis from './BaselineSettingAnalysis'; import BaselineSettingDays from './BaselineSettingDays'; diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/ProjectBaselineSelector.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/ProjectBaselineSelector.tsx index 190f93fcb13..724d16a6020 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/ProjectBaselineSelector.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/ProjectBaselineSelector.tsx @@ -25,7 +25,8 @@ import { Alert } from '../../../components/ui/Alert'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { Branch } from '../../../types/branch-like'; -import { NewCodePeriod, NewCodePeriodSettingType, ParsedAnalysis } from '../../../types/types'; +import { ParsedAnalysis } from '../../../types/project-activity'; +import { NewCodePeriod, NewCodePeriodSettingType } from '../../../types/types'; import { validateSetting } from '../utils'; import BaselineSettingAnalysis from './BaselineSettingAnalysis'; import BaselineSettingDays from './BaselineSettingDays'; diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisList-test.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisList-test.tsx index 72ba24597a0..17d935e0480 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisList-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisList-test.tsx @@ -22,7 +22,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { getProjectActivity } from '../../../../api/projectActivity'; import { toShortNotSoISOString } from '../../../../helpers/dates'; -import { mockAnalysis, mockAnalysisEvent } from '../../../../helpers/testMocks'; +import { mockAnalysis, mockAnalysisEvent } from '../../../../helpers/mocks/project-activity'; import { waitAndUpdate } from '../../../../helpers/testUtils'; import BranchAnalysisList from '../BranchAnalysisList'; diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisListRenderer-test.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisListRenderer-test.tsx index 98c9fab01e5..1fa07679e2c 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisListRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisListRenderer-test.tsx @@ -19,7 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockAnalysisEvent, mockParsedAnalysis } from '../../../../helpers/testMocks'; +import { mockAnalysisEvent, mockParsedAnalysis } from '../../../../helpers/mocks/project-activity'; import BranchAnalysisListRenderer, { BranchAnalysisListRendererProps } from '../BranchAnalysisListRenderer'; diff --git a/server/sonar-web/src/main/js/components/activity-graph/DataTableModal.tsx b/server/sonar-web/src/main/js/components/activity-graph/DataTableModal.tsx index 8cfea76f95c..ef88cf83586 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/DataTableModal.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/DataTableModal.tsx @@ -20,7 +20,6 @@ import { filter, slice, sortBy } from 'lodash'; import * as React from 'react'; import { FormattedMessage } from 'react-intl'; -import EventInner from '../../apps/projectActivity/components/EventInner'; import { translate, translateWithParameters } from '../../helpers/l10n'; import { formatMeasure } from '../../helpers/measures'; import { ParsedAnalysis, Serie } from '../../types/project-activity'; @@ -29,6 +28,7 @@ import Modal from '../controls/Modal'; import DateFormatter from '../intl/DateFormatter'; import TimeFormatter from '../intl/TimeFormatter'; import { Alert } from '../ui/Alert'; +import EventInner from './EventInner'; import { getAnalysisEventsForDate } from './utils'; export interface DataTableModalProps { diff --git a/server/sonar-web/src/main/js/components/activity-graph/DefinitionChangeEventInner.tsx b/server/sonar-web/src/main/js/components/activity-graph/DefinitionChangeEventInner.tsx new file mode 100644 index 00000000000..7d52c9c970b --- /dev/null +++ b/server/sonar-web/src/main/js/components/activity-graph/DefinitionChangeEventInner.tsx @@ -0,0 +1,169 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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 * as React from 'react'; +import { FormattedMessage } from 'react-intl'; +import { isMainBranch } from '../../helpers/branch-like'; +import { translate } from '../../helpers/l10n'; +import { limitComponentName } from '../../helpers/path'; +import { getProjectUrl } from '../../helpers/urls'; +import { BranchLike } from '../../types/branch-like'; +import { AnalysisEvent } from '../../types/project-activity'; +import Link from '../common/Link'; +import { ButtonLink } from '../controls/buttons'; +import BranchIcon from '../icons/BranchIcon'; +import DropdownIcon from '../icons/DropdownIcon'; + +export type DefinitionChangeEvent = AnalysisEvent & + Required>; + +export function isDefinitionChangeEvent(event: AnalysisEvent): event is DefinitionChangeEvent { + return event.category === 'DEFINITION_CHANGE' && event.definitionChange !== undefined; +} + +interface Props { + branchLike: BranchLike | undefined; + event: DefinitionChangeEvent; + readonly?: boolean; +} + +interface State { + expanded: boolean; +} + +export class DefinitionChangeEventInner extends React.PureComponent { + state: State = { expanded: false }; + + stopPropagation = (event: React.MouseEvent) => { + event.stopPropagation(); + }; + + toggleProjectsList = () => { + this.setState(state => ({ expanded: !state.expanded })); + }; + + renderProjectLink = (project: { key: string; name: string }, branch: string | undefined) => ( + + {limitComponentName(project.name, 28)} + + ); + + renderBranch = (branch = translate('branches.main_branch')) => ( + + + {branch} + + ); + + renderProjectChange(project: { + changeType: string; + key: string; + name: string; + branch?: string; + newBranch?: string; + oldBranch?: string; + }) { + const mainBranch = !this.props.branchLike || isMainBranch(this.props.branchLike); + + if (project.changeType === 'ADDED') { + const message = mainBranch + ? 'event.definition_change.added' + : 'event.definition_change.branch_added'; + return ( +
+ +
+ ); + } else if (project.changeType === 'REMOVED') { + const message = mainBranch + ? 'event.definition_change.removed' + : 'event.definition_change.branch_removed'; + return ( +
+ +
+ ); + } else if (project.changeType === 'BRANCH_CHANGED') { + return ( + + ); + } + return null; + } + + render() { + const { event, readonly } = this.props; + const { expanded } = this.state; + return ( + <> + + {translate('event.category', event.category)} + {!readonly && ':'} + + + {!readonly && ( +
+ + {expanded ? translate('hide') : translate('more')} + + +
+ )} + + {expanded && ( +
    + {event.definitionChange.projects.map(project => ( +
  • + {this.renderProjectChange(project)} +
  • + ))} +
+ )} + + ); + } +} diff --git a/server/sonar-web/src/main/js/components/activity-graph/EventInner.tsx b/server/sonar-web/src/main/js/components/activity-graph/EventInner.tsx new file mode 100644 index 00000000000..b4dc517d75a --- /dev/null +++ b/server/sonar-web/src/main/js/components/activity-graph/EventInner.tsx @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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 * as React from 'react'; +import { ComponentContext } from '../../app/components/componentContext/ComponentContext'; +import { translate } from '../../helpers/l10n'; +import { AnalysisEvent } from '../../types/project-activity'; +import Tooltip from '../controls/Tooltip'; +import { DefinitionChangeEventInner, isDefinitionChangeEvent } from './DefinitionChangeEventInner'; +import { isRichQualityGateEvent, RichQualityGateEventInner } from './RichQualityGateEventInner'; + +export interface EventInnerProps { + event: AnalysisEvent; + readonly?: boolean; +} + +export default function EventInner({ event, readonly }: EventInnerProps) { + if (isRichQualityGateEvent(event)) { + return ; + } else if (isDefinitionChangeEvent(event)) { + return ( + + {({ branchLike }) => ( + + )} + + ); + } + + return ( + + + + {translate('event.category', event.category)}: + + {event.name} + + + ); +} diff --git a/server/sonar-web/src/main/js/components/activity-graph/GraphHistory.tsx b/server/sonar-web/src/main/js/components/activity-graph/GraphHistory.tsx index f19056711d3..bb674ec3a21 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/GraphHistory.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/GraphHistory.tsx @@ -22,8 +22,7 @@ import { AutoSizer } from 'react-virtualized/dist/commonjs/AutoSizer'; import AdvancedTimeline from '../../components/charts/AdvancedTimeline'; import { translate } from '../../helpers/l10n'; import { formatMeasure, getShortType } from '../../helpers/measures'; -import { MeasureHistory, Serie } from '../../types/project-activity'; -import { ParsedAnalysis } from '../../types/types'; +import { MeasureHistory, ParsedAnalysis, Serie } from '../../types/project-activity'; import { Button } from '../controls/buttons'; import ModalButton from '../controls/ModalButton'; import DataTableModal from './DataTableModal'; diff --git a/server/sonar-web/src/main/js/components/activity-graph/GraphsHistory.tsx b/server/sonar-web/src/main/js/components/activity-graph/GraphsHistory.tsx index 288bd4773b3..d4924ebb2be 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/GraphsHistory.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/GraphsHistory.tsx @@ -22,8 +22,7 @@ import * as React from 'react'; import DeferredSpinner from '../../components/ui/DeferredSpinner'; import { translate, translateWithParameters } from '../../helpers/l10n'; import { getBaseUrl } from '../../helpers/system'; -import { GraphType, MeasureHistory, Serie } from '../../types/project-activity'; -import { ParsedAnalysis } from '../../types/types'; +import { GraphType, MeasureHistory, ParsedAnalysis, Serie } from '../../types/project-activity'; import GraphHistory from './GraphHistory'; import './styles.css'; import { getSeriesMetricType, hasHistoryData, isCustomGraph } from './utils'; diff --git a/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltips.tsx b/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltips.tsx index 25c93ea2fef..b7d49b60cd5 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltips.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltips.tsx @@ -20,8 +20,7 @@ import * as React from 'react'; import { Popup, PopupPlacement } from '../../components/ui/popups'; import { isDefined } from '../../helpers/types'; -import { MeasureHistory, Serie } from '../../types/project-activity'; -import { AnalysisEvent } from '../../types/types'; +import { AnalysisEvent, MeasureHistory, Serie } from '../../types/project-activity'; import DateTimeFormatter from '../intl/DateTimeFormatter'; import GraphsTooltipsContent from './GraphsTooltipsContent'; import GraphsTooltipsContentCoverage from './GraphsTooltipsContentCoverage'; diff --git a/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltipsContentEvents.tsx b/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltipsContentEvents.tsx index 466e0c1edf8..85cafa0761b 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltipsContentEvents.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/GraphsTooltipsContentEvents.tsx @@ -18,8 +18,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import EventInner from '../../apps/projectActivity/components/EventInner'; -import { AnalysisEvent } from '../../types/types'; +import { AnalysisEvent } from '../../types/project-activity'; +import EventInner from './EventInner'; interface Props { addSeparator: boolean; diff --git a/server/sonar-web/src/main/js/components/activity-graph/RichQualityGateEventInner.tsx b/server/sonar-web/src/main/js/components/activity-graph/RichQualityGateEventInner.tsx new file mode 100644 index 00000000000..2f81862002c --- /dev/null +++ b/server/sonar-web/src/main/js/components/activity-graph/RichQualityGateEventInner.tsx @@ -0,0 +1,111 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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 * as React from 'react'; +import { FormattedMessage } from 'react-intl'; +import { translate, translateWithParameters } from '../../helpers/l10n'; +import { getProjectUrl } from '../../helpers/urls'; +import { AnalysisEvent } from '../../types/project-activity'; +import Link from '../common/Link'; +import { ResetButtonLink } from '../controls/buttons'; +import DropdownIcon from '../icons/DropdownIcon'; +import Level from '../ui/Level'; + +export type RichQualityGateEvent = AnalysisEvent & Required>; + +export function isRichQualityGateEvent(event: AnalysisEvent): event is RichQualityGateEvent { + return event.category === 'QUALITY_GATE' && event.qualityGate !== undefined; +} + +interface Props { + event: RichQualityGateEvent; + readonly?: boolean; +} + +interface State { + expanded: boolean; +} + +export class RichQualityGateEventInner extends React.PureComponent { + state: State = { expanded: false }; + + stopPropagation = (event: React.MouseEvent) => { + event.stopPropagation(); + }; + + toggleProjectsList = () => { + this.setState(state => ({ expanded: !state.expanded })); + }; + + render() { + const { event, readonly } = this.props; + const { expanded } = this.state; + return ( + <> + {translate('event.category', event.category)}: + {event.qualityGate.stillFailing ? ( + }} + /> + ) : ( + + )} + +
+ {!readonly && event.qualityGate.failing.length > 0 && ( + + {expanded ? translate('hide') : translate('more')} + + + )} +
+ + {expanded && ( +
    + {event.qualityGate.failing.map(project => ( +
  • + +
    + + + {project.name} + + +
    +
  • + ))} +
+ )} + + ); + } +} diff --git a/server/sonar-web/src/main/js/components/activity-graph/__tests__/DefinitionChangeEventInner-test.tsx b/server/sonar-web/src/main/js/components/activity-graph/__tests__/DefinitionChangeEventInner-test.tsx new file mode 100644 index 00000000000..9c5d0a62286 --- /dev/null +++ b/server/sonar-web/src/main/js/components/activity-graph/__tests__/DefinitionChangeEventInner-test.tsx @@ -0,0 +1,88 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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 { shallow } from 'enzyme'; +import * as React from 'react'; +import { mockBranch } from '../../../helpers/mocks/branch-like'; +import { click } from '../../../helpers/testUtils'; +import { DefinitionChangeEvent, DefinitionChangeEventInner } from '../DefinitionChangeEventInner'; + +it('should render', () => { + const event: DefinitionChangeEvent = { + category: 'DEFINITION_CHANGE', + key: 'foo1234', + name: '', + definitionChange: { + projects: [ + { changeType: 'ADDED', key: 'foo', name: 'Foo', branch: 'master' }, + { changeType: 'REMOVED', key: 'bar', name: 'Bar', branch: 'master' } + ] + } + }; + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + + click(wrapper.find('.project-activity-event-inner-more-link')); + wrapper.update(); + expect(wrapper).toMatchSnapshot(); +}); + +it('should render for a branch', () => { + const branch = mockBranch({ name: 'feature-x' }); + const event: DefinitionChangeEvent = { + category: 'DEFINITION_CHANGE', + key: 'foo1234', + name: '', + definitionChange: { + projects: [ + { changeType: 'ADDED', key: 'foo', name: 'Foo', branch: 'feature-x' }, + { + changeType: 'BRANCH_CHANGED', + key: 'bar', + name: 'Bar', + oldBranch: 'master', + newBranch: 'feature-y' + } + ] + } + }; + const wrapper = shallow(); + click(wrapper.find('.project-activity-event-inner-more-link')); + wrapper.update(); + expect(wrapper).toMatchSnapshot(); +}); + +it('should render when readonly', () => { + const event: DefinitionChangeEvent = { + category: 'DEFINITION_CHANGE', + key: 'foo1234', + name: '', + definitionChange: { + projects: [ + { changeType: 'ADDED', key: 'foo', name: 'Foo', branch: 'master' }, + { changeType: 'REMOVED', key: 'bar', name: 'Bar', branch: 'master' } + ] + } + }; + const wrapper = shallow( + + ); + expect(wrapper).toMatchSnapshot(); + expect(wrapper.find('.project-activity-event-inner-more-link').exists()).toBe(false); +}); diff --git a/server/sonar-web/src/main/js/components/activity-graph/__tests__/EventInner-test.tsx b/server/sonar-web/src/main/js/components/activity-graph/__tests__/EventInner-test.tsx new file mode 100644 index 00000000000..950e389f6ca --- /dev/null +++ b/server/sonar-web/src/main/js/components/activity-graph/__tests__/EventInner-test.tsx @@ -0,0 +1,75 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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 { shallow } from 'enzyme'; +import * as React from 'react'; +import { mockAnalysisEvent } from '../../../helpers/mocks/project-activity'; +import { BranchLike } from '../../../types/branch-like'; +import EventInner, { EventInnerProps } from '../EventInner'; + +jest.mock('../../../app/components/componentContext/ComponentContext', () => { + const { mockBranch } = jest.requireActual('../../../helpers/mocks/branch-like'); + return { + ComponentContext: { + Consumer: ({ + children + }: { + children: (props: { branchLike: BranchLike }) => React.ReactNode; + }) => { + return children({ branchLike: mockBranch() }); + } + } + }; +}); + +it('should render correctly', () => { + expect(shallowRender()).toMatchSnapshot('default'); + expect( + shallowRender({ + event: mockAnalysisEvent({ + category: 'VERSION', + description: undefined, + qualityGate: undefined + }) + }) + ).toMatchSnapshot('no description'); + expect(shallowRender({ event: mockAnalysisEvent() })).toMatchSnapshot('rich quality gate'); + expect( + shallowRender({ + event: mockAnalysisEvent({ + category: 'DEFINITION_CHANGE', + definitionChange: { + projects: [{ changeType: 'ADDED', key: 'foo', name: 'Foo' }] + }, + qualityGate: undefined + }) + }) + .find('Consumer') + .dive() + ).toMatchSnapshot('definition change'); +}); + +function shallowRender(props: Partial = {}) { + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphHistory-test.tsx b/server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphHistory-test.tsx index cd141b7a13d..7cd02bd75b8 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphHistory-test.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphHistory-test.tsx @@ -44,7 +44,8 @@ it('should correctly render a graph', () => { function shallowRender(overrides: Partial = {}) { return shallow( { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + + click(wrapper.find('.project-activity-event-inner-more-link')); + wrapper.update(); + expect(wrapper).toMatchSnapshot(); +}); + +it('should not expand', () => { + const wrapper = shallow( + + ); + expect(wrapper.find('.project-activity-event-inner-more-link').exists()).toBe(false); +}); + +it('should not expand when readonly', () => { + const wrapper = shallow(); + expect(wrapper.find('.project-activity-event-inner-more-link').exists()).toBe(false); +}); diff --git a/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/DefinitionChangeEventInner-test.tsx.snap b/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/DefinitionChangeEventInner-test.tsx.snap new file mode 100644 index 00000000000..ce770c6fcd3 --- /dev/null +++ b/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/DefinitionChangeEventInner-test.tsx.snap @@ -0,0 +1,248 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render 1`] = ` + + + event.category.DEFINITION_CHANGE + : + +
+ + more + + +
+
+`; + +exports[`should render 2`] = ` + + + event.category.DEFINITION_CHANGE + : + +
+ + hide + + +
+
    +
  • +
    + + + master + , + "project": + Foo + , + } + } + /> +
    +
  • +
  • +
    + + + master + , + "project": + Bar + , + } + } + /> +
    +
  • +
+
+`; + +exports[`should render for a branch 1`] = ` + + + event.category.DEFINITION_CHANGE + : + +
+ + hide + + +
+
    +
  • +
    + + + feature-x + , + "project": + Foo + , + } + } + /> +
    +
  • +
  • + + + feature-y + , + "oldBranch": + + master + , + "project": + Bar + , + } + } + /> +
  • +
+
+`; + +exports[`should render when readonly 1`] = ` + + + event.category.DEFINITION_CHANGE + + +`; diff --git a/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/EventInner-test.tsx.snap b/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/EventInner-test.tsx.snap new file mode 100644 index 00000000000..639a2bb4f5d --- /dev/null +++ b/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/EventInner-test.tsx.snap @@ -0,0 +1,105 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly: default 1`] = ` + + + + event.category.VERSION + : + + + Lorem ipsum + + + +`; + +exports[`should render correctly: definition change 1`] = ` + +`; + +exports[`should render correctly: no description 1`] = ` + + + + event.category.VERSION + : + + + Lorem ipsum + + + +`; + +exports[`should render correctly: rich quality gate 1`] = ` + +`; diff --git a/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/GraphHistory-test.tsx.snap b/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/GraphHistory-test.tsx.snap index 5c0af0d1425..f1443c67c06 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/GraphHistory-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/GraphHistory-test.tsx.snap @@ -37,10 +37,10 @@ exports[`should correctly render a graph 1`] = `
+ + event.category.QUALITY_GATE + : + + , + } + } + /> +
+ + more + + +
+ +`; + +exports[`should render 2`] = ` + + + event.category.QUALITY_GATE + : + + , + } + } + /> +
+ + hide + + +
+
    +
  • + +
    + + + Foo + + +
    +
  • +
  • + +
    + + + Bar + + +
    +
  • +
+
+`; diff --git a/server/sonar-web/src/main/js/components/activity-graph/utils.ts b/server/sonar-web/src/main/js/components/activity-graph/utils.ts index 46e3714d696..4c84246e277 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/utils.ts +++ b/server/sonar-web/src/main/js/components/activity-graph/utils.ts @@ -22,8 +22,8 @@ import { getLocalizedMetricName, translate } from '../../helpers/l10n'; import { localizeMetric } from '../../helpers/measures'; import { get, save } from '../../helpers/storage'; import { MetricKey } from '../../types/metrics'; -import { GraphType, MeasureHistory, Serie } from '../../types/project-activity'; -import { Dict, Metric, ParsedAnalysis } from '../../types/types'; +import { GraphType, MeasureHistory, ParsedAnalysis, Serie } from '../../types/project-activity'; +import { Dict, Metric } from '../../types/types'; export const DEFAULT_GRAPH = GraphType.issues; diff --git a/server/sonar-web/src/main/js/helpers/mocks/project-activity.ts b/server/sonar-web/src/main/js/helpers/mocks/project-activity.ts new file mode 100644 index 00000000000..439bf4a576d --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/mocks/project-activity.ts @@ -0,0 +1,67 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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 { Analysis, AnalysisEvent, ParsedAnalysis } from '../../types/project-activity'; + +export function mockAnalysis(overrides: Partial = {}): Analysis { + return { + date: '2017-03-01T09:36:01+0100', + events: [], + key: 'foo', + projectVersion: '1.0', + ...overrides + }; +} + +export function mockParsedAnalysis(overrides: Partial = {}): ParsedAnalysis { + return { + date: new Date('2017-03-01T09:37:01+0100'), + events: [], + key: 'foo', + projectVersion: '1.0', + ...overrides + }; +} + +export function mockAnalysisEvent(overrides: Partial = {}): AnalysisEvent { + return { + category: 'QUALITY_GATE', + key: 'E11', + description: 'Lorem ipsum dolor sit amet', + name: 'Lorem ipsum', + qualityGate: { + status: 'ERROR', + stillFailing: true, + failing: [ + { + key: 'foo', + name: 'Foo', + branch: 'master' + }, + { + key: 'bar', + name: 'Bar', + branch: 'feature/bar' + } + ] + }, + ...overrides + }; +} diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index 4c46878abcb..0f89329fe9f 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -31,8 +31,6 @@ import { DumpStatus, DumpTask } from '../types/project-dump'; import { TaskStatuses } from '../types/tasks'; import { AlmApplication, - Analysis, - AnalysisEvent, Condition, FlowLocation, Group, @@ -43,7 +41,6 @@ import { MeasureEnhanced, Metric, Paging, - ParsedAnalysis, Period, ProfileInheritanceDetails, Rule, @@ -67,52 +64,6 @@ export function mockAlmApplication(overrides: Partial = {}): Alm }; } -export function mockAnalysis(overrides: Partial = {}): Analysis { - return { - date: '2017-03-01T09:36:01+0100', - events: [], - key: 'foo', - projectVersion: '1.0', - ...overrides - }; -} - -export function mockParsedAnalysis(overrides: Partial = {}): ParsedAnalysis { - return { - date: new Date('2017-03-01T09:37:01+0100'), - events: [], - key: 'foo', - projectVersion: '1.0', - ...overrides - }; -} - -export function mockAnalysisEvent(overrides: Partial = {}): AnalysisEvent { - return { - category: 'QUALITY_GATE', - key: 'E11', - description: 'Lorem ipsum dolor sit amet', - name: 'Lorem ipsum', - qualityGate: { - status: 'ERROR', - stillFailing: true, - failing: [ - { - key: 'foo', - name: 'Foo', - branch: 'master' - }, - { - key: 'bar', - name: 'Bar', - branch: 'feature/bar' - } - ] - }, - ...overrides - }; -} - export function mockAppState(overrides: Partial = {}): AppState { return { edition: EditionKey.community, diff --git a/server/sonar-web/src/main/js/types/project-activity.ts b/server/sonar-web/src/main/js/types/project-activity.ts index 065f679d945..864f9577484 100644 --- a/server/sonar-web/src/main/js/types/project-activity.ts +++ b/server/sonar-web/src/main/js/types/project-activity.ts @@ -17,6 +17,45 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +interface BaseAnalysis { + buildString?: string; + detectedCI?: string; + events: AnalysisEvent[]; + key: string; + manualNewCodePeriodBaseline?: boolean; + projectVersion?: string; +} + +export interface Analysis extends BaseAnalysis { + date: string; +} + +export interface ParsedAnalysis extends BaseAnalysis { + date: Date; +} + +export interface AnalysisEvent { + category: string; + description?: string; + key: string; + name: string; + qualityGate?: { + failing: Array<{ branch: string; key: string; name: string }>; + status: string; + stillFailing: boolean; + }; + definitionChange?: { + projects: Array<{ + branch?: string; + changeType: string; + key: string; + name: string; + newBranch?: string; + oldBranch?: string; + }>; + }; +} + export enum GraphType { issues = 'issues', coverage = 'coverage', diff --git a/server/sonar-web/src/main/js/types/types.ts b/server/sonar-web/src/main/js/types/types.ts index e4495e1bc3c..a6d68a4336c 100644 --- a/server/sonar-web/src/main/js/types/types.ts +++ b/server/sonar-web/src/main/js/types/types.ts @@ -49,45 +49,6 @@ export interface AlmUnboundApplication { name: string; } -interface BaseAnalysis { - buildString?: string; - detectedCI?: string; - events: AnalysisEvent[]; - key: string; - manualNewCodePeriodBaseline?: boolean; - projectVersion?: string; -} - -export interface Analysis extends BaseAnalysis { - date: string; -} - -export interface ParsedAnalysis extends BaseAnalysis { - date: Date; -} - -export interface AnalysisEvent { - category: string; - description?: string; - key: string; - name: string; - qualityGate?: { - failing: Array<{ branch: string; key: string; name: string }>; - status: string; - stillFailing: boolean; - }; - definitionChange?: { - projects: Array<{ - branch?: string; - changeType: string; - key: string; - name: string; - newBranch?: string; - oldBranch?: string; - }>; - }; -} - export interface Breadcrumb { key: string; name: string;