subscriptionBox.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. const {container} = renderComponent();
  25. expect(container).toSnapshot();
  26. });
  27. it('calls onChange prop when checking checkbox', async () => {
  28. renderComponent();
  29. await userEvent.click(screen.getByRole('checkbox'));
  30. expect(onChange).toHaveBeenCalledWith('issue', true);
  31. });
  32. it('disables the checkbox from permissions', async () => {
  33. renderComponent({disabledFromPermissions: true});
  34. expect(screen.getByRole('checkbox')).toBeDisabled();
  35. await userEvent.hover(screen.getByRole('checkbox'));
  36. expect(
  37. await screen.findByText("Must have at least 'Read' permissions enabled for Event")
  38. ).toBeInTheDocument();
  39. });
  40. describe('error.created resource subscription', () => {
  41. it('checkbox disabled without integrations-event-hooks flag', async () => {
  42. renderComponent({resource: 'error'});
  43. expect(screen.getByRole('checkbox')).toBeDisabled();
  44. await userEvent.hover(screen.getByRole('checkbox'));
  45. expect(
  46. await screen.findByText(
  47. 'Your organization does not have access to the error subscription resource.'
  48. )
  49. ).toBeInTheDocument();
  50. });
  51. it('checkbox visible with integrations-event-hooks flag', () => {
  52. org = TestStubs.Organization({features: ['integrations-event-hooks']});
  53. renderComponent({resource: 'error', organization: org});
  54. expect(screen.getByRole('checkbox')).toBeEnabled();
  55. });
  56. });
  57. it('disables checkbox when webhookDisabled=true', async () => {
  58. renderComponent({resource: 'error', webhookDisabled: true});
  59. expect(screen.getByRole('checkbox')).toBeDisabled();
  60. await userEvent.hover(screen.getByRole('checkbox'));
  61. expect(
  62. await screen.findByText(
  63. 'Cannot enable webhook subscription without specifying a webhook url'
  64. )
  65. ).toBeInTheDocument();
  66. });
  67. });