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.

WebhookActions-test.tsx 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 { shallow } from 'enzyme';
  21. import * as React from 'react';
  22. import { click } from '../../../../helpers/testUtils';
  23. import WebhookActions from '../WebhookActions';
  24. const webhook = {
  25. key: '1',
  26. name: 'foo',
  27. url: 'http://foo.bar',
  28. hasSecret: false,
  29. };
  30. const delivery = {
  31. at: '12.02.2018',
  32. durationMs: 20,
  33. httpStatus: 200,
  34. id: '2',
  35. success: true,
  36. };
  37. it('should render correctly', () => {
  38. expect(getWrapper()).toMatchSnapshot();
  39. });
  40. it('should display the update webhook form', () => {
  41. const onUpdate = jest.fn(() => Promise.resolve());
  42. const wrapper = getWrapper({ onUpdate });
  43. click(wrapper.find('.js-webhook-update'));
  44. expect(wrapper.find('CreateWebhookForm').exists()).toBe(true);
  45. wrapper.find('CreateWebhookForm').prop<Function>('onDone')({
  46. name: webhook.name,
  47. url: webhook.url,
  48. });
  49. expect(onUpdate).toHaveBeenLastCalledWith({
  50. webhook: webhook.key,
  51. name: webhook.name,
  52. url: webhook.url,
  53. });
  54. });
  55. it('should display the delete webhook form', () => {
  56. const onDelete = jest.fn(() => Promise.resolve());
  57. const wrapper = getWrapper({ onDelete });
  58. click(wrapper.find('.js-webhook-delete'));
  59. expect(wrapper.find('DeleteWebhookForm').exists()).toBe(true);
  60. wrapper.find('DeleteWebhookForm').prop<Function>('onSubmit')();
  61. expect(onDelete).toHaveBeenLastCalledWith(webhook.key);
  62. });
  63. it('should display the deliveries form', () => {
  64. const wrapper = getWrapper({ webhook: { ...webhook, latestDelivery: delivery } });
  65. expect(wrapper).toMatchSnapshot();
  66. click(wrapper.find('.js-webhook-deliveries'));
  67. expect(wrapper.find('DeliveriesForm').exists()).toBe(true);
  68. });
  69. function getWrapper(props = {}) {
  70. return shallow(
  71. <WebhookActions
  72. onDelete={jest.fn(() => Promise.resolve())}
  73. onUpdate={jest.fn(() => Promise.resolve())}
  74. webhook={webhook}
  75. {...props}
  76. />
  77. );
  78. }