teamNotificationSettings.spec.jsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {mountGlobalModal} from 'sentry-test/modal';
  4. import TeamNotificationSettings from 'sentry/views/settings/organizationTeams/teamNotifications';
  5. const EXTERNAL_NAME = 'marcos';
  6. const EXAMPLE_EXTERNAL_TEAM = {
  7. externalName: EXTERNAL_NAME,
  8. id: '1',
  9. integrationId: '1',
  10. provider: 'slack',
  11. };
  12. const EXAMPLE_INTEGRATION = {
  13. id: '1',
  14. provider: {
  15. key: 'slack',
  16. },
  17. };
  18. describe('TeamNotificationSettings', () => {
  19. let team;
  20. beforeEach(() => {
  21. MockApiClient.clearMockResponses();
  22. team = TestStubs.Team();
  23. });
  24. it('should render empty message when there are no integrations', () => {
  25. const {organization, routerContext} = initializeOrg();
  26. MockApiClient.addMockResponse({
  27. url: `/teams/${organization.slug}/${team.slug}/`,
  28. body: {
  29. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  30. },
  31. });
  32. MockApiClient.addMockResponse({
  33. url: `/organizations/${organization.slug}/integrations/`,
  34. body: [],
  35. });
  36. const wrapper = mountWithTheme(
  37. <TeamNotificationSettings team={team} organization={organization} />,
  38. routerContext
  39. );
  40. const emptyMessage = wrapper.find('Panel div[data-test-id="empty-message"]');
  41. expect(emptyMessage).toHaveLength(1);
  42. expect(emptyMessage.text()).toBe(
  43. 'No Notification Integrations have been installed yet.'
  44. );
  45. });
  46. it('should render empty message when there are no externalTeams', () => {
  47. const {organization, routerContext} = initializeOrg();
  48. MockApiClient.addMockResponse({
  49. url: `/teams/${organization.slug}/${team.slug}/`,
  50. body: {
  51. externalTeams: [],
  52. },
  53. });
  54. MockApiClient.addMockResponse({
  55. url: `/organizations/${organization.slug}/integrations/`,
  56. body: [EXAMPLE_INTEGRATION],
  57. });
  58. const wrapper = mountWithTheme(
  59. <TeamNotificationSettings team={team} organization={organization} />,
  60. routerContext
  61. );
  62. const emptyMessage = wrapper.find('Panel div[data-test-id="empty-message"]');
  63. expect(emptyMessage).toHaveLength(1);
  64. expect(emptyMessage.find('div div div').first().text()).toBe(
  65. 'No teams have been linked yet.'
  66. );
  67. });
  68. it('should render each externalTeam', () => {
  69. const {organization, routerContext} = initializeOrg();
  70. MockApiClient.addMockResponse({
  71. url: `/teams/${organization.slug}/${team.slug}/`,
  72. body: {
  73. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  74. },
  75. });
  76. MockApiClient.addMockResponse({
  77. url: `/organizations/${organization.slug}/integrations/`,
  78. body: [EXAMPLE_INTEGRATION],
  79. });
  80. const wrapper = mountWithTheme(
  81. <TeamNotificationSettings team={team} organization={organization} />,
  82. routerContext
  83. );
  84. const input = wrapper.find('Panel').last().find('input');
  85. expect(input.prop('disabled')).toBe(true);
  86. expect(input.prop('value')).toBe(EXTERNAL_NAME);
  87. expect(wrapper.find('button[aria-label="delete"]').exists()).toBe(true);
  88. });
  89. it('should delete be able to delete the externalTeam', async () => {
  90. const {organization, routerContext} = initializeOrg();
  91. MockApiClient.addMockResponse({
  92. url: `/teams/${organization.slug}/${team.slug}/`,
  93. body: {
  94. externalTeams: [EXAMPLE_EXTERNAL_TEAM],
  95. },
  96. });
  97. MockApiClient.addMockResponse({
  98. url: `/organizations/${organization.slug}/integrations/`,
  99. body: [EXAMPLE_INTEGRATION],
  100. });
  101. const deleteMock = MockApiClient.addMockResponse({
  102. url: `/teams/${organization.slug}/${team.slug}/external-teams/${EXAMPLE_EXTERNAL_TEAM.id}/`,
  103. status: 204,
  104. method: 'DELETE',
  105. });
  106. const wrapper = mountWithTheme(
  107. <TeamNotificationSettings team={team} organization={organization} />,
  108. routerContext
  109. );
  110. const deleteButton = wrapper.find('button[aria-label="delete"]');
  111. expect(deleteButton.prop('disabled')).toBe(false);
  112. deleteButton.simulate('click');
  113. await tick();
  114. const modal = await mountGlobalModal();
  115. const confirmBtn = modal.find('Button').last().simulate('click');
  116. expect(confirmBtn.exists()).toBe(true);
  117. confirmBtn.simulate('click');
  118. expect(deleteMock).toHaveBeenCalled();
  119. });
  120. });