index.spec.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import AcceptProjectTransfer from 'sentry/views/acceptProjectTransfer';
  5. describe('AcceptProjectTransfer', function () {
  6. let getMock: jest.Mock;
  7. let postMock: jest.Mock;
  8. const endpoint = '/accept-transfer/';
  9. beforeEach(function () {
  10. MockApiClient.clearMockResponses();
  11. getMock = MockApiClient.addMockResponse({
  12. url: '/accept-transfer/',
  13. method: 'GET',
  14. body: {
  15. project: ProjectFixture(),
  16. organizations: [OrganizationFixture()],
  17. },
  18. });
  19. postMock = MockApiClient.addMockResponse({
  20. url: '/accept-transfer/',
  21. method: 'POST',
  22. statusCode: 204,
  23. });
  24. });
  25. it('renders', function () {
  26. render(<AcceptProjectTransfer />);
  27. expect(getMock).toHaveBeenCalled();
  28. });
  29. it('renders and fetches data from the region url', function () {
  30. window.__initialData = {
  31. ...window.__initialData,
  32. links: {
  33. regionUrl: 'http://us.sentry.io',
  34. sentryUrl: 'http://sentry.io',
  35. organizationUrl: 'http://acme.sentry.io',
  36. },
  37. };
  38. getMock = MockApiClient.addMockResponse({
  39. url: '/accept-transfer/',
  40. method: 'GET',
  41. body: {
  42. project: ProjectFixture(),
  43. organizations: [OrganizationFixture()],
  44. },
  45. match: [(_url, options) => options.host === 'http://us.sentry.io'],
  46. });
  47. render(<AcceptProjectTransfer />);
  48. expect(getMock).toHaveBeenCalled();
  49. });
  50. it('submits', async function () {
  51. render(<AcceptProjectTransfer />);
  52. await userEvent.click(await screen.findByRole('button', {name: 'Transfer Project'}));
  53. expect(postMock).toHaveBeenCalledWith(
  54. endpoint,
  55. expect.objectContaining({
  56. method: 'POST',
  57. host: 'http://us.sentry.io',
  58. })
  59. );
  60. });
  61. });