messagingIntegrationAlertRule.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {OrganizationIntegrationsFixture} from 'sentry-fixture/organizationIntegrations';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import selectEvent from 'sentry-test/selectEvent';
  4. import type {IssueAlertNotificationProps} from 'sentry/views/projectInstall/issueAlertNotificationOptions';
  5. import MessagingIntegrationAlertRule from 'sentry/views/projectInstall/messagingIntegrationAlertRule';
  6. describe('MessagingIntegrationAlertRule', function () {
  7. const slackIntegrations = [
  8. OrganizationIntegrationsFixture({
  9. name: "Moo Deng's Workspace",
  10. }),
  11. OrganizationIntegrationsFixture({
  12. name: "Moo Waan's Workspace",
  13. }),
  14. ];
  15. const discordIntegrations = [
  16. OrganizationIntegrationsFixture({
  17. name: "Moo Deng's Server",
  18. }),
  19. ];
  20. const msteamsIntegrations = [
  21. OrganizationIntegrationsFixture({
  22. name: "Moo Deng's Team",
  23. }),
  24. ];
  25. const providersToIntegrations = {
  26. slack: slackIntegrations,
  27. discord: discordIntegrations,
  28. msteams: msteamsIntegrations,
  29. };
  30. const mockSetChannel = jest.fn();
  31. const mockSetIntegration = jest.fn();
  32. const mockSetProvider = jest.fn();
  33. const notificationProps: IssueAlertNotificationProps = {
  34. actions: [],
  35. channel: 'channel',
  36. integration: slackIntegrations[0],
  37. provider: 'slack',
  38. providersToIntegrations: providersToIntegrations,
  39. querySuccess: true,
  40. shouldRenderSetupButton: false,
  41. setActions: jest.fn(),
  42. setChannel: mockSetChannel,
  43. setIntegration: mockSetIntegration,
  44. setProvider: mockSetProvider,
  45. };
  46. const getComponent = () => <MessagingIntegrationAlertRule {...notificationProps} />;
  47. it('renders', function () {
  48. render(getComponent());
  49. expect(screen.getAllByRole('textbox')).toHaveLength(3);
  50. });
  51. it('calls setter when new integration is selected', async function () {
  52. render(getComponent());
  53. await selectEvent.select(
  54. screen.getByText("Moo Deng's Workspace"),
  55. "Moo Waan's Workspace"
  56. );
  57. expect(mockSetIntegration).toHaveBeenCalled();
  58. });
  59. it('calls setters when new provider is selected', async function () {
  60. render(getComponent());
  61. await selectEvent.select(screen.getByText('Slack'), 'Discord');
  62. expect(mockSetProvider).toHaveBeenCalled();
  63. expect(mockSetIntegration).toHaveBeenCalled();
  64. expect(mockSetChannel).toHaveBeenCalled();
  65. });
  66. it('disables provider select when there is only one provider option', function () {
  67. render(
  68. <MessagingIntegrationAlertRule
  69. {...notificationProps}
  70. providersToIntegrations={{slack: slackIntegrations}}
  71. />
  72. );
  73. expect(screen.getByLabelText('provider')).toBeDisabled();
  74. });
  75. it('disables integration select when there is only one integration option', function () {
  76. render(
  77. <MessagingIntegrationAlertRule
  78. {...{
  79. ...notificationProps,
  80. integration: discordIntegrations[0],
  81. provider: 'discord',
  82. }}
  83. />
  84. );
  85. expect(screen.getByLabelText('integration')).toBeDisabled();
  86. });
  87. });