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.

DeliveriesForm-test.tsx 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 { searchDeliveries } from '../../../../api/webhooks';
  23. import DeliveriesForm from '../DeliveriesForm';
  24. jest.mock('../../../../api/webhooks', () => ({
  25. searchDeliveries: jest.fn(() =>
  26. Promise.resolve({
  27. deliveries: [
  28. {
  29. at: '12.02.2018',
  30. durationMs: 20,
  31. httpStatus: 200,
  32. id: '2',
  33. success: true,
  34. },
  35. {
  36. at: '11.02.2018',
  37. durationMs: 122,
  38. httpStatus: 500,
  39. id: '1',
  40. success: false,
  41. },
  42. ],
  43. paging: {
  44. pageIndex: 1,
  45. pageSize: 10,
  46. total: 15,
  47. },
  48. })
  49. ),
  50. }));
  51. const webhook = { key: '1', name: 'foo', url: 'http://foo.bar', hasSecret: false };
  52. beforeEach(() => {
  53. (searchDeliveries as jest.Mock<any>).mockClear();
  54. });
  55. it('should render correctly', async () => {
  56. const wrapper = getWrapper();
  57. expect(wrapper).toMatchSnapshot();
  58. await new Promise(setImmediate);
  59. expect(searchDeliveries as jest.Mock<any>).toHaveBeenLastCalledWith({
  60. webhook: webhook.key,
  61. ps: 10,
  62. });
  63. wrapper.update();
  64. expect(wrapper).toMatchSnapshot();
  65. wrapper.find('ListFooter').prop<Function>('loadMore')();
  66. expect(searchDeliveries).toHaveBeenLastCalledWith({ webhook: webhook.key, p: 2, ps: 10 });
  67. });
  68. function getWrapper(props = {}) {
  69. return shallow(<DeliveriesForm onClose={jest.fn()} webhook={webhook} {...props} />);
  70. }