issueAlertNotificationOptions.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. refetchConfigs: jest.fn(),
  24. setActions: mockSetAction,
  25. setChannel: jest.fn(),
  26. setIntegration: jest.fn(),
  27. setProvider: jest.fn(),
  28. };
  29. const getComponent = () => <IssueAlertNotificationOptions {...notificationProps} />;
  30. it('renders setup button if no integrations are active', async function () {
  31. const providers = (providerKey: string) => [
  32. GitHubIntegrationProviderFixture({key: providerKey}),
  33. ];
  34. const providerKeys = ['slack', 'discord', 'msteams'];
  35. const mockResponses: jest.Mock<any>[] = [];
  36. providerKeys.forEach(providerKey => {
  37. mockResponses.push(
  38. MockApiClient.addMockResponse({
  39. url: `/organizations/${organization.slug}/config/integrations/?provider_key=${providerKey}`,
  40. body: {providers: providers(providerKey)},
  41. })
  42. );
  43. });
  44. mockResponses.push(
  45. MockApiClient.addMockResponse({
  46. url: `/organizations/${organization.slug}/integrations/?integrationType=messaging`,
  47. body: [],
  48. })
  49. );
  50. render(
  51. <IssueAlertNotificationOptions {...notificationProps} shouldRenderSetupButton />,
  52. {organization: organization}
  53. );
  54. await screen.findByText(/notify via email/i);
  55. expect(screen.queryByText(/notify via integration/i)).not.toBeInTheDocument();
  56. await screen.findByRole('button', {name: /connect to messaging/i});
  57. mockResponses.forEach(mock => {
  58. expect(mock).toHaveBeenCalled();
  59. });
  60. });
  61. it('renders alert configuration if integration is installed', async function () {
  62. integrations.push(
  63. OrganizationIntegrationsFixture({
  64. name: "Moo Toon's Workspace",
  65. status: 'active',
  66. })
  67. );
  68. render(getComponent(), {organization: organization});
  69. await screen.findByText(/notify via email/i);
  70. await screen.findByText(/notify via integration/i);
  71. });
  72. it('calls setter when new integration option is selected', async function () {
  73. integrations.push(
  74. OrganizationIntegrationsFixture({
  75. name: "Moo Toon's Workspace",
  76. status: 'active',
  77. })
  78. );
  79. render(getComponent(), {organization: organization});
  80. await screen.findByText(/notify via email/i);
  81. await screen.findByText(/notify via integration/i);
  82. await userEvent.click(screen.getByText(/notify via integration/i));
  83. expect(mockSetAction).toHaveBeenCalled();
  84. });
  85. });