diff options
author | Philippe Perrin <philippe.perrin@sonarsource.com> | 2019-11-05 10:41:23 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-12-09 20:46:16 +0100 |
commit | 6afac55982884880fc9ee29fd5b27162336048d8 (patch) | |
tree | 1d5aff086a432750e0da0fa0c4b7e925ebb50e32 /server/sonar-web/src | |
parent | 502c335e49d50080e5e126a15f6928e335cdbb9a (diff) | |
download | sonarqube-6afac55982884880fc9ee29fd5b27162336048d8.tar.gz sonarqube-6afac55982884880fc9ee29fd5b27162336048d8.zip |
SONAR-12674 Setting the new code period should be available for all types of branches
Diffstat (limited to 'server/sonar-web/src')
9 files changed, 185 insertions, 17 deletions
diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/__tests__/BranchList-test.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/__tests__/BranchList-test.tsx index 0c34ed35b6b..c74164771e5 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/__tests__/BranchList-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/__tests__/BranchList-test.tsx @@ -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', diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/__tests__/__snapshots__/BranchList-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectBaseline/__tests__/__snapshots__/BranchList-test.tsx.snap index 12ab71b6a45..df73eeeaa98 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/__tests__/__snapshots__/BranchList-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectBaseline/__tests__/__snapshots__/BranchList-test.tsx.snap @@ -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> diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchList.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchList.tsx index d907968a407..9aa7ffdf8b9 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchList.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/BranchList.tsx @@ -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 index 00000000000..193a0310631 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/store/__tests__/actions-test.ts @@ -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' + } + ]); +}); diff --git a/server/sonar-web/src/main/js/components/icons-components/BranchIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/BranchIcon.tsx index 7f7794e73c8..200afa5a85a 100644 --- a/server/sonar-web/src/main/js/components/icons-components/BranchIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/BranchIcon.tsx @@ -19,21 +19,18 @@ */ 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 index 00000000000..9fad6aad693 --- /dev/null +++ b/server/sonar-web/src/main/js/components/icons-components/__tests__/BranchIcon-test.tsx @@ -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 index 00000000000..abc10820cf4 --- /dev/null +++ b/server/sonar-web/src/main/js/components/icons-components/__tests__/__snapshots__/BranchIcon-test.tsx.snap @@ -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 />`; diff --git a/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts index 34f7dbf42a4..a8186914371 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/branches-test.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 { 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(); diff --git a/server/sonar-web/src/main/js/helpers/branches.ts b/server/sonar-web/src/main/js/helpers/branches.ts index c032c1ccde0..3cac030ccba 100644 --- a/server/sonar-web/src/main/js/helpers/branches.ts +++ b/server/sonar-web/src/main/js/helpers/branches.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 { 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; } |