You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BranchLikeNavigation-test.tsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  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.
  10. *
  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.
  15. *
  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.
  19. */
  20. import { shallow } from 'enzyme';
  21. import * as React from 'react';
  22. import Toggler from 'sonar-ui-common/components/controls/Toggler';
  23. import { click } from 'sonar-ui-common/helpers/testUtils';
  24. import { mockSetOfBranchAndPullRequest } from '../../../../../../helpers/mocks/branch-like';
  25. import { mockAppState, mockComponent } from '../../../../../../helpers/testMocks';
  26. import { BranchLikeNavigation, BranchLikeNavigationProps } from '../BranchLikeNavigation';
  27. it('should render correctly', () => {
  28. const wrapper = shallowRender();
  29. expect(wrapper).toMatchSnapshot();
  30. });
  31. it('should render the menu trigger if branches are enabled', () => {
  32. const wrapper = shallowRender({ appState: mockAppState({ branchesEnabled: true }) });
  33. expect(wrapper).toMatchSnapshot();
  34. });
  35. it('should properly toggle menu opening when clicking the anchor', () => {
  36. const wrapper = shallowRender({ appState: mockAppState({ branchesEnabled: true }) });
  37. expect(wrapper.find(Toggler).props().open).toBe(false);
  38. click(wrapper.find('a'));
  39. expect(wrapper.find(Toggler).props().open).toBe(true);
  40. click(wrapper.find('a'));
  41. expect(wrapper.find(Toggler).props().open).toBe(false);
  42. });
  43. it('should properly close menu when toggler asks for', () => {
  44. const wrapper = shallowRender({ appState: mockAppState({ branchesEnabled: true }) });
  45. expect(wrapper.find(Toggler).props().open).toBe(false);
  46. click(wrapper.find('a'));
  47. expect(wrapper.find(Toggler).props().open).toBe(true);
  48. wrapper
  49. .find(Toggler)
  50. .props()
  51. .onRequestClose();
  52. expect(wrapper.find(Toggler).props().open).toBe(false);
  53. });
  54. function shallowRender(props?: Partial<BranchLikeNavigationProps>) {
  55. const branchLikes = mockSetOfBranchAndPullRequest();
  56. return shallow(
  57. <BranchLikeNavigation
  58. appState={mockAppState()}
  59. branchLikes={branchLikes}
  60. component={mockComponent()}
  61. currentBranchLike={branchLikes[0]}
  62. {...props}
  63. />
  64. );
  65. }