teamNotifications.spec.tsx 4.0 KB

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