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.

AlmTabRenderer-test.tsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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 {
  23. mockAzureBindingDefinition,
  24. mockBitbucketCloudBindingDefinition,
  25. mockGithubBindingDefinition
  26. } from '../../../../../helpers/mocks/alm-settings';
  27. import { AlmKeys } from '../../../../../types/alm-settings';
  28. import AlmTabRenderer, { AlmTabRendererProps } from '../AlmTabRenderer';
  29. it('should render correctly for multi-ALM binding', () => {
  30. expect(shallowRenderAzure({ loadingAlmDefinitions: true })).toMatchSnapshot(
  31. 'loading ALM definitions'
  32. );
  33. expect(shallowRenderAzure({ loadingProjectCount: true })).toMatchSnapshot(
  34. 'loading project count'
  35. );
  36. expect(shallowRenderAzure({})).toMatchSnapshot('loaded');
  37. expect(shallowRenderAzure({ editedDefinition: mockAzureBindingDefinition() })).toMatchSnapshot(
  38. 'editing a definition'
  39. );
  40. });
  41. it('should render correctly for single-ALM binding', () => {
  42. expect(
  43. shallowRenderAzure({ loadingAlmDefinitions: true, multipleAlmEnabled: false })
  44. ).toMatchSnapshot();
  45. expect(shallowRenderAzure({ multipleAlmEnabled: false })).toMatchSnapshot();
  46. expect(
  47. shallowRenderAzure({ definitions: [mockAzureBindingDefinition()], multipleAlmEnabled: false })
  48. ).toMatchSnapshot();
  49. });
  50. it('should render correctly with validation', () => {
  51. const githubProps = {
  52. alm: AlmKeys.GitHub,
  53. definitions: [mockGithubBindingDefinition()]
  54. };
  55. expect(shallowRender(githubProps)).toMatchSnapshot('default');
  56. expect(shallowRender({ ...githubProps, definitions: [] })).toMatchSnapshot('empty');
  57. expect(
  58. shallowRender({
  59. ...githubProps,
  60. editedDefinition: mockGithubBindingDefinition()
  61. })
  62. ).toMatchSnapshot('create a second');
  63. expect(
  64. shallowRender({
  65. ...githubProps,
  66. definitions: [],
  67. editedDefinition: mockGithubBindingDefinition()
  68. })
  69. ).toMatchSnapshot('create a first');
  70. expect(
  71. shallowRender({
  72. almTab: AlmKeys.BitbucketServer, // BitbucketServer will be passed for both Bitbucket variants.
  73. definitions: [mockBitbucketCloudBindingDefinition()]
  74. })
  75. ).toMatchSnapshot('pass the correct key for bitbucket cloud');
  76. });
  77. function shallowRenderAzure(props: Partial<AlmTabRendererProps>) {
  78. return shallowRender({
  79. definitions: [mockAzureBindingDefinition()],
  80. ...props
  81. });
  82. }
  83. function shallowRender(props: Partial<AlmTabRendererProps> = {}) {
  84. return shallow(
  85. <AlmTabRenderer
  86. almTab={AlmKeys.Azure}
  87. branchesEnabled={true}
  88. definitions={[]}
  89. definitionStatus={{}}
  90. loadingAlmDefinitions={false}
  91. loadingProjectCount={false}
  92. multipleAlmEnabled={true}
  93. onCancel={jest.fn()}
  94. onCheck={jest.fn()}
  95. onCreate={jest.fn()}
  96. onDelete={jest.fn()}
  97. onEdit={jest.fn()}
  98. afterSubmit={jest.fn()}
  99. {...props}
  100. />
  101. );
  102. }