issue.spec.tsx 2.1 KB

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