project.spec.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import UnsubscribeProject from 'sentry/views/unsubscribe/project';
  4. describe('UnsubscribeProject', function () {
  5. const params = {orgId: 'acme', id: '9876'};
  6. let mockUpdate: jest.Mock;
  7. let mockGet: jest.Mock;
  8. beforeEach(() => {
  9. mockUpdate = MockApiClient.addMockResponse({
  10. url: '/organizations/acme/unsubscribe/project/9876/?_=signature-value',
  11. method: 'POST',
  12. status: 201,
  13. });
  14. mockGet = MockApiClient.addMockResponse({
  15. url: '/organizations/acme/unsubscribe/project/9876/',
  16. method: 'GET',
  17. status: 200,
  18. body: {
  19. viewUrl: 'https://acme.sentry.io/projects/react/',
  20. type: 'project',
  21. slug: 'react',
  22. displayName: 'Bruce Wayne',
  23. },
  24. });
  25. });
  26. it('loads data from the API based on URL parameters', async function () {
  27. const {router, routerProps} = initializeOrg({
  28. router: {location: {query: {_: 'signature-value'}}, params},
  29. });
  30. render(
  31. <UnsubscribeProject {...routerProps} location={router.location} params={params} />,
  32. {router}
  33. );
  34. expect(await screen.findByText('acme / react')).toBeInTheDocument();
  35. expect(screen.getByRole('button', {name: 'Unsubscribe'})).toBeInTheDocument();
  36. expect(mockGet).toHaveBeenCalled();
  37. });
  38. it('makes an API request when the form is submitted', async function () {
  39. const {router, routerProps} = initializeOrg({
  40. router: {location: {query: {_: 'signature-value'}}, params},
  41. });
  42. render(
  43. <UnsubscribeProject {...routerProps} location={router.location} params={params} />,
  44. {router}
  45. );
  46. expect(await screen.findByText('acme / react')).toBeInTheDocument();
  47. const button = screen.getByRole('button', {name: 'Unsubscribe'});
  48. await userEvent.click(button);
  49. expect(mockUpdate).toHaveBeenCalledWith(
  50. '/organizations/acme/unsubscribe/project/9876/?_=signature-value',
  51. expect.objectContaining({data: {cancel: 1}})
  52. );
  53. });
  54. });