issueAlertNotificationOptions.spec.tsx 3.2 KB

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