teamNotifications.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 type {ExternalTeam} from 'sentry/types/integrations';
  10. import TeamNotificationSettings from 'sentry/views/settings/organizationTeams/teamNotifications';
  11. const EXTERNAL_NAME = 'marcos';
  12. const EXAMPLE_EXTERNAL_TEAM: ExternalTeam = {
  13. externalName: EXTERNAL_NAME,
  14. id: '1',
  15. integrationId: '1',
  16. provider: 'slack',
  17. teamId: '1',
  18. };
  19. const EXAMPLE_INTEGRATION = {
  20. id: '1',
  21. provider: {
  22. key: 'slack',
  23. },
  24. };
  25. describe('TeamNotificationSettings', () => {
  26. const teamWithExternalTeam = TeamFixture({
  27. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  28. });
  29. const teamWithoutExternalTeam = TeamFixture();
  30. const {organization, router} = initializeOrg({
  31. router: {params: {teamId: teamWithExternalTeam.slug}},
  32. });
  33. beforeEach(() => {
  34. MockApiClient.clearMockResponses();
  35. });
  36. it('should render empty message when there are no integrations', async () => {
  37. MockApiClient.addMockResponse({
  38. url: `/teams/${organization.slug}/${teamWithExternalTeam.slug}/`,
  39. body: teamWithExternalTeam,
  40. });
  41. MockApiClient.addMockResponse({
  42. url: `/organizations/${organization.slug}/integrations/`,
  43. body: [],
  44. });
  45. render(<TeamNotificationSettings />, {router, organization});
  46. expect(
  47. await screen.findByText('No Notification Integrations have been installed yet.')
  48. ).toBeInTheDocument();
  49. });
  50. it('should render empty message when there are no externalTeams', async () => {
  51. MockApiClient.addMockResponse({
  52. url: `/teams/${organization.slug}/${teamWithExternalTeam.slug}/`,
  53. body: teamWithoutExternalTeam,
  54. });
  55. MockApiClient.addMockResponse({
  56. url: `/organizations/${organization.slug}/integrations/`,
  57. body: [EXAMPLE_INTEGRATION],
  58. });
  59. render(<TeamNotificationSettings />, {router, organization});
  60. expect(await screen.findByText('No teams have been linked yet.')).toBeInTheDocument();
  61. });
  62. it('should render each externalTeam', async () => {
  63. MockApiClient.addMockResponse({
  64. url: `/teams/${organization.slug}/${teamWithExternalTeam.slug}/`,
  65. body: teamWithExternalTeam,
  66. });
  67. MockApiClient.addMockResponse({
  68. url: `/organizations/${organization.slug}/integrations/`,
  69. body: [EXAMPLE_INTEGRATION],
  70. });
  71. render(<TeamNotificationSettings />, {router, organization});
  72. const input = await screen.findByRole('textbox', {
  73. name: 'Unlink this channel in slack with `/slack unlink team`',
  74. });
  75. expect(input).toBeDisabled();
  76. expect(input).toHaveValue(EXTERNAL_NAME);
  77. expect(screen.getByRole('button', {name: 'Unlink'})).toBeInTheDocument();
  78. });
  79. it('should delete be able to delete the externalTeam', async () => {
  80. MockApiClient.addMockResponse({
  81. url: `/teams/${organization.slug}/${teamWithExternalTeam.slug}/`,
  82. body: teamWithExternalTeam,
  83. });
  84. MockApiClient.addMockResponse({
  85. url: `/organizations/${organization.slug}/integrations/`,
  86. body: [EXAMPLE_INTEGRATION],
  87. });
  88. const deleteMock = MockApiClient.addMockResponse({
  89. url: `/teams/${organization.slug}/${teamWithExternalTeam.slug}/external-teams/${EXAMPLE_EXTERNAL_TEAM.id}/`,
  90. status: 204,
  91. method: 'DELETE',
  92. });
  93. render(<TeamNotificationSettings />, {router, organization});
  94. await userEvent.click(await screen.findByRole('button', {name: 'Unlink'}));
  95. renderGlobalModal();
  96. await userEvent.click(screen.getByTestId('confirm-button'));
  97. expect(deleteMock).toHaveBeenCalled();
  98. });
  99. });