subscriptionBox.spec.jsx 2.4 KB

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