results.spec.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import Results from 'app/views/eventsV2/results';
  5. const FIELDS = [
  6. {
  7. field: 'title',
  8. },
  9. {
  10. field: 'timestamp',
  11. },
  12. {
  13. field: 'user',
  14. },
  15. ];
  16. const generateFields = () => {
  17. return {
  18. field: FIELDS.map(i => i.field),
  19. };
  20. };
  21. describe('EventsV2 > Results', function() {
  22. const eventTitle = 'Oh no something bad';
  23. const features = ['events-v2'];
  24. beforeEach(function() {
  25. MockApiClient.addMockResponse({
  26. url: '/organizations/org-slug/projects/',
  27. body: [],
  28. });
  29. MockApiClient.addMockResponse({
  30. url: '/organizations/org-slug/tags/',
  31. body: [],
  32. });
  33. MockApiClient.addMockResponse({
  34. url: '/organizations/org-slug/events-stats/',
  35. body: {data: [[123, []]]},
  36. });
  37. MockApiClient.addMockResponse({
  38. url: '/organizations/org-slug/recent-searches/',
  39. body: [],
  40. });
  41. MockApiClient.addMockResponse({
  42. url: '/organizations/org-slug/recent-searches/',
  43. method: 'POST',
  44. body: [],
  45. });
  46. MockApiClient.addMockResponse({
  47. url: '/organizations/org-slug/releases/',
  48. body: [],
  49. });
  50. MockApiClient.addMockResponse({
  51. url: '/organizations/org-slug/eventsv2/',
  52. body: {
  53. meta: {
  54. id: 'string',
  55. title: 'string',
  56. 'project.name': 'string',
  57. timestamp: 'date',
  58. 'user.id': 'string',
  59. },
  60. data: [
  61. {
  62. id: 'deadbeef',
  63. 'user.id': 'alberto leal',
  64. title: eventTitle,
  65. 'project.name': 'project-slug',
  66. timestamp: '2019-05-23T22:12:48+00:00',
  67. },
  68. ],
  69. },
  70. });
  71. MockApiClient.addMockResponse({
  72. url: '/organizations/org-slug/events/project-slug:deadbeef/',
  73. method: 'GET',
  74. body: {
  75. id: '1234',
  76. size: 1200,
  77. eventID: 'deadbeef',
  78. title: 'Oh no something bad',
  79. message: 'It was not good',
  80. dateCreated: '2019-05-23T22:12:48+00:00',
  81. entries: [
  82. {
  83. type: 'message',
  84. message: 'bad stuff',
  85. data: {},
  86. },
  87. ],
  88. tags: [{key: 'browser', value: 'Firefox'}],
  89. },
  90. });
  91. });
  92. afterEach(function() {
  93. MockApiClient.clearMockResponses();
  94. });
  95. it('pagination cursor should be cleared when making a search', function() {
  96. const organization = TestStubs.Organization({
  97. features,
  98. projects: [TestStubs.Project()],
  99. });
  100. const initialData = initializeOrg({
  101. organization,
  102. router: {
  103. location: {query: {...generateFields(), cursor: '0%3A50%3A0'}},
  104. },
  105. });
  106. const wrapper = mountWithTheme(
  107. <Results
  108. organization={organization}
  109. location={initialData.router.location}
  110. router={initialData.router}
  111. />,
  112. initialData.routerContext
  113. );
  114. // ensure cursor query string is initially present in the location
  115. expect(initialData.router.location).toEqual({
  116. query: {
  117. ...generateFields(),
  118. cursor: '0%3A50%3A0',
  119. },
  120. });
  121. // perform a search
  122. const search = wrapper.find('#smart-search-input').first();
  123. search.simulate('change', {target: {value: 'geo:canada'}}).simulate('submit', {
  124. preventDefault() {},
  125. });
  126. // cursor query string should be omitted from the query string
  127. expect(initialData.router.push).toHaveBeenCalledWith({
  128. pathname: undefined,
  129. query: {
  130. ...generateFields(),
  131. query: 'geo:canada',
  132. statsPeriod: '14d',
  133. },
  134. });
  135. });
  136. });