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.

Components-test.tsx 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 { mockBranch } from '../../../../helpers/mocks/branch-like';
  23. import { ComponentQualifier } from '../../../../types/component';
  24. import { Components } from '../Components';
  25. const COMPONENT = {
  26. key: 'foo',
  27. name: 'Foo',
  28. qualifier: ComponentQualifier.Project,
  29. branch: 'develop'
  30. };
  31. const PORTFOLIO = { key: 'bar', name: 'Bar', qualifier: ComponentQualifier.Portfolio };
  32. const METRICS = { coverage: { id: '1', key: 'coverage', type: 'PERCENT', name: 'Coverage' } };
  33. const BRANCH = mockBranch({ name: 'feature' });
  34. it('renders correctly', () => {
  35. expect(
  36. shallow(
  37. <Components
  38. baseComponent={COMPONENT}
  39. components={[COMPONENT]}
  40. metrics={METRICS}
  41. rootComponent={COMPONENT}
  42. />
  43. )
  44. ).toMatchSnapshot();
  45. });
  46. it('renders correctly for a search', () => {
  47. expect(
  48. shallow(<Components components={[COMPONENT]} metrics={{}} rootComponent={COMPONENT} />)
  49. ).toMatchSnapshot();
  50. });
  51. it('renders correctly for leak', () => {
  52. expect(
  53. shallow(
  54. <Components
  55. baseComponent={COMPONENT}
  56. branchLike={BRANCH}
  57. components={[COMPONENT]}
  58. metrics={METRICS}
  59. rootComponent={COMPONENT}
  60. />
  61. )
  62. ).toMatchSnapshot();
  63. });
  64. it('handle no components correctly', () => {
  65. expect(
  66. shallow(
  67. <Components
  68. baseComponent={PORTFOLIO}
  69. components={[]}
  70. metrics={METRICS}
  71. rootComponent={PORTFOLIO}
  72. />
  73. )
  74. .find('ComponentsEmpty')
  75. .exists()
  76. ).toBe(true);
  77. });