setupAlertIntegrationButton.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render} from 'sentry-test/reactTestingLibrary';
  4. import SetupAlertIntegrationButton from 'sentry/views/alerts/rules/issue/setupAlertIntegrationButton';
  5. describe('SetupAlertIntegrationButton', function () {
  6. const organization = OrganizationFixture();
  7. const featureOrg = OrganizationFixture({
  8. features: ['messaging-integration-onboarding'],
  9. });
  10. const project = ProjectFixture();
  11. it('renders slack button if no alert integrations when feature flag is off', function () {
  12. MockApiClient.addMockResponse({
  13. url: `/projects/${organization.slug}/${project.slug}/?expand=hasAlertIntegration`,
  14. body: {
  15. ...project,
  16. hasAlertIntegrationInstalled: false,
  17. },
  18. });
  19. const {container} = render(
  20. <SetupAlertIntegrationButton
  21. projectSlug={project.slug}
  22. organization={organization}
  23. />
  24. );
  25. expect(container).toHaveTextContent('Set Up Slack Now');
  26. });
  27. it('does not render button if alert integration installed when feature flag is off', function () {
  28. MockApiClient.addMockResponse({
  29. url: `/projects/${organization.slug}/${project.slug}/?expand=hasAlertIntegration`,
  30. body: {
  31. ...project,
  32. hasAlertIntegrationInstalled: true,
  33. },
  34. });
  35. const {container} = render(
  36. <SetupAlertIntegrationButton
  37. projectSlug={project.slug}
  38. organization={organization}
  39. />
  40. );
  41. expect(container).not.toHaveTextContent('Set Up Slack Now');
  42. });
  43. it('renders connect to messaging button when feature flag is on', function () {
  44. MockApiClient.addMockResponse({
  45. url: `/projects/${featureOrg.slug}/${project.slug}/?expand=hasAlertIntegration`,
  46. body: {
  47. ...project,
  48. hasAlertIntegrationInstalled: false,
  49. },
  50. });
  51. const {container} = render(
  52. <SetupAlertIntegrationButton projectSlug={project.slug} organization={featureOrg} />
  53. );
  54. expect(container).toHaveTextContent('Connect to messaging');
  55. });
  56. it('does not render button if alert integration installed when feature flag is on', function () {
  57. MockApiClient.addMockResponse({
  58. url: `/projects/${featureOrg.slug}/${project.slug}/?expand=hasAlertIntegration`,
  59. body: {
  60. ...project,
  61. hasAlertIntegrationInstalled: true,
  62. },
  63. });
  64. const {container} = render(
  65. <SetupAlertIntegrationButton projectSlug={project.slug} organization={featureOrg} />
  66. );
  67. expect(container).not.toHaveTextContent('Connect to messaging');
  68. });
  69. });