]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14516 Remove hardcoded usage of 'master' from webapp
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Mon, 1 Mar 2021 14:32:34 +0000 (15:32 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 3 Mar 2021 20:12:51 +0000 (20:12 +0000)
server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx
server/sonar-web/src/main/js/apps/projectBaseline/components/ProjectBaselineSelector.tsx
server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx
server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/ProjectBaselineSelector-test.tsx
server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/__snapshots__/App-test.tsx.snap

index 32a1c54100d255901727e1dfa1c1b7a08d6a4127..ed9efc5b52166e9a7a59fd5513ae1c85f6216c59 100644 (file)
@@ -34,6 +34,7 @@ import BranchList from './BranchList';
 import ProjectBaselineSelector from './ProjectBaselineSelector';
 
 interface Props {
+  branchLike: Branch;
   branchLikes: BranchLike[];
   branchesEnabled?: boolean;
   canAdmin?: boolean;
@@ -120,13 +121,15 @@ export default class App extends React.PureComponent<Props, State> {
   }
 
   fetchLeakPeriodSetting() {
+    const { branchLike, branchesEnabled, component } = this.props;
+
     this.setState({ loading: true });
 
     Promise.all([
       getNewCodePeriod(),
       getNewCodePeriod({
-        branch: !this.props.branchesEnabled ? 'master' : undefined,
-        project: this.props.component.key
+        branch: branchesEnabled ? undefined : branchLike.name,
+        project: component.key
       })
     ]).then(
       ([generalSetting, setting]) => {
@@ -226,7 +229,7 @@ export default class App extends React.PureComponent<Props, State> {
   };
 
   render() {
-    const { branchesEnabled, canAdmin, component } = this.props;
+    const { branchesEnabled, canAdmin, component, branchLike } = this.props;
     const {
       analysis,
       branchList,
@@ -256,6 +259,7 @@ export default class App extends React.PureComponent<Props, State> {
               {generalSetting && overrideGeneralSetting !== undefined && (
                 <ProjectBaselineSelector
                   analysis={analysis}
+                  branch={branchLike}
                   branchList={branchList}
                   branchesEnabled={branchesEnabled}
                   component={component.key}
index 574ce1a048d1a410a39929a8863314ab46ec2aee..4d133b25ee17662ba13f66b0645065a33c6703e1 100644 (file)
@@ -34,6 +34,7 @@ import BranchAnalysisList from './BranchAnalysisList';
 
 export interface ProjectBaselineSelectorProps {
   analysis?: string;
+  branch: Branch;
   branchList: Branch[];
   branchesEnabled?: boolean;
   component: string;
@@ -82,6 +83,7 @@ function branchToOption(b: Branch) {
 export default function ProjectBaselineSelector(props: ProjectBaselineSelectorProps) {
   const {
     analysis,
+    branch,
     branchList,
     branchesEnabled,
     component,
@@ -163,7 +165,7 @@ export default function ProjectBaselineSelector(props: ProjectBaselineSelectorPr
         {selected === 'SPECIFIC_ANALYSIS' && (
           <BranchAnalysisList
             analysis={analysis || ''}
-            branch="master"
+            branch={branch.name}
             component={component}
             onSelectAnalysis={props.onSelectAnalysis}
           />
index f4c3fd6bc94d66b4fe05cb54ffad066fd90cc125..65cd8e22f0833190929cf9d72eeb272a21014799 100644 (file)
@@ -35,8 +35,14 @@ jest.mock('../../../../api/newCodePeriod', () => ({
   setNewCodePeriod: jest.fn().mockResolvedValue({})
 }));
 
-it('should render correctly', () => {
-  expect(shallowRender()).toMatchSnapshot();
+it('should render correctly', async () => {
+  let wrapper = shallowRender();
+  await waitAndUpdate(wrapper);
+  expect(wrapper).toMatchSnapshot();
+
+  wrapper = shallowRender({ branchesEnabled: false });
+  await waitAndUpdate(wrapper);
+  expect(wrapper).toMatchSnapshot('without branch support');
 });
 
 it('should initialize correctly', async () => {
@@ -100,6 +106,7 @@ it('should handle errors gracefully', async () => {
 function shallowRender(props: Partial<App['props']> = {}) {
   return shallow<App>(
     <App
+      branchLike={mockBranch()}
       branchLikes={[mockMainBranch()]}
       branchesEnabled={true}
       canAdmin={true}
index 0e1cf612c5a9762cd77af4d7eeb8931a65827c64..294b63939ee9bf4e4869098d906f94c93df27482 100644 (file)
@@ -19,7 +19,7 @@
  */
 import { shallow } from 'enzyme';
 import * as React from 'react';
-import { mockMainBranch } from '../../../../helpers/mocks/branch-like';
+import { mockBranch, mockMainBranch } from '../../../../helpers/mocks/branch-like';
 import ProjectBaselineSelector, { ProjectBaselineSelectorProps } from '../ProjectBaselineSelector';
 
 it('should render correctly', () => {
@@ -105,6 +105,7 @@ it('should disable the save button when date is invalid', () => {
 function shallowRender(props: Partial<ProjectBaselineSelectorProps> = {}) {
   return shallow(
     <ProjectBaselineSelector
+      branch={mockBranch()}
       branchList={[mockMainBranch()]}
       branchesEnabled={true}
       component=""
index 7b76b1ebb90016e2d8a33017e08a203a74d0c08e..e642a0c6573118e572d415404bc90a00082722f7 100644 (file)
@@ -11,7 +11,186 @@ exports[`should render correctly 1`] = `
     <AppHeader
       canAdmin={true}
     />
-    <DeferredSpinner />
+    <div
+      className="panel-white project-baseline"
+    >
+      <h2>
+        project_baseline.default_setting
+      </h2>
+      <ProjectBaselineSelector
+        analysis=""
+        branch={
+          Object {
+            "analysisDate": "2018-01-01",
+            "excludedFromPurge": true,
+            "isMain": false,
+            "name": "branch-6.7",
+          }
+        }
+        branchList={
+          Array [
+            Object {
+              "analysisDate": "2018-01-01",
+              "excludedFromPurge": true,
+              "isMain": true,
+              "name": "master",
+            },
+          ]
+        }
+        branchesEnabled={true}
+        component="my-project"
+        currentSetting="PREVIOUS_VERSION"
+        days="30"
+        generalSetting={
+          Object {
+            "type": "PREVIOUS_VERSION",
+          }
+        }
+        onCancel={[Function]}
+        onSelectAnalysis={[Function]}
+        onSelectDays={[Function]}
+        onSelectReferenceBranch={[Function]}
+        onSelectSetting={[Function]}
+        onSubmit={[Function]}
+        onToggleSpecificSetting={[Function]}
+        overrideGeneralSetting={true}
+        referenceBranch="master"
+        saving={false}
+        selected="PREVIOUS_VERSION"
+      />
+      <div
+        className="spacer-top invisible"
+      >
+        <span
+          className="text-success"
+        >
+          <AlertSuccessIcon
+            className="spacer-right"
+          />
+          settings.state.saved
+        </span>
+      </div>
+      <div
+        className="huge-spacer-top branch-baseline-selector"
+      >
+        <hr />
+        <h2>
+          project_baseline.configure_branches
+        </h2>
+        <BranchList
+          branchList={
+            Array [
+              Object {
+                "analysisDate": "2018-01-01",
+                "excludedFromPurge": true,
+                "isMain": true,
+                "name": "master",
+              },
+            ]
+          }
+          component={
+            Object {
+              "breadcrumbs": Array [],
+              "key": "my-project",
+              "name": "MyProject",
+              "qualifier": "TRK",
+              "qualityGate": Object {
+                "isDefault": true,
+                "key": "30",
+                "name": "Sonar way",
+              },
+              "qualityProfiles": Array [
+                Object {
+                  "deleted": false,
+                  "key": "my-qp",
+                  "language": "ts",
+                  "name": "Sonar way",
+                },
+              ],
+              "tags": Array [],
+            }
+          }
+          inheritedSetting={
+            Object {
+              "type": "PREVIOUS_VERSION",
+              "value": undefined,
+            }
+          }
+        />
+      </div>
+    </div>
+  </div>
+</Fragment>
+`;
+
+exports[`should render correctly: without branch support 1`] = `
+<Fragment>
+  <Suggestions
+    suggestions="project_baseline"
+  />
+  <div
+    className="page page-limited"
+  >
+    <AppHeader
+      canAdmin={true}
+    />
+    <div
+      className="panel-white project-baseline"
+    >
+      <ProjectBaselineSelector
+        analysis=""
+        branch={
+          Object {
+            "analysisDate": "2018-01-01",
+            "excludedFromPurge": true,
+            "isMain": false,
+            "name": "branch-6.7",
+          }
+        }
+        branchList={
+          Array [
+            Object {
+              "analysisDate": "2018-01-01",
+              "excludedFromPurge": true,
+              "isMain": true,
+              "name": "master",
+            },
+          ]
+        }
+        branchesEnabled={false}
+        component="my-project"
+        currentSetting="PREVIOUS_VERSION"
+        days="30"
+        generalSetting={
+          Object {
+            "type": "PREVIOUS_VERSION",
+          }
+        }
+        onCancel={[Function]}
+        onSelectAnalysis={[Function]}
+        onSelectDays={[Function]}
+        onSelectReferenceBranch={[Function]}
+        onSelectSetting={[Function]}
+        onSubmit={[Function]}
+        onToggleSpecificSetting={[Function]}
+        overrideGeneralSetting={true}
+        referenceBranch="master"
+        saving={false}
+        selected="PREVIOUS_VERSION"
+      />
+      <div
+        className="spacer-top invisible"
+      >
+        <span
+          className="text-success"
+        >
+          <AlertSuccessIcon
+            className="spacer-right"
+          />
+          settings.state.saved
+        </span>
+      </div>
+    </div>
   </div>
 </Fragment>
 `;