teamNotifications.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import TeamNotificationSettings from 'sentry/views/settings/organizationTeams/teamNotifications';
  9. const EXTERNAL_NAME = 'marcos';
  10. const EXAMPLE_EXTERNAL_TEAM = {
  11. externalName: EXTERNAL_NAME,
  12. id: '1',
  13. integrationId: '1',
  14. provider: 'slack',
  15. };
  16. const EXAMPLE_INTEGRATION = {
  17. id: '1',
  18. provider: {
  19. key: 'slack',
  20. },
  21. };
  22. describe('TeamNotificationSettings', () => {
  23. const {organization, routerContext, routerProps} = initializeOrg();
  24. const team = TestStubs.Team();
  25. beforeEach(() => {
  26. MockApiClient.clearMockResponses();
  27. });
  28. it('should render empty message when there are no integrations', () => {
  29. MockApiClient.addMockResponse({
  30. url: `/teams/${organization.slug}/${team.slug}/`,
  31. body: {
  32. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  33. },
  34. });
  35. MockApiClient.addMockResponse({
  36. url: `/organizations/${organization.slug}/integrations/`,
  37. body: [],
  38. });
  39. render(
  40. <TeamNotificationSettings
  41. {...routerProps}
  42. team={team}
  43. params={{teamId: team.id}}
  44. organization={organization}
  45. />,
  46. {context: routerContext}
  47. );
  48. expect(
  49. screen.getByText('No Notification Integrations have been installed yet.')
  50. ).toBeInTheDocument();
  51. });
  52. it('should render empty message when there are no externalTeams', () => {
  53. MockApiClient.addMockResponse({
  54. url: `/teams/${organization.slug}/${team.slug}/`,
  55. body: {
  56. externalTeams: [],
  57. },
  58. });
  59. MockApiClient.addMockResponse({
  60. url: `/organizations/${organization.slug}/integrations/`,
  61. body: [EXAMPLE_INTEGRATION],
  62. });
  63. render(
  64. <TeamNotificationSettings
  65. {...routerProps}
  66. team={team}
  67. params={{teamId: team.id}}
  68. organization={organization}
  69. />,
  70. {
  71. context: routerContext,
  72. }
  73. );
  74. expect(screen.getByText('No teams have been linked yet.')).toBeInTheDocument();
  75. });
  76. it('should render each externalTeam', () => {
  77. MockApiClient.addMockResponse({
  78. url: `/teams/${organization.slug}/${team.slug}/`,
  79. body: {
  80. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  81. },
  82. });
  83. MockApiClient.addMockResponse({
  84. url: `/organizations/${organization.slug}/integrations/`,
  85. body: [EXAMPLE_INTEGRATION],
  86. });
  87. render(
  88. <TeamNotificationSettings
  89. {...routerProps}
  90. team={team}
  91. params={{teamId: team.id}}
  92. organization={organization}
  93. />,
  94. {
  95. context: routerContext,
  96. }
  97. );
  98. const input = screen.getByRole('textbox', {
  99. name: 'Unlink this channel in slack with `/slack unlink team`',
  100. });
  101. expect(input).toBeDisabled();
  102. expect(input).toHaveValue(EXTERNAL_NAME);
  103. expect(screen.getByRole('button', {name: 'delete'})).toBeInTheDocument();
  104. });
  105. it('should delete be able to delete the externalTeam', async () => {
  106. MockApiClient.addMockResponse({
  107. url: `/teams/${organization.slug}/${team.slug}/`,
  108. body: {
  109. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  110. },
  111. });
  112. MockApiClient.addMockResponse({
  113. url: `/organizations/${organization.slug}/integrations/`,
  114. body: [EXAMPLE_INTEGRATION],
  115. });
  116. const deleteMock = MockApiClient.addMockResponse({
  117. url: `/teams/${organization.slug}/${team.slug}/external-teams/${EXAMPLE_EXTERNAL_TEAM.id}/`,
  118. status: 204,
  119. method: 'DELETE',
  120. });
  121. render(
  122. <TeamNotificationSettings
  123. {...routerProps}
  124. team={team}
  125. params={{teamId: team.id}}
  126. organization={organization}
  127. />,
  128. {
  129. context: routerContext,
  130. }
  131. );
  132. await userEvent.click(screen.getByRole('button', {name: 'delete'}));
  133. renderGlobalModal();
  134. await userEvent.click(screen.getByTestId('confirm-button'));
  135. expect(deleteMock).toHaveBeenCalled();
  136. });
  137. });