mockPullRequest,
mockShortLivingBranch
} from '../../../helpers/testMocks';
+import BranchBaselineSettingModal from '../components/BranchBaselineSettingModal';
import BranchList from '../components/BranchList';
jest.mock('../../../api/newCodePeriod', () => ({
]
});
await waitAndUpdate(wrapper);
- expect(wrapper.state('branches')).toHaveLength(2);
+ expect(wrapper.state().branches).toHaveLength(3);
expect(wrapper).toMatchSnapshot();
});
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',
</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>
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 {
}
sortAndFilterBranches(branchLikes: T.BranchLike[] = []) {
- return sortBranchesAsTree(
- branchLikes.filter(b => isMainBranch(b) || isLongLivingBranch(b))
- ) as T.Branch[];
+ return sortBranches(branchLikes.filter(isBranch));
}
fetchBranches() {
--- /dev/null
+/*
+ * 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'
+ }
+ ]);
+});
*/
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} />;
}
}
--- /dev/null
+/*
+ * 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} />);
+}
--- /dev/null
+// 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 />`;
* 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,
});
});
+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();
* 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;
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;
}