3 * Copyright (C) 2009-2022 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 { shallow } from 'enzyme';
21 import * as React from 'react';
22 import { ButtonPlain } from '../../../../../../components/controls/buttons';
23 import Toggler from '../../../../../../components/controls/Toggler';
24 import { mockSetOfBranchAndPullRequest } from '../../../../../../helpers/mocks/branch-like';
25 import { mockComponent } from '../../../../../../helpers/mocks/component';
26 import { mockAppState } from '../../../../../../helpers/testMocks';
27 import { click } from '../../../../../../helpers/testUtils';
28 import { BranchLikeNavigation, BranchLikeNavigationProps } from '../BranchLikeNavigation';
30 it('should render correctly', () => {
31 const wrapper = shallowRender();
32 expect(wrapper).toMatchSnapshot();
35 it('should render the menu trigger if branches are enabled', () => {
36 const wrapper = shallowRender({ appState: mockAppState({ branchesEnabled: true }) });
37 expect(wrapper).toMatchSnapshot();
40 it('should properly toggle menu opening when clicking the anchor', () => {
41 const wrapper = shallowRender({ appState: mockAppState({ branchesEnabled: true }) });
42 expect(wrapper.find(Toggler).props().open).toBe(false);
44 click(wrapper.find(ButtonPlain));
45 expect(wrapper.find(Toggler).props().open).toBe(true);
47 click(wrapper.find(ButtonPlain));
48 expect(wrapper.find(Toggler).props().open).toBe(false);
51 it('should properly close menu when toggler asks for', () => {
52 const wrapper = shallowRender({ appState: mockAppState({ branchesEnabled: true }) });
53 expect(wrapper.find(Toggler).props().open).toBe(false);
55 click(wrapper.find(ButtonPlain));
56 expect(wrapper.find(Toggler).props().open).toBe(true);
62 expect(wrapper.find(Toggler).props().open).toBe(false);
65 function shallowRender(props?: Partial<BranchLikeNavigationProps>) {
66 const branchLikes = mockSetOfBranchAndPullRequest();
70 appState={mockAppState()}
71 branchLikes={branchLikes}
72 component={mockComponent()}
73 currentBranchLike={branchLikes[0]}