index.spec.tsx 2.1 KB

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