project.spec.tsx 2.1 KB

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