customCommitsResolutionModal.spec.jsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {act} from 'sentry-test/reactTestingLibrary';
  3. import {selectByValue} from 'sentry-test/select-new';
  4. import CustomCommitsResolutionModal from 'sentry/components/customCommitsResolutionModal';
  5. describe('CustomCommitsResolutionModal', function () {
  6. let commitsMock;
  7. beforeEach(function () {
  8. commitsMock = MockApiClient.addMockResponse({
  9. url: '/projects/org-slug/project-slug/commits/',
  10. body: [TestStubs.Commit()],
  11. });
  12. });
  13. it('can select a commit', async function () {
  14. const onSelected = jest.fn();
  15. const wrapper = mountWithTheme(
  16. <CustomCommitsResolutionModal
  17. Header={p => p.children}
  18. Body={p => p.children}
  19. Footer={p => p.children}
  20. orgSlug="org-slug"
  21. projectSlug="project-slug"
  22. onSelected={onSelected}
  23. closeModal={jest.fn()}
  24. />
  25. );
  26. expect(commitsMock).toHaveBeenCalled();
  27. await act(tick);
  28. wrapper.update();
  29. expect(wrapper.find('Select').prop('options')).toEqual([
  30. expect.objectContaining({
  31. value: 'f7f395d14b2fe29a4e253bf1d3094d61e6ad4434',
  32. label: expect.anything(),
  33. }),
  34. ]);
  35. selectByValue(wrapper, 'f7f395d14b2fe29a4e253bf1d3094d61e6ad4434', {
  36. selector: 'SelectAsyncControl[name="commit"]',
  37. });
  38. await act(tick);
  39. wrapper.find('form').simulate('submit');
  40. expect(onSelected).toHaveBeenCalledWith({
  41. inCommit: {
  42. commit: 'f7f395d14b2fe29a4e253bf1d3094d61e6ad4434',
  43. repository: 'example/repo-name',
  44. },
  45. });
  46. });
  47. });