3 * Copyright (C) 2009-2018 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 import * as React from 'react';
21 import { shallow } from 'enzyme';
22 import ComponentNavBranchesMenu from '../ComponentNavBranchesMenu';
23 import { elementKeydown } from '../../../../../helpers/testUtils';
25 const component = { key: 'component' } as T.Component;
27 it('renders list', () => {
30 <ComponentNavBranchesMenu
35 shortBranch('baz', true),
39 currentBranchLike={mainBranch()}
46 it('searches', () => {
47 const wrapper = shallow(
48 <ComponentNavBranchesMenu
52 shortBranch('foobar'),
57 currentBranchLike={mainBranch()}
61 wrapper.setState({ query: 'bar' });
62 expect(wrapper).toMatchSnapshot();
65 it('selects next & previous', () => {
66 const wrapper = shallow<ComponentNavBranchesMenu>(
67 <ComponentNavBranchesMenu
68 branchLikes={[mainBranch(), shortBranch('foo'), shortBranch('foobar'), longBranch('bar')]}
70 currentBranchLike={mainBranch()}
74 elementKeydown(wrapper.find('SearchBox'), 40);
76 expect(wrapper.state().selected).toEqual(shortBranch('foo'));
77 elementKeydown(wrapper.find('SearchBox'), 40);
79 expect(wrapper.state().selected).toEqual(shortBranch('foobar'));
80 elementKeydown(wrapper.find('SearchBox'), 38);
82 expect(wrapper.state().selected).toEqual(shortBranch('foo'));
85 function mainBranch(): T.MainBranch {
86 return { isMain: true, name: 'master' };
89 function shortBranch(name: string, isOrphan?: true): T.ShortLivingBranch {
93 mergeBranch: 'master',
95 status: { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 },
100 function longBranch(name: string): T.LongLivingBranch {
101 return { isMain: false, name, type: 'LONG' };
104 function pullRequest(title: string): T.PullRequest {
109 status: { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 },