setupAlertIntegrationButton.spec.tsx 3.2 KB

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