index.spec.tsx 2.1 KB

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