issueAlertNotificationOptions.spec.tsx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {GitHubIntegrationProviderFixture} from 'sentry-fixture/githubIntegrationProvider';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {OrganizationIntegrationsFixture} from 'sentry-fixture/organizationIntegrations';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import type {OrganizationIntegration} from 'sentry/types/integrations';
  6. import IssueAlertNotificationOptions, {
  7. type IssueAlertNotificationProps,
  8. } from 'sentry/views/projectInstall/issueAlertNotificationOptions';
  9. describe('MessagingIntegrationAlertRule', function () {
  10. const organization = OrganizationFixture({
  11. features: ['messaging-integration-onboarding-project-creation'],
  12. });
  13. const integrations: OrganizationIntegration[] = [];
  14. const mockSetAction = jest.fn();
  15. const notificationProps: IssueAlertNotificationProps = {
  16. actions: [],
  17. channel: 'channel',
  18. integration: undefined,
  19. provider: 'slack',
  20. providersToIntegrations: {},
  21. querySuccess: true,
  22. shouldRenderSetupButton: false,
  23. setActions: mockSetAction,
  24. setChannel: jest.fn(),
  25. setIntegration: jest.fn(),
  26. setProvider: jest.fn(),
  27. };
  28. const getComponent = () => <IssueAlertNotificationOptions {...notificationProps} />;
  29. it('renders setup button if no integrations are active', async function () {
  30. const providers = (providerKey: string) => [
  31. GitHubIntegrationProviderFixture({key: providerKey}),
  32. ];
  33. const providerKeys = ['slack', 'discord', 'msteams'];
  34. const mockResponses: jest.Mock<any>[] = [];
  35. providerKeys.forEach(providerKey => {
  36. mockResponses.push(
  37. MockApiClient.addMockResponse({
  38. url: `/organizations/${organization.slug}/config/integrations/?provider_key=${providerKey}`,
  39. body: {providers: providers(providerKey)},
  40. })
  41. );
  42. });
  43. mockResponses.push(
  44. MockApiClient.addMockResponse({
  45. url: `/organizations/${organization.slug}/integrations/?integrationType=messaging`,
  46. body: [],
  47. })
  48. );
  49. render(
  50. <IssueAlertNotificationOptions {...notificationProps} shouldRenderSetupButton />,
  51. {organization: organization}
  52. );
  53. await screen.findByText(/notify via email/i);
  54. expect(screen.queryByText(/notify via integration/i)).not.toBeInTheDocument();
  55. await screen.findByRole('button', {name: /connect to messaging/i});
  56. mockResponses.forEach(mock => {
  57. expect(mock).toHaveBeenCalled();
  58. });
  59. });
  60. it('renders alert configuration if integration is installed', async function () {
  61. integrations.push(
  62. OrganizationIntegrationsFixture({
  63. name: "Moo Toon's Workspace",
  64. status: 'active',
  65. })
  66. );
  67. render(getComponent(), {organization: organization});
  68. await screen.findByText(/notify via email/i);
  69. await screen.findByText(/notify via integration/i);
  70. });
  71. it('calls setter when new integration option is selected', async function () {
  72. integrations.push(
  73. OrganizationIntegrationsFixture({
  74. name: "Moo Toon's Workspace",
  75. status: 'active',
  76. })
  77. );
  78. render(getComponent(), {organization: organization});
  79. await screen.findByText(/notify via email/i);
  80. await screen.findByText(/notify via integration/i);
  81. await userEvent.click(screen.getByText(/notify via integration/i));
  82. expect(mockSetAction).toHaveBeenCalled();
  83. });
  84. });