eventCauseEmpty.spec.jsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import moment from 'moment';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import EventCauseEmpty from 'sentry/components/events/eventCauseEmpty';
  4. import {trackAnalyticsEventV2} from 'sentry/utils/analytics';
  5. jest.mock('sentry/utils/analytics');
  6. describe('EventCauseEmpty', function () {
  7. let putMock;
  8. const organization = TestStubs.Organization();
  9. const project = TestStubs.Project({
  10. platform: 'javascript',
  11. firstEvent: '2020-01-01T23:54:33.831199Z',
  12. });
  13. const event = TestStubs.Event();
  14. beforeEach(function () {
  15. jest.clearAllMocks();
  16. MockApiClient.clearMockResponses();
  17. MockApiClient.addMockResponse({
  18. url: '/projects/org-slug/project-slug/releases/completion/',
  19. body: [{step: 'commit', complete: false}],
  20. });
  21. MockApiClient.addMockResponse({
  22. method: 'GET',
  23. url: '/prompts-activity/',
  24. body: {},
  25. });
  26. putMock = MockApiClient.addMockResponse({
  27. method: 'PUT',
  28. url: '/prompts-activity/',
  29. });
  30. });
  31. it('renders', async function () {
  32. const wrapper = mountWithTheme(
  33. <EventCauseEmpty event={event} organization={organization} project={project} />
  34. );
  35. await tick();
  36. wrapper.update();
  37. expect(wrapper.find('ExampleCommitPanel').exists()).toBe(true);
  38. expect(trackAnalyticsEventV2).toHaveBeenCalledWith({
  39. eventKey: 'event_cause.viewed',
  40. eventName: null,
  41. organization,
  42. project_id: project.id,
  43. platform: project.platform,
  44. });
  45. });
  46. /**
  47. * Want to alternate between showing the configure suspect commits prompt and
  48. * the show configure distributed tracing prompt.
  49. */
  50. it('doesnt render when event id starts with even char', async function () {
  51. const newEvent = {
  52. ...event,
  53. id: 'A',
  54. eventID: 'ABCDEFABCDEFABCDEFABCDEFABCDEFAB',
  55. };
  56. const wrapper = mountWithTheme(
  57. <EventCauseEmpty event={newEvent} organization={organization} project={project} />
  58. );
  59. await tick();
  60. wrapper.update();
  61. expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
  62. expect(trackAnalyticsEventV2).not.toHaveBeenCalled();
  63. });
  64. it('can be snoozed', async function () {
  65. const wrapper = mountWithTheme(
  66. <EventCauseEmpty event={event} organization={organization} project={project} />
  67. );
  68. await tick();
  69. wrapper.update();
  70. wrapper.find('button[aria-label="Snooze"]').first().simulate('click');
  71. await tick();
  72. wrapper.update();
  73. expect(putMock).toHaveBeenCalledWith(
  74. '/prompts-activity/',
  75. expect.objectContaining({
  76. method: 'PUT',
  77. data: {
  78. organization_id: organization.id,
  79. project_id: project.id,
  80. feature: 'suspect_commits',
  81. status: 'snoozed',
  82. },
  83. })
  84. );
  85. expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
  86. expect(trackAnalyticsEventV2).toHaveBeenCalledWith({
  87. eventKey: 'event_cause.snoozed',
  88. eventName: 'Event Cause Snoozed',
  89. organization,
  90. project_id: project.id,
  91. platform: project.platform,
  92. });
  93. });
  94. it('does not render when snoozed', async function () {
  95. const snoozed_ts = moment().subtract(1, 'day').unix();
  96. MockApiClient.addMockResponse({
  97. method: 'GET',
  98. url: '/prompts-activity/',
  99. body: {data: {snoozed_ts}},
  100. });
  101. const wrapper = mountWithTheme(
  102. <EventCauseEmpty event={event} organization={organization} project={project} />
  103. );
  104. await tick();
  105. wrapper.update();
  106. expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
  107. });
  108. it('renders when snoozed more than 7 days ago', async function () {
  109. const snoozed_ts = moment().subtract(9, 'day').unix();
  110. MockApiClient.addMockResponse({
  111. method: 'GET',
  112. url: '/prompts-activity/',
  113. body: {data: {snoozed_ts}},
  114. });
  115. const wrapper = mountWithTheme(
  116. <EventCauseEmpty event={event} organization={organization} project={project} />
  117. );
  118. await tick();
  119. wrapper.update();
  120. expect(wrapper.find('ExampleCommitPanel').exists()).toBe(true);
  121. });
  122. it('can be dismissed', async function () {
  123. const wrapper = mountWithTheme(
  124. <EventCauseEmpty event={event} organization={organization} project={project} />
  125. );
  126. await tick();
  127. wrapper.update();
  128. wrapper.find('button[aria-label="Dismiss"]').first().simulate('click');
  129. await tick();
  130. wrapper.update();
  131. expect(putMock).toHaveBeenCalledWith(
  132. '/prompts-activity/',
  133. expect.objectContaining({
  134. method: 'PUT',
  135. data: {
  136. organization_id: organization.id,
  137. project_id: project.id,
  138. feature: 'suspect_commits',
  139. status: 'dismissed',
  140. },
  141. })
  142. );
  143. expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
  144. expect(trackAnalyticsEventV2).toHaveBeenCalledWith({
  145. eventKey: 'event_cause.dismissed',
  146. eventName: 'Event Cause Dismissed',
  147. organization,
  148. project_id: project.id,
  149. platform: project.platform,
  150. });
  151. });
  152. it('does not render when dismissed', async function () {
  153. MockApiClient.addMockResponse({
  154. method: 'GET',
  155. url: '/prompts-activity/',
  156. body: {data: {dismissed_ts: moment().unix()}},
  157. });
  158. const wrapper = mountWithTheme(
  159. <EventCauseEmpty event={event} organization={organization} project={project} />
  160. );
  161. await tick();
  162. wrapper.update();
  163. expect(wrapper.find('ExampleCommitPanel').exists()).toBe(false);
  164. });
  165. it('can capture analytics on docs click', async function () {
  166. const wrapper = mountWithTheme(
  167. <EventCauseEmpty event={event} organization={organization} project={project} />
  168. );
  169. await tick();
  170. wrapper.update();
  171. wrapper.find('[aria-label="Read the docs"]').first().simulate('click');
  172. expect(trackAnalyticsEventV2).toHaveBeenCalledWith({
  173. eventKey: 'event_cause.docs_clicked',
  174. eventName: 'Event Cause Docs Clicked',
  175. organization,
  176. project_id: project.id,
  177. platform: project.platform,
  178. });
  179. });
  180. });