messagingIntegrationAlertRule.spec.tsx 2.9 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 MessagingIntegrationAlertRule from 'sentry/views/projectInstall/messagingIntegrationAlertRule';
  5. describe('MessagingIntegrationAlertRule', function () {
  6. const slackIntegrations = [
  7. OrganizationIntegrationsFixture({
  8. name: "Moo Deng's Workspace",
  9. }),
  10. OrganizationIntegrationsFixture({
  11. name: "Moo Waan's Workspace",
  12. }),
  13. ];
  14. const discordIntegrations = [
  15. OrganizationIntegrationsFixture({
  16. name: "Moo Deng's Server",
  17. }),
  18. ];
  19. const msteamsIntegrations = [
  20. OrganizationIntegrationsFixture({
  21. name: "Moo Deng's Team",
  22. }),
  23. ];
  24. const providersToIntegrations = {
  25. slack: slackIntegrations,
  26. discord: discordIntegrations,
  27. msteams: msteamsIntegrations,
  28. };
  29. const mockSetChannel = jest.fn();
  30. const mockSetIntegration = jest.fn();
  31. const mockSetProvider = jest.fn();
  32. const notificationProps = {
  33. actions: [],
  34. channel: 'channel',
  35. integration: slackIntegrations[0],
  36. provider: 'slack',
  37. providersToIntegrations: providersToIntegrations,
  38. querySuccess: true,
  39. shouldRenderSetupButton: false,
  40. refetchConfigs: jest.fn(),
  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. });