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.

NavBarTabs-test.tsx 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 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 { screen } from '@testing-library/react';
  21. import { renderWithRouter } from '../../helpers/testUtils';
  22. import { FCProps } from '../../types/misc';
  23. import { DisabledTabLink, NavBarTabLink, NavBarTabs } from '../NavBarTabs';
  24. describe('NewNavBarTabs', () => {
  25. it('should render correctly', () => {
  26. setup();
  27. expect(screen.getByRole('list')).toBeInTheDocument();
  28. expect(screen.getByRole('listitem')).toBeInTheDocument();
  29. expect(screen.getByRole('link')).toBeInTheDocument();
  30. expect(screen.getByRole('link')).toHaveTextContent('test');
  31. });
  32. function setup() {
  33. return renderWithRouter(
  34. <NavBarTabs>
  35. <NavBarTabLink text="test" to="/summary/new_code" />
  36. </NavBarTabs>,
  37. );
  38. }
  39. });
  40. describe('NewNavBarTabLink', () => {
  41. it('should not be active when on different url', () => {
  42. setupWithProps();
  43. expect(screen.getByRole('link')).not.toHaveClass('active');
  44. });
  45. it('should be active when on same url', () => {
  46. setupWithProps({ to: '/' });
  47. expect(screen.getByRole('link')).toHaveClass('active');
  48. });
  49. it('should be active when active prop is set regardless of the url', () => {
  50. setupWithProps({ active: true, withChevron: true });
  51. expect(screen.getByRole('link')).toHaveClass('active');
  52. });
  53. it('should not be active when active prop is false regardless of the url', () => {
  54. setupWithProps({ active: false, to: '/' });
  55. expect(screen.getByRole('link')).not.toHaveClass('active');
  56. });
  57. function setupWithProps(props: Partial<FCProps<typeof NavBarTabLink>> = {}) {
  58. return renderWithRouter(<NavBarTabLink text="test" to="/summary/new_code" {...props} />);
  59. }
  60. });
  61. describe('DisabledTabLink', () => {
  62. it('should render correctly', () => {
  63. renderWithRouter(<DisabledTabLink label="label" overlay={<span>Overlay</span>} />);
  64. expect(screen.getByRole('link')).toHaveClass('disabled-link');
  65. });
  66. });