index.spec.tsx 2.0 KB

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