From 49789f6a622f402e85a72b9b77b9dfa827785a60 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal <45544358+wouter-admiraal-sonarsource@users.noreply.github.com> Date: Mon, 30 Aug 2021 12:10:31 +0200 Subject: [PATCH] SONAR-12018 Keep users on Measures page when drilling down --- .../__tests__/ComponentContainer-test.tsx | 3 +- .../__tests__/ProjectAdminContainer-test.tsx | 2 +- .../ProjectAdminPageExtension-test.tsx | 3 +- .../__tests__/ProjectPageExtension-test.tsx | 3 +- .../component/__tests__/Breadcrumb-test.tsx | 2 +- .../component/__tests__/ComponentNav-test.tsx | 2 +- .../ComponentNavBgTaskNotif-test.tsx | 3 +- ...ponentNavProjectBindingErrorNotif-test.tsx | 2 +- .../nav/component/__tests__/Header-test.tsx | 3 +- .../component/__tests__/HeaderMeta-test.tsx | 3 +- .../nav/component/__tests__/Menu-test.tsx | 2 +- .../__tests__/BranchLikeNavigation-test.tsx | 3 +- .../__tests__/CurrentBranchLike-test.tsx | 2 +- .../branch-like/__tests__/Menu-test.tsx | 3 +- .../branch-like/__tests__/MenuItem-test.tsx | 2 +- .../__tests__/MenuItemList-test.tsx | 2 +- .../__tests__/ProjectInformation-test.tsx | 8 +- .../ProjectInformationRenderer-test.tsx | 2 +- .../meta/__tests__/MetaSize-test.tsx | 3 +- .../meta/__tests__/MetaTags-test.tsx | 2 +- .../__tests__/ProjectNotifications-test.tsx | 2 +- .../__tests__/ApplicationSettingsApp-test.tsx | 2 +- .../components/__tests__/Stats-test.tsx | 2 +- .../components/__tests__/AppCode-test.tsx | 8 +- .../components/__tests__/Component-test.tsx | 3 +- .../__tests__/ComponentMeasure-test.tsx | 3 +- .../__tests__/ComponentName-test.tsx | 2 +- .../__tests__/ComponentsHeader-test.tsx | 2 +- .../components/MeasureContent.tsx | 9 +- .../components/MeasureViewSelect.tsx | 9 +- .../components/__tests__/App-test.tsx | 3 +- .../__tests__/MeasureContent-test.tsx | 5 +- .../__tests__/MeasureOverview-test.tsx | 4 +- .../__tests__/MeasureViewSelect-test.tsx | 34 +- .../MeasureViewSelect-test.tsx.snap | 51 ++- .../drilldown/ComponentCell.tsx | 168 +++++---- .../drilldown/ComponentsList.tsx | 5 +- .../drilldown/ComponentsListRow.tsx | 6 +- .../drilldown/FilesView.tsx | 5 +- .../drilldown/__tests__/BubbleChart-test.tsx | 8 +- .../__tests__/ComponentCell-test.tsx | 106 +++++- .../__tests__/ComponentList-test.tsx | 3 - .../__snapshots__/ComponentCell-test.tsx.snap | 334 +++++++++++++++++- .../__snapshots__/ComponentList-test.tsx.snap | 2 - .../__snapshots__/FilesView-test.tsx.snap | 2 - .../main/js/apps/component-measures/utils.ts | 11 +- .../issues/components/__tests__/App-test.tsx | 2 +- .../sidebar/__tests__/AuthorFacet-test.tsx | 2 +- .../__tests__/CreationDateFacet-test.tsx | 2 +- .../sidebar/__tests__/DirectoryFacet-test.tsx | 2 +- .../sidebar/__tests__/FileFacet-test.tsx | 2 +- .../sidebar/__tests__/ProjectFacet-test.tsx | 2 +- .../issues/sidebar/__tests__/Sidebar-test.tsx | 2 +- .../branches/__tests__/ActivityPanel-test.tsx | 2 +- .../__tests__/BranchOverview-test.tsx | 3 +- .../__tests__/BranchOverviewRenderer-test.tsx | 3 +- .../branches/__tests__/DebtValue-test.tsx | 3 +- .../__tests__/DrilldownMeasureValue-test.tsx | 3 +- .../FirstAnalysisNextStepsNotif-test.tsx | 3 +- .../branches/__tests__/MeasuresPanel-test.tsx | 8 +- .../MeasuresPanelIssueMeasureRow-test.tsx | 3 +- .../__tests__/MeasuresPanelNoNewCode-test.tsx | 3 +- .../branches/__tests__/NoCodeWarning-test.tsx | 3 +- .../__tests__/QualityGatePanel-test.tsx | 3 +- .../QualityGatePanelSection-test.tsx | 2 +- .../__tests__/EmptyOverview-test.tsx | 3 +- .../components/__tests__/IssueLabel-test.tsx | 3 +- .../components/__tests__/IssueRating-test.tsx | 3 +- .../__tests__/MeasurementLabel-test.tsx | 3 +- .../__tests__/QualityGateConditions-test.tsx | 2 +- .../__tests__/LargeQualityGateBadge-test.tsx | 2 +- .../__tests__/PullRequestOverview-test.tsx | 2 +- .../project/components/__tests__/App-test.tsx | 2 +- .../components/__tests__/App-test.tsx | 2 +- .../__tests__/UnsubscribeEmailModal-test.tsx | 2 +- .../ProjectActivityAppContainer-test.tsx | 3 +- .../components/__tests__/App-test.tsx | 3 +- .../components/__tests__/BranchList-test.tsx | 2 +- .../components/__tests__/App-test.tsx | 2 +- .../__tests__/BranchLikeRow-test.tsx | 2 +- .../__tests__/BranchLikeTable-test.tsx | 2 +- .../__tests__/BranchLikeTabs-test.tsx | 2 +- .../__tests__/BranchPurgeSetting-test.tsx | 2 +- .../__tests__/DeleteBranchModal-test.tsx | 2 +- .../__tests__/RenameBranchModal-test.tsx | 2 +- .../projectKey/__tests__/UpdateForm-test.tsx | 3 +- .../__tests__/ProjectQualityGateApp-test.tsx | 2 +- .../ProjectQualityProfilesApp-test.tsx | 2 +- ...ProjectQualityProfilesAppRenderer-test.tsx | 3 +- .../__tests__/SetQualityProfileModal-test.tsx | 3 +- .../js/apps/projects/__tests__/utils-test.ts | 2 +- .../__tests__/SecurityHotspotsApp-test.tsx | 2 +- .../SecurityHotspotsAppRenderer-test.tsx | 2 +- .../components/__tests__/FilterBar-test.tsx | 3 +- .../HotspotSnippetContainer-test.tsx | 3 +- .../__tests__/HotspotViewer-test.tsx | 2 +- .../__tests__/HotspotViewerRenderer-test.tsx | 3 +- .../__tests__/AdditionalCategories-test.tsx | 2 +- .../__tests__/AllCategoriesList-test.tsx | 2 +- .../__tests__/AnalysisScope-test.tsx | 2 +- .../components/__tests__/Languages-test.tsx | 3 +- .../components/__tests__/PageHeader-test.tsx | 2 +- .../__tests__/PRDecorationBinding-test.tsx | 3 +- .../__tests__/TutorialsApp-test.tsx | 3 +- .../__tests__/ComponentReportActions-test.tsx | 3 +- .../ComponentReportActionsRenderer-test.tsx | 2 +- .../__tests__/withKeyboardNavigation-test.tsx | 2 +- .../issue/__tests__/actions-test.ts | 3 +- .../__tests__/TutorialSelection-test.tsx | 8 +- .../TutorialSelectionRenderer-test.tsx | 3 +- .../__tests__/AzurePipelinesTutorial-test.tsx | 3 +- .../BranchAnalysisStepContent-test.tsx | 2 +- .../ServiceEndpointStepContent-test.tsx | 3 +- .../__tests__/AnalysisCommand-test.tsx | 3 +- .../BitbucketPipelinesTutorial-test.tsx | 3 +- .../__tests__/PreambuleYaml-test.tsx | 2 +- .../__tests__/RepositoryVariables-test.tsx | 3 +- .../__tests__/DefaultProjectKey-test.tsx | 2 +- .../__tests__/EditTokenModal-test.tsx | 3 +- .../__tests__/TokenStepGenerator-test.tsx | 3 +- .../__tests__/AnalysisCommand-test.tsx | 3 +- .../__tests__/GitHubActionTutorial-test.tsx | 3 +- .../__tests__/SecretStep-test.tsx | 3 +- .../commands/__tests__/CFamily-test.tsx | 2 +- .../commands/__tests__/DotNet-test.tsx | 2 +- .../commands/__tests__/Gradle-test.tsx | 2 +- .../commands/__tests__/JavaMaven-test.tsx | 2 +- .../commands/__tests__/Others-test.tsx | 2 +- .../EnvironmentVariablesStep-test.tsx | 3 +- .../__tests__/GitLabCITutorial-test.tsx | 3 +- .../__tests__/ProjectKeyStep-test.tsx | 2 +- .../__tests__/JenkinsTutorial-test.tsx | 2 +- .../__tests__/JenkinsfileStep-test.tsx | 2 +- .../__tests__/CFamilly-test.tsx | 2 +- .../buildtool-steps/__tests__/DotNet-test.tsx | 2 +- .../__tests__/DotNetCore-test.tsx | 2 +- .../__tests__/DotNetFramework-test.tsx | 2 +- .../buildtool-steps/__tests__/Gradle-test.tsx | 2 +- .../buildtool-steps/__tests__/Maven-test.tsx | 2 +- .../buildtool-steps/__tests__/Other-test.tsx | 2 +- .../manual/__tests__/DoneNextSteps-test.tsx | 2 +- .../manual/__tests__/ManualTutorial-test.tsx | 3 +- .../__tests__/ProjectAnalysisStep-test.tsx | 2 +- .../__tests__/AnalysisCommand-test.tsx | 2 +- .../__tests__/CLangGCCCommand-test.tsx | 2 +- .../manual/commands/__tests__/DotNet-test.tsx | 2 +- .../commands/__tests__/DotNetExecute-test.tsx | 2 +- .../__tests__/DotNetFramework-test.tsx | 2 +- .../commands/__tests__/DotnetCore-test.tsx | 2 +- .../commands/__tests__/ExecScanner-test.tsx | 2 +- .../commands/__tests__/JavaGradle-test.tsx | 2 +- .../commands/__tests__/JavaMaven-test.tsx | 2 +- .../manual/commands/__tests__/Other-test.tsx | 2 +- .../main/js/helpers/__tests__/urls-test.ts | 88 +++++ .../src/main/js/helpers/mocks/component.ts | 47 ++- .../src/main/js/helpers/testMocks.ts | 44 --- server/sonar-web/src/main/js/helpers/urls.ts | 13 +- .../sonar-web/src/main/js/types/component.ts | 6 + .../sonar-web/src/main/js/types/measures.ts | 2 + 159 files changed, 938 insertions(+), 372 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx index d3e921899fe..6a4590cd08c 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx @@ -26,8 +26,9 @@ import { getComponentData } from '../../../api/components'; import { getComponentNavigation } from '../../../api/nav'; import { mockProjectAlmBindingConfigurationErrors } from '../../../helpers/mocks/alm-settings'; import { mockBranch, mockMainBranch, mockPullRequest } from '../../../helpers/mocks/branch-like'; +import { mockComponent } from '../../../helpers/mocks/component'; import { mockTask } from '../../../helpers/mocks/tasks'; -import { mockAppState, mockComponent, mockLocation, mockRouter } from '../../../helpers/testMocks'; +import { mockAppState, mockLocation, mockRouter } from '../../../helpers/testMocks'; import { waitAndUpdate } from '../../../helpers/testUtils'; import { AlmKeys } from '../../../types/alm-settings'; import { ComponentQualifier } from '../../../types/component'; diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ProjectAdminContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ProjectAdminContainer-test.tsx index 001822909b6..e867f7145ae 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/ProjectAdminContainer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/ProjectAdminContainer-test.tsx @@ -20,7 +20,7 @@ import { mount, shallow } from 'enzyme'; import * as React from 'react'; import handleRequiredAuthorization from '../../../app/utils/handleRequiredAuthorization'; -import { mockComponent } from '../../../helpers/testMocks'; +import { mockComponent } from '../../../helpers/mocks/component'; import ProjectAdminContainer from '../ProjectAdminContainer'; jest.mock('../../utils/handleRequiredAuthorization', () => { diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectAdminPageExtension-test.tsx b/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectAdminPageExtension-test.tsx index 047550a9f43..3219a8192e2 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectAdminPageExtension-test.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectAdminPageExtension-test.tsx @@ -19,7 +19,8 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponent, mockLocation } from '../../../../helpers/testMocks'; +import { mockComponent } from '../../../../helpers/mocks/component'; +import { mockLocation } from '../../../../helpers/testMocks'; import { ProjectAdminPageExtension, ProjectAdminPageExtensionProps diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectPageExtension-test.tsx b/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectPageExtension-test.tsx index b79a25a557b..62eeccafae5 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectPageExtension-test.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectPageExtension-test.tsx @@ -20,7 +20,8 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockMainBranch } from '../../../../helpers/mocks/branch-like'; -import { mockComponent, mockLocation } from '../../../../helpers/testMocks'; +import { mockComponent } from '../../../../helpers/mocks/component'; +import { mockLocation } from '../../../../helpers/testMocks'; import ProjectPageExtension, { ProjectPageExtensionProps } from '../ProjectPageExtension'; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Breadcrumb-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Breadcrumb-test.tsx index 2b1d7f8a931..f7a10d8085f 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Breadcrumb-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Breadcrumb-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockMainBranch } from '../../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../helpers/mocks/component'; import { ComponentQualifier } from '../../../../../types/component'; import { Breadcrumb } from '../Breadcrumb'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx index 47d8fbc25dc..c1e4fe0e54e 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx @@ -20,8 +20,8 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockProjectAlmBindingConfigurationErrors } from '../../../../../helpers/mocks/alm-settings'; +import { mockComponent } from '../../../../../helpers/mocks/component'; import { mockTask, mockTaskWarning } from '../../../../../helpers/mocks/tasks'; -import { mockComponent } from '../../../../../helpers/testMocks'; import { ComponentQualifier } from '../../../../../types/component'; import { TaskStatuses } from '../../../../../types/tasks'; import RecentHistory from '../../../RecentHistory'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx index 9c2ffae48bf..1cafb3663d7 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx @@ -22,8 +22,9 @@ import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import { Alert } from '../../../../../components/ui/Alert'; import { hasMessage } from '../../../../../helpers/l10n'; +import { mockComponent } from '../../../../../helpers/mocks/component'; import { mockTask } from '../../../../../helpers/mocks/tasks'; -import { mockComponent, mockLocation } from '../../../../../helpers/testMocks'; +import { mockLocation } from '../../../../../helpers/testMocks'; import { Task, TaskStatuses, TaskTypes } from '../../../../../types/tasks'; import { ComponentNavBgTaskNotif } from '../ComponentNavBgTaskNotif'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavProjectBindingErrorNotif-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavProjectBindingErrorNotif-test.tsx index fc6b51ad03f..35ca8b06ad1 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavProjectBindingErrorNotif-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavProjectBindingErrorNotif-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponent } from '../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../helpers/mocks/component'; import { ComponentNavProjectBindingErrorNotif, ComponentNavProjectBindingErrorNotifProps diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx index 987d9418a27..56adc77296c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx @@ -21,7 +21,8 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import Favorite from '../../../../../components/controls/Favorite'; import { mockSetOfBranchAndPullRequest } from '../../../../../helpers/mocks/branch-like'; -import { mockComponent, mockCurrentUser } from '../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../helpers/mocks/component'; +import { mockCurrentUser } from '../../../../../helpers/testMocks'; import { Header, HeaderProps } from '../Header'; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/HeaderMeta-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/HeaderMeta-test.tsx index a0ae8cfb150..fa2a4041b2c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/HeaderMeta-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/HeaderMeta-test.tsx @@ -21,8 +21,9 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import HomePageSelect from '../../../../../components/controls/HomePageSelect'; import { mockBranch, mockPullRequest } from '../../../../../helpers/mocks/branch-like'; +import { mockComponent } from '../../../../../helpers/mocks/component'; import { mockTaskWarning } from '../../../../../helpers/mocks/tasks'; -import { mockComponent, mockCurrentUser } from '../../../../../helpers/testMocks'; +import { mockCurrentUser } from '../../../../../helpers/testMocks'; import { ComponentQualifier } from '../../../../../types/component'; import { getCurrentPage, HeaderMeta, HeaderMetaProps } from '../HeaderMeta'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx index 0599e075ba2..7591d825abf 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Menu-test.tsx @@ -24,7 +24,7 @@ import { mockMainBranch, mockPullRequest } from '../../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../helpers/mocks/component'; import { ComponentQualifier } from '../../../../../types/component'; import { Menu } from '../Menu'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/BranchLikeNavigation-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/BranchLikeNavigation-test.tsx index 7f2f4b407e2..ed6b180e931 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/BranchLikeNavigation-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/BranchLikeNavigation-test.tsx @@ -21,7 +21,8 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import Toggler from '../../../../../../components/controls/Toggler'; import { mockSetOfBranchAndPullRequest } from '../../../../../../helpers/mocks/branch-like'; -import { mockAppState, mockComponent } from '../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../helpers/mocks/component'; +import { mockAppState } from '../../../../../../helpers/testMocks'; import { click } from '../../../../../../helpers/testUtils'; import { BranchLikeNavigation, BranchLikeNavigationProps } from '../BranchLikeNavigation'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/CurrentBranchLike-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/CurrentBranchLike-test.tsx index 7da6e02c498..baa825330d8 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/CurrentBranchLike-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/CurrentBranchLike-test.tsx @@ -24,7 +24,7 @@ import { mockProjectGitLabBindingResponse } from '../../../../../../helpers/mocks/alm-settings'; import { mockMainBranch } from '../../../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../helpers/mocks/component'; import { ComponentQualifier } from '../../../../../../types/component'; import { CurrentBranchLike, CurrentBranchLikeProps } from '../CurrentBranchLike'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx index a6268c83505..f0ca9926d3c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx @@ -26,7 +26,8 @@ import { mockPullRequest, mockSetOfBranchAndPullRequest } from '../../../../../../helpers/mocks/branch-like'; -import { mockComponent, mockRouter } from '../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../helpers/mocks/component'; +import { mockRouter } from '../../../../../../helpers/testMocks'; import { click, mockEvent } from '../../../../../../helpers/testUtils'; import { Menu } from '../Menu'; import { MenuItemList } from '../MenuItemList'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/MenuItem-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/MenuItem-test.tsx index fb41672dbed..c1260ef0992 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/MenuItem-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/MenuItem-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockMainBranch, mockPullRequest } from '../../../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../helpers/mocks/component'; import { click } from '../../../../../../helpers/testUtils'; import { MenuItem, MenuItemProps } from '../MenuItem'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/MenuItemList-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/MenuItemList-test.tsx index 9f9f1830f1a..473bc8c2681 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/MenuItemList-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/MenuItemList-test.tsx @@ -24,7 +24,7 @@ import { mockPullRequest, mockSetOfBranchAndPullRequest } from '../../../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../helpers/mocks/component'; import { MenuItemList, MenuItemListProps } from '../MenuItemList'; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformation-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformation-test.tsx index b6d8ff63be3..856efeeb83c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformation-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformation-test.tsx @@ -19,12 +19,8 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { - mockComponent, - mockCurrentUser, - mockLoggedInUser, - mockMetric -} from '../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../helpers/mocks/component'; +import { mockCurrentUser, mockLoggedInUser, mockMetric } from '../../../../../../helpers/testMocks'; import { waitAndUpdate } from '../../../../../../helpers/testUtils'; import { ProjectInformation } from '../ProjectInformation'; import { ProjectInformationPages } from '../ProjectInformationPages'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformationRenderer-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformationRenderer-test.tsx index b34b1039797..80bfd0483df 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformationRenderer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/ProjectInformationRenderer-test.tsx @@ -19,7 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponent } from '../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../helpers/mocks/component'; import { ProjectInformationRenderer, ProjectInformationRendererProps diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaSize-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaSize-test.tsx index 13f1f82f6de..2042cb04c41 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaSize-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaSize-test.tsx @@ -19,7 +19,8 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponent, mockMeasure } from '../../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../../helpers/mocks/component'; +import { mockMeasure } from '../../../../../../../helpers/testMocks'; import { ComponentQualifier } from '../../../../../../../types/component'; import { MetricKey } from '../../../../../../../types/metrics'; import MetaSize, { MetaSizeProps } from '../MetaSize'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaTags-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaTags-test.tsx index b83a5cc290e..59de28e4ba6 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaTags-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaTags-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { setApplicationTags, setProjectTags } from '../../../../../../../api/components'; -import { mockComponent } from '../../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../../helpers/mocks/component'; import { ComponentQualifier } from '../../../../../../../types/component'; import MetaTags from '../MetaTags'; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/notifications/__tests__/ProjectNotifications-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/notifications/__tests__/ProjectNotifications-test.tsx index 2e33d89a858..45076ab677e 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/notifications/__tests__/ProjectNotifications-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/notifications/__tests__/ProjectNotifications-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponent } from '../../../../../../../helpers/testMocks'; +import { mockComponent } from '../../../../../../../helpers/mocks/component'; import { ProjectNotifications } from '../ProjectNotifications'; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/application-settings/__tests__/ApplicationSettingsApp-test.tsx b/server/sonar-web/src/main/js/apps/application-settings/__tests__/ApplicationSettingsApp-test.tsx index 08a39bee4cc..77f8c981da3 100644 --- a/server/sonar-web/src/main/js/apps/application-settings/__tests__/ApplicationSettingsApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/application-settings/__tests__/ApplicationSettingsApp-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { setSimpleSettingValue } from '../../../api/settings'; -import { mockComponent } from '../../../helpers/testMocks'; +import { mockComponent } from '../../../helpers/mocks/component'; import { waitAndUpdate } from '../../../helpers/testUtils'; import { SettingsKey } from '../../../types/settings'; import ApplicationSettingsApp from '../ApplicationSettingsApp'; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stats-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stats-test.tsx index b0915472c99..c4da39f3186 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stats-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stats-test.tsx @@ -19,7 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponent } from '../../../../helpers/testMocks'; +import { mockComponent } from '../../../../helpers/mocks/component'; import Stats, { Props } from '../Stats'; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/AppCode-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/AppCode-test.tsx index beef71fc318..346e5028355 100644 --- a/server/sonar-web/src/main/js/apps/code/components/__tests__/AppCode-test.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/AppCode-test.tsx @@ -20,12 +20,8 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockPullRequest } from '../../../../helpers/mocks/branch-like'; -import { - mockComponent, - mockComponentMeasure, - mockIssue, - mockRouter -} from '../../../../helpers/testMocks'; +import { mockComponent, mockComponentMeasure } from '../../../../helpers/mocks/component'; +import { mockIssue, mockRouter } from '../../../../helpers/testMocks'; import { waitAndUpdate } from '../../../../helpers/testUtils'; import { ComponentQualifier } from '../../../../types/component'; import { loadMoreChildren, retrieveComponent } from '../../utils'; diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/Component-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/Component-test.tsx index 42c7322c089..1bdd69d6c41 100644 --- a/server/sonar-web/src/main/js/apps/code/components/__tests__/Component-test.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/Component-test.tsx @@ -19,7 +19,8 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponentMeasure, mockMetric } from '../../../../helpers/testMocks'; +import { mockComponentMeasure } from '../../../../helpers/mocks/component'; +import { mockMetric } from '../../../../helpers/testMocks'; import { Component } from '../Component'; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx index b0e029c4908..2de1b93fbef 100644 --- a/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx @@ -19,7 +19,8 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponentMeasure, mockMeasure, mockMetric } from '../../../../helpers/testMocks'; +import { mockComponentMeasure } from '../../../../helpers/mocks/component'; +import { mockMeasure, mockMetric } from '../../../../helpers/testMocks'; import ComponentMeasure from '../ComponentMeasure'; it('renders correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentName-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentName-test.tsx index 7c1724c95fc..049c3ccc248 100644 --- a/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentName-test.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentName-test.tsx @@ -20,7 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockMainBranch } from '../../../../helpers/mocks/branch-like'; -import { mockComponentMeasure } from '../../../../helpers/testMocks'; +import { mockComponentMeasure } from '../../../../helpers/mocks/component'; import ComponentName, { getTooltip, mostCommonPrefix, Props } from '../ComponentName'; describe('#getTooltip', () => { diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentsHeader-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentsHeader-test.tsx index 01c89144175..3c06d6b4f7e 100644 --- a/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentsHeader-test.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentsHeader-test.tsx @@ -19,7 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { mockComponent } from '../../../../helpers/testMocks'; +import { mockComponent } from '../../../../helpers/mocks/component'; import ComponentsHeader from '../ComponentsHeader'; it('renders correctly for projects', () => { diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx index a117429d6fa..c5c6b915305 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx @@ -31,11 +31,12 @@ import { RequestData } from '../../../helpers/request'; import { scrollToElement } from '../../../helpers/scrolling'; import { getProjectUrl } from '../../../helpers/urls'; import { BranchLike } from '../../../types/branch-like'; +import { MeasurePageView } from '../../../types/measures'; import { MetricKey } from '../../../types/metrics'; import { complementary } from '../config/complementary'; import FilesView from '../drilldown/FilesView'; import TreeMapView from '../drilldown/TreeMapView'; -import { enhanceComponent, isFileType, isViewType, Query, View } from '../utils'; +import { enhanceComponent, isFileType, isViewType, Query } from '../utils'; import Breadcrumbs from './Breadcrumbs'; import MeasureContentHeader from './MeasureContentHeader'; import MeasureHeader from './MeasureHeader'; @@ -51,7 +52,7 @@ interface Props { router: InjectedRouter; selected?: string; updateQuery: (query: Partial) => void; - view: View; + view: MeasurePageView; } interface State { @@ -170,7 +171,7 @@ export default class MeasureContent extends React.PureComponent { }; getComponentRequestParams( - view: View, + view: MeasurePageView, metric: Pick, options: Object = {} ) { @@ -218,7 +219,7 @@ export default class MeasureContent extends React.PureComponent { }); }; - updateView = (view: View) => { + updateView = (view: MeasurePageView) => { this.props.updateQuery({ view }); }; diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureViewSelect.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureViewSelect.tsx index c6860eb3066..43da92b6dcb 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureViewSelect.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureViewSelect.tsx @@ -23,13 +23,14 @@ import ListIcon from '../../../components/icons/ListIcon'; import TreeIcon from '../../../components/icons/TreeIcon'; import TreemapIcon from '../../../components/icons/TreemapIcon'; import { translate } from '../../../helpers/l10n'; -import { hasList, hasTree, hasTreemap, View } from '../utils'; +import { MeasurePageView } from '../../../types/measures'; +import { hasList, hasTree, hasTreemap } from '../utils'; interface Props { className?: string; metric: T.Metric; - handleViewChange: (view: View) => void; - view: View; + handleViewChange: (view: MeasurePageView) => void; + view: MeasurePageView; } export default class MeasureViewSelect extends React.PureComponent { @@ -61,7 +62,7 @@ export default class MeasureViewSelect extends React.PureComponent { }; handleChange = (option: { value: string }) => { - return this.props.handleViewChange(option.value as View); + return this.props.handleViewChange(option.value as MeasurePageView); }; renderOption = (option: { icon: JSX.Element; label: string }) => { diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/App-test.tsx index 9c9ae1d407e..c805df0da81 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/App-test.tsx @@ -21,7 +21,8 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { getMeasuresWithPeriod } from '../../../../api/measures'; import { mockMainBranch, mockPullRequest } from '../../../../helpers/mocks/branch-like'; -import { mockComponent, mockIssue, mockLocation, mockRouter } from '../../../../helpers/testMocks'; +import { mockComponent } from '../../../../helpers/mocks/component'; +import { mockIssue, mockLocation, mockRouter } from '../../../../helpers/testMocks'; import { waitAndUpdate } from '../../../../helpers/testUtils'; import { App } from '../App'; diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureContent-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureContent-test.tsx index d89eb1f0c04..1071d5f1fba 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureContent-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureContent-test.tsx @@ -20,8 +20,9 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { getComponentTree } from '../../../../api/components'; +import { mockComponentMeasure } from '../../../../helpers/mocks/component'; import { scrollToElement } from '../../../../helpers/scrolling'; -import { mockComponentMeasure, mockRouter } from '../../../../helpers/testMocks'; +import { mockRouter } from '../../../../helpers/testMocks'; import { waitAndUpdate } from '../../../../helpers/testUtils'; import MeasureContent from '../MeasureContent'; @@ -30,7 +31,7 @@ jest.mock('../../../../helpers/scrolling', () => ({ })); jest.mock('../../../../api/components', () => { - const { mockComponentMeasure } = jest.requireActual('../../../../helpers/testMocks'); + const { mockComponentMeasure } = jest.requireActual('../../../../helpers/mocks/component'); return { getComponentTree: jest.fn().mockResolvedValue({ paging: { pageIndex: 1, pageSize: 500, total: 2 }, diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureOverview-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureOverview-test.tsx index 77923e3f982..4d368739eb1 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureOverview-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureOverview-test.tsx @@ -23,9 +23,11 @@ import { keyBy } from 'lodash'; import * as React from 'react'; import { getComponentLeaves } from '../../../../api/components'; import { mockBranch } from '../../../../helpers/mocks/branch-like'; -import { mockComponentMeasureEnhanced } from '../../../../helpers/mocks/component'; import { mockComponentMeasure, + mockComponentMeasureEnhanced +} from '../../../../helpers/mocks/component'; +import { mockMeasure, mockMeasureEnhanced, mockMetric, diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx index 161f47f2a34..302bf0bf71c 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx @@ -17,18 +17,34 @@ * 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 { mockMetric } from '../../../../helpers/testMocks'; +import { MetricKey } from '../../../../types/metrics'; import MeasureViewSelect from '../MeasureViewSelect'; -it('should display correctly with treemap option', () => { +it('should render correctly', () => { + expect( + shallowRender({ metric: mockMetric({ key: MetricKey.releasability_rating }) }) + ).toMatchSnapshot('has no list'); expect( - shallow( - {}} - metric={{ type: 'PERCENT' } as T.Metric} - view="tree" - /> - ) - ).toMatchSnapshot(); + shallowRender({ metric: mockMetric({ key: MetricKey.alert_status, type: 'LEVEL' }) }) + ).toMatchSnapshot('has no tree'); + expect(shallowRender({ metric: mockMetric({ type: 'RATING' }) })).toMatchSnapshot( + 'has no treemap' + ); }); + +it('should correctly trigger a selection change', () => { + const handleViewChange = jest.fn(); + const wrapper = shallowRender({ handleViewChange }); + wrapper.instance().handleChange({ value: 'list' }); + expect(handleViewChange).toBeCalledWith('list'); +}); + +function shallowRender(props: Partial = {}) { + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureViewSelect-test.tsx.snap b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureViewSelect-test.tsx.snap index bc440003070..29fe3dbd9eb 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureViewSelect-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureViewSelect-test.tsx.snap @@ -1,6 +1,53 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should display correctly with treemap option 1`] = ` +exports[`should render correctly: has no list 1`] = ` +, + "label": "component_measures.tab.list", + "value": "list", + }, + ] + } + searchable={false} + value="list" + valueRenderer={[Function]} +/> +`; + +exports[`should render correctly: has no treemap 1`] = `