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.

TreeMap-test.tsx 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 { mount } from 'enzyme';
  21. import * as React from 'react';
  22. import { mockComponentMeasureEnhanced } from '../../../helpers/mocks/component';
  23. import TreeMap from '../TreeMap';
  24. import TreeMapRect from '../TreeMapRect';
  25. it('should render correctly', () => {
  26. const items = [
  27. {
  28. key: '1',
  29. size: 10,
  30. color: '#777',
  31. label: 'SonarQube :: Server',
  32. component: mockComponentMeasureEnhanced()
  33. },
  34. {
  35. key: '2',
  36. size: 30,
  37. color: '#777',
  38. label: 'SonarQube :: Web',
  39. component: mockComponentMeasureEnhanced()
  40. },
  41. {
  42. key: '3',
  43. size: 20,
  44. gradient: '#777',
  45. label: 'SonarQube :: Search',
  46. metric: { key: 'coverage', type: 'PERCENT' },
  47. component: mockComponentMeasureEnhanced()
  48. }
  49. ];
  50. const onRectClick = jest.fn();
  51. const chart = mount(
  52. <TreeMap height={100} items={items} onRectangleClick={onRectClick} width={100} />
  53. );
  54. const rects = chart.find(TreeMapRect);
  55. expect(rects).toHaveLength(3);
  56. const event: React.MouseEvent<HTMLAnchorElement> = {
  57. stopPropagation: jest.fn()
  58. } as any;
  59. (rects.first().instance() as TreeMapRect).handleLinkClick(event);
  60. expect(event.stopPropagation).toHaveBeenCalled();
  61. (rects.first().instance() as TreeMapRect).handleRectClick();
  62. expect(onRectClick).toHaveBeenCalledWith(expect.objectContaining({ key: 'foo' }));
  63. });