]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12674 Setting the new code period should be available for all types of branches
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Tue, 5 Nov 2019 09:41:23 +0000 (10:41 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 9 Dec 2019 19:46:16 +0000 (20:46 +0100)
server/sonar-web/src/main/js/apps/projectBaseline/__tests__/BranchList-test.tsx
server/sonar-web/src/main/js/apps/projectBaseline/__tests__/__snapshots__/BranchList-test.tsx.snap
server/sonar-web/src/main/js/apps/projectBaseline/components/BranchList.tsx
server/sonar-web/src/main/js/apps/settings/store/__tests__/actions-test.ts [new file with mode: 0644]
server/sonar-web/src/main/js/components/icons-components/BranchIcon.tsx
server/sonar-web/src/main/js/components/icons-components/__tests__/BranchIcon-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/components/icons-components/__tests__/__snapshots__/BranchIcon-test.tsx.snap [new file with mode: 0644]
server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts
server/sonar-web/src/main/js/helpers/branches.ts

index 0c34ed35b6b25770a2783135692378a5816a07e1..c74164771e5a1c7ac764baf890c38083903167aa 100644 (file)
@@ -28,6 +28,7 @@ import {
   mockPullRequest,
   mockShortLivingBranch
 } from '../../../helpers/testMocks';
+import BranchBaselineSettingModal from '../components/BranchBaselineSettingModal';
 import BranchList from '../components/BranchList';
 
 jest.mock('../../../api/newCodePeriod', () => ({
@@ -55,7 +56,7 @@ it('should render correctly', async () => {
     ]
   });
   await waitAndUpdate(wrapper);
-  expect(wrapper.state('branches')).toHaveLength(2);
+  expect(wrapper.state().branches).toHaveLength(3);
   expect(wrapper).toMatchSnapshot();
 });
 
@@ -78,14 +79,14 @@ it('should toggle popup', async () => {
 
   await waitAndUpdate(wrapper);
 
-  const nodes = wrapper.find('BranchBaselineSettingModal');
+  const nodes = wrapper.find(BranchBaselineSettingModal);
   expect(nodes).toHaveLength(1);
-  expect(nodes.first().prop('branch')).toEqual(mockMainBranch());
+  expect(nodes.first().props().branch).toEqual(mockMainBranch());
 
   wrapper.instance().closeEditModal('master', { type: 'NUMBER_OF_DAYS', value: '23' });
 
   expect(wrapper.find('BranchBaselineSettingModal')).toHaveLength(0);
-  expect(wrapper.state('branches').find(b => b.name === 'master')).toEqual({
+  expect(wrapper.state().branches.find(b => b.name === 'master')).toEqual({
     analysisDate: '2018-01-01',
     isMain: true,
     name: 'master',
index 12ab71b6a459b10032e0fdaf4de8e591baa2ada4..df73eeeaa98f5ddc9e069ca8890b91ca7817cc7b 100644 (file)
@@ -109,6 +109,43 @@ exports[`should render correctly 1`] = `
           </ActionsDropdown>
         </td>
       </tr>
+      <tr
+        key="feature/foo"
+      >
+        <td
+          className="nowrap"
+        >
+          <BranchIcon
+            branchLike={
+              Object {
+                "analysisDate": "2018-01-01",
+                "isMain": false,
+                "mergeBranch": "master",
+                "name": "feature/foo",
+                "type": "SHORT",
+              }
+            }
+            className="little-spacer-right"
+          />
+          feature/foo
+        </td>
+        <td
+          className="huge-spacer-right nowrap"
+        >
+          branch_list.default_setting
+        </td>
+        <td
+          className="text-right"
+        >
+          <ActionsDropdown>
+            <ActionsDropdownItem
+              onClick={[Function]}
+            >
+              edit
+            </ActionsDropdownItem>
+          </ActionsDropdown>
+        </td>
+      </tr>
     </tbody>
   </table>
 </Fragment>
index d907968a40770905c52681655fb00521047bee23..9aa7ffdf8b9115103e55e3e8918159701f7776a3 100644 (file)
@@ -26,7 +26,7 @@ import { translate } from 'sonar-ui-common/helpers/l10n';
 import { listBranchesNewCodePeriod, resetNewCodePeriod } from '../../../api/newCodePeriod';
 import BranchIcon from '../../../components/icons-components/BranchIcon';
 import DateTimeFormatter from '../../../components/intl/DateTimeFormatter';
-import { isLongLivingBranch, isMainBranch, sortBranchesAsTree } from '../../../helpers/branches';
+import { isBranch, sortBranches } from '../../../helpers/branches';
 import BranchBaselineSettingModal from './BranchBaselineSettingModal';
 
 interface Props {
@@ -58,9 +58,7 @@ export default class BranchList extends React.PureComponent<Props, State> {
   }
 
   sortAndFilterBranches(branchLikes: T.BranchLike[] = []) {
-    return sortBranchesAsTree(
-      branchLikes.filter(b => isMainBranch(b) || isLongLivingBranch(b))
-    ) as T.Branch[];
+    return sortBranches(branchLikes.filter(isBranch));
   }
 
   fetchBranches() {
diff --git a/server/sonar-web/src/main/js/apps/settings/store/__tests__/actions-test.ts b/server/sonar-web/src/main/js/apps/settings/store/__tests__/actions-test.ts
new file mode 100644 (file)
index 0000000..193a031
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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 { fetchSettings } from '../actions';
+import { receiveDefinitions } from '../definitions';
+
+jest.mock('../../../../api/settings', () => ({
+  getDefinitions: jest.fn().mockResolvedValue([
+    {
+      key: 'SETTINGS_1_KEY',
+      type: 'SETTINGS_1_TYPE'
+    },
+    {
+      key: 'SETTINGS_2_KEY',
+      type: 'LICENSE'
+    }
+  ])
+}));
+
+jest.mock('../definitions', () => ({
+  receiveDefinitions: jest.fn()
+}));
+
+it('#fetchSettings should filter LICENSE type settings', async () => {
+  const dispatch = jest.fn();
+
+  await fetchSettings()(dispatch);
+
+  expect(receiveDefinitions).toHaveBeenCalledWith([
+    {
+      key: 'SETTINGS_1_KEY',
+      type: 'SETTINGS_1_TYPE'
+    }
+  ]);
+});
index 7f7794e73c8c1582b17dba9eaea10e9e8df0d7d0..200afa5a85adad194b37473ffadd4f72b55a99f0 100644 (file)
  */
 import * as React from 'react';
 import { IconProps } from 'sonar-ui-common/components/icons/Icon';
-import LongLivingBranchIcon from 'sonar-ui-common/components/icons/LongLivingBranchIcon';
 import PullRequestIcon from 'sonar-ui-common/components/icons/PullRequestIcon';
 import ShortLivingBranchIcon from 'sonar-ui-common/components/icons/ShortLivingBranchIcon';
-import { isPullRequest, isShortLivingBranch } from '../../helpers/branches';
+import { isPullRequest } from '../../helpers/branches';
 
-interface Props extends IconProps {
+export interface BranchIconProps extends IconProps {
   branchLike: T.BranchLike;
 }
 
-export default function BranchIcon({ branchLike, ...props }: Props) {
+export default function BranchIcon({ branchLike, ...props }: BranchIconProps) {
   if (isPullRequest(branchLike)) {
     return <PullRequestIcon {...props} />;
-  } else if (isShortLivingBranch(branchLike)) {
-    return <ShortLivingBranchIcon {...props} />;
   } else {
-    return <LongLivingBranchIcon {...props} />;
+    return <ShortLivingBranchIcon {...props} />;
   }
 }
diff --git a/server/sonar-web/src/main/js/components/icons-components/__tests__/BranchIcon-test.tsx b/server/sonar-web/src/main/js/components/icons-components/__tests__/BranchIcon-test.tsx
new file mode 100644 (file)
index 0000000..9fad6aa
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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 {
+  mockLongLivingBranch,
+  mockPullRequest,
+  mockShortLivingBranch
+} from '../../../helpers/testMocks';
+import BranchIcon, { BranchIconProps } from '../BranchIcon';
+
+it('should render short living branch icon for short living branch', () => {
+  const wrapper = shallowRender({ branchLike: mockShortLivingBranch() });
+  expect(wrapper).toMatchSnapshot();
+});
+
+it('should render short living branch icon for long living branch', () => {
+  const wrapper = shallowRender({ branchLike: mockLongLivingBranch() });
+  expect(wrapper).toMatchSnapshot();
+});
+
+it('should render pull request icon correctly', () => {
+  const wrapper = shallowRender({ branchLike: mockPullRequest() });
+  expect(wrapper).toMatchSnapshot();
+});
+
+function shallowRender(props: BranchIconProps) {
+  return shallow(<BranchIcon {...props} />);
+}
diff --git a/server/sonar-web/src/main/js/components/icons-components/__tests__/__snapshots__/BranchIcon-test.tsx.snap b/server/sonar-web/src/main/js/components/icons-components/__tests__/__snapshots__/BranchIcon-test.tsx.snap
new file mode 100644 (file)
index 0000000..abc1082
--- /dev/null
@@ -0,0 +1,7 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render pull request icon correctly 1`] = `<PullRequestIcon />`;
+
+exports[`should render short living branch icon for long living branch 1`] = `<ShortLivingBranchIcon />`;
+
+exports[`should render short living branch icon for short living branch 1`] = `<ShortLivingBranchIcon />`;
index 34f7dbf42a4e040e025063d4b65ae0c281506e85..a818691437124b2409c6ae24975b321d5f6c75b4 100644 (file)
@@ -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 { isSameBranchLike, sortBranchesAsTree } from '../branches';
+import { isSameBranchLike, sortBranches, sortBranchesAsTree } from '../branches';
 import {
   mockLongLivingBranch,
   mockMainBranch,
@@ -62,6 +62,31 @@ describe('#sortBranchesAsTree', () => {
   });
 });
 
+describe('#sortBranches', () => {
+  it('should sort branches correctly', () => {
+    const main = mockMainBranch();
+    const shortFoo = mockShortLivingBranch({ name: 'shortFoo', mergeBranch: 'master' });
+    const shortBar = mockShortLivingBranch({ name: 'shortBar', mergeBranch: 'longBaz' });
+    const shortPre = mockShortLivingBranch({ name: 'shortPre', mergeBranch: 'shortFoo' });
+    const longBaz = mockLongLivingBranch({ name: 'longBaz' });
+    const longQux = mockLongLivingBranch({ name: 'longQux' });
+    const longQwe = mockLongLivingBranch({ name: 'longQwe' });
+    const branchList = [shortFoo, longBaz, shortPre, longQux, main, longQwe, shortBar];
+
+    const sortedBrancList = sortBranches(branchList);
+
+    expect(sortedBrancList).toEqual([
+      main,
+      longBaz,
+      longQux,
+      longQwe,
+      shortBar,
+      shortFoo,
+      shortPre
+    ]);
+  });
+});
+
 describe('#isSameBranchLike', () => {
   it('compares different kinds', () => {
     const main = mockMainBranch();
index c032c1ccde09bf8bf9bc97d8d44af692ba59d6aa..3cac030ccba7edad94607f08ffeb4034d2acbbd9 100644 (file)
@@ -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 { sortBy } from 'lodash';
+import { orderBy, sortBy } from 'lodash';
 
 export function isBranch(branchLike?: T.BranchLike): branchLike is T.Branch {
   return branchLike !== undefined && (branchLike as T.Branch).isMain !== undefined;
@@ -41,6 +41,10 @@ export function isMainBranch(branchLike?: T.BranchLike): branchLike is T.MainBra
   return isBranch(branchLike) && branchLike.isMain;
 }
 
+export function sortBranches(branches: T.Branch[]) {
+  return orderBy(branches, [b => b.isMain, b => b.name], ['desc', 'asc']);
+}
+
 export function isPullRequest(branchLike?: T.BranchLike): branchLike is T.PullRequest {
   return branchLike !== undefined && (branchLike as T.PullRequest).key !== undefined;
 }