teamNotifications.spec.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. let team;
  24. beforeEach(() => {
  25. MockApiClient.clearMockResponses();
  26. team = TestStubs.Team();
  27. });
  28. it('should render empty message when there are no integrations', () => {
  29. const {organization, routerContext} = initializeOrg();
  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(<TeamNotificationSettings team={team} organization={organization} />, {
  41. context: routerContext,
  42. });
  43. expect(
  44. screen.getByText('No Notification Integrations have been installed yet.')
  45. ).toBeInTheDocument();
  46. });
  47. it('should render empty message when there are no externalTeams', () => {
  48. const {organization, routerContext} = initializeOrg();
  49. MockApiClient.addMockResponse({
  50. url: `/teams/${organization.slug}/${team.slug}/`,
  51. body: {
  52. externalTeams: [],
  53. },
  54. });
  55. MockApiClient.addMockResponse({
  56. url: `/organizations/${organization.slug}/integrations/`,
  57. body: [EXAMPLE_INTEGRATION],
  58. });
  59. render(<TeamNotificationSettings team={team} organization={organization} />, {
  60. context: routerContext,
  61. });
  62. expect(screen.getByText('No teams have been linked yet.')).toBeInTheDocument();
  63. });
  64. it('should render each externalTeam', () => {
  65. const {organization, routerContext} = initializeOrg();
  66. MockApiClient.addMockResponse({
  67. url: `/teams/${organization.slug}/${team.slug}/`,
  68. body: {
  69. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  70. },
  71. });
  72. MockApiClient.addMockResponse({
  73. url: `/organizations/${organization.slug}/integrations/`,
  74. body: [EXAMPLE_INTEGRATION],
  75. });
  76. render(<TeamNotificationSettings team={team} organization={organization} />, {
  77. context: routerContext,
  78. });
  79. const input = screen.getByRole('textbox', {
  80. name: 'Unlink this channel in slack with `/slack unlink team`',
  81. });
  82. expect(input).toBeDisabled();
  83. expect(input).toHaveValue(EXTERNAL_NAME);
  84. expect(screen.getByRole('button', {name: 'delete'})).toBeInTheDocument();
  85. });
  86. it('should delete be able to delete the externalTeam', () => {
  87. const {organization, routerContext} = initializeOrg();
  88. MockApiClient.addMockResponse({
  89. url: `/teams/${organization.slug}/${team.slug}/`,
  90. body: {
  91. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  92. },
  93. });
  94. MockApiClient.addMockResponse({
  95. url: `/organizations/${organization.slug}/integrations/`,
  96. body: [EXAMPLE_INTEGRATION],
  97. });
  98. const deleteMock = MockApiClient.addMockResponse({
  99. url: `/teams/${organization.slug}/${team.slug}/external-teams/${EXAMPLE_EXTERNAL_TEAM.id}/`,
  100. status: 204,
  101. method: 'DELETE',
  102. });
  103. render(<TeamNotificationSettings team={team} organization={organization} />, {
  104. context: routerContext,
  105. });
  106. userEvent.click(screen.getByRole('button', {name: 'delete'}));
  107. renderGlobalModal();
  108. userEvent.click(screen.getByTestId('confirm-button'));
  109. expect(deleteMock).toHaveBeenCalled();
  110. });
  111. });