subscriptionBox.spec.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import type {ComponentProps} from 'react';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import SubscriptionBox from 'sentry/views/settings/organizationDeveloperSettings/subscriptionBox';
  4. describe('SubscriptionBox', () => {
  5. const onChange = jest.fn();
  6. let org = TestStubs.Organization();
  7. beforeEach(() => {
  8. onChange.mockReset();
  9. });
  10. function renderComponent(props: Partial<ComponentProps<typeof SubscriptionBox>> = {}) {
  11. return render(
  12. <SubscriptionBox
  13. resource="issue"
  14. checked={false}
  15. disabledFromPermissions={false}
  16. onChange={onChange}
  17. organization={org}
  18. isNew={false}
  19. {...props}
  20. />
  21. );
  22. }
  23. it('renders resource checkbox', () => {
  24. renderComponent();
  25. });
  26. it('calls onChange prop when checking checkbox', async () => {
  27. renderComponent();
  28. await userEvent.click(screen.getByRole('checkbox'));
  29. expect(onChange).toHaveBeenCalledWith('issue', true);
  30. });
  31. it('disables the checkbox from permissions', async () => {
  32. renderComponent({disabledFromPermissions: true});
  33. expect(screen.getByRole('checkbox')).toBeDisabled();
  34. await userEvent.hover(screen.getByRole('checkbox'));
  35. expect(
  36. await screen.findByText("Must have at least 'Read' permissions enabled for Event")
  37. ).toBeInTheDocument();
  38. });
  39. describe('error.created resource subscription', () => {
  40. it('checkbox disabled without integrations-event-hooks flag', async () => {
  41. renderComponent({resource: 'error'});
  42. expect(screen.getByRole('checkbox')).toBeDisabled();
  43. await userEvent.hover(screen.getByRole('checkbox'));
  44. expect(
  45. await screen.findByText(
  46. 'Your organization does not have access to the error subscription resource.'
  47. )
  48. ).toBeInTheDocument();
  49. });
  50. it('checkbox visible with integrations-event-hooks flag', () => {
  51. org = TestStubs.Organization({features: ['integrations-event-hooks']});
  52. renderComponent({resource: 'error', organization: org});
  53. expect(screen.getByRole('checkbox')).toBeEnabled();
  54. });
  55. });
  56. it('disables checkbox when webhookDisabled=true', async () => {
  57. renderComponent({resource: 'error', webhookDisabled: true});
  58. expect(screen.getByRole('checkbox')).toBeDisabled();
  59. await userEvent.hover(screen.getByRole('checkbox'));
  60. expect(
  61. await screen.findByText(
  62. 'Cannot enable webhook subscription without specifying a webhook url'
  63. )
  64. ).toBeInTheDocument();
  65. });
  66. });