subscriptionBox.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import type {ComponentProps} from 'react';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import SubscriptionBox from 'sentry/views/settings/organizationDeveloperSettings/subscriptionBox';
  5. describe('SubscriptionBox', () => {
  6. const onChange = jest.fn();
  7. let org = Organization();
  8. beforeEach(() => {
  9. onChange.mockReset();
  10. });
  11. function renderComponent(props: Partial<ComponentProps<typeof SubscriptionBox>> = {}) {
  12. return render(
  13. <SubscriptionBox
  14. resource="issue"
  15. checked={false}
  16. disabledFromPermissions={false}
  17. onChange={onChange}
  18. organization={org}
  19. isNew={false}
  20. {...props}
  21. />
  22. );
  23. }
  24. it('renders resource checkbox', () => {
  25. renderComponent();
  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 = 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. });