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.

AlmTab-test.tsx 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 { mockAzureBindingDefinition } from '../../../../../helpers/mocks/alm-settings';
  23. import { waitAndUpdate } from '../../../../../helpers/testUtils';
  24. import { AlmKeys } from '../../../../../types/alm-settings';
  25. import AlmTab from '../AlmTab';
  26. it('should render correctly', () => {
  27. expect(shallowRender()).toMatchSnapshot();
  28. });
  29. it('should handle cancel', async () => {
  30. const wrapper = shallowRender();
  31. wrapper.setState({
  32. editedDefinition: mockAzureBindingDefinition()
  33. });
  34. wrapper.instance().handleCancel();
  35. await waitAndUpdate(wrapper);
  36. expect(wrapper.state().editedDefinition).toBeUndefined();
  37. });
  38. it('should handle edit', async () => {
  39. const config = mockAzureBindingDefinition();
  40. const wrapper = shallowRender({ definitions: [config] });
  41. wrapper.instance().handleEdit(config.key);
  42. await waitAndUpdate(wrapper);
  43. expect(wrapper.state().editedDefinition).toEqual(config);
  44. });
  45. it('should handle create', async () => {
  46. const wrapper = shallowRender();
  47. wrapper.instance().handleCreate();
  48. await waitAndUpdate(wrapper);
  49. expect(wrapper.state().editedDefinition).toBeUndefined();
  50. });
  51. it('should handle afterSubmit', async () => {
  52. const onUpdateDefinitions = jest.fn();
  53. const onCheck = jest.fn();
  54. const binding = mockAzureBindingDefinition();
  55. const wrapper = shallowRender({ onUpdateDefinitions, onCheck });
  56. wrapper.instance().handleAfterSubmit(binding);
  57. await waitAndUpdate(wrapper);
  58. expect(wrapper.state().editedDefinition).toBeUndefined();
  59. expect(onUpdateDefinitions).toHaveBeenCalled();
  60. expect(onCheck).toHaveBeenCalledWith(binding.key);
  61. });
  62. function shallowRender(props: Partial<AlmTab['props']> = {}) {
  63. return shallow<AlmTab>(
  64. <AlmTab
  65. almTab={AlmKeys.Azure}
  66. branchesEnabled={true}
  67. definitions={[mockAzureBindingDefinition()]}
  68. definitionStatus={{}}
  69. loadingAlmDefinitions={false}
  70. loadingProjectCount={false}
  71. multipleAlmEnabled={true}
  72. onCheck={jest.fn()}
  73. onDelete={jest.fn()}
  74. onUpdateDefinitions={jest.fn()}
  75. {...props}
  76. />
  77. );
  78. }