miniGraph.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import MiniGraph from 'sentry/views/eventsV2/miniGraph';
  5. jest.mock('sentry/components/charts/eventsGeoRequest', () =>
  6. jest.fn(({children}) =>
  7. children({
  8. errored: false,
  9. loading: false,
  10. reloading: false,
  11. tableData: [
  12. {
  13. data: [
  14. {
  15. 'geo.country_code': 'PE',
  16. count: 9215,
  17. },
  18. {
  19. 'geo.country_code': 'VI',
  20. count: 1,
  21. },
  22. ],
  23. meta: {
  24. 'geo.country_code': 'string',
  25. count: 'integer',
  26. },
  27. title: 'Country',
  28. },
  29. ],
  30. })
  31. )
  32. );
  33. describe('EventsV2 > MiniGraph', function () {
  34. const features = ['discover-basic'];
  35. const location = TestStubs.location({
  36. query: {query: 'tag:value'},
  37. pathname: '/',
  38. });
  39. let organization, eventView, initialData;
  40. beforeEach(() => {
  41. organization = TestStubs.Organization({
  42. features,
  43. projects: [TestStubs.Project()],
  44. });
  45. initialData = initializeOrg({
  46. organization,
  47. router: {
  48. location,
  49. },
  50. project: 1,
  51. projects: [],
  52. });
  53. eventView = EventView.fromSavedQueryOrLocation(undefined, location);
  54. MockApiClient.clearMockResponses();
  55. MockApiClient.addMockResponse({
  56. url: '/organizations/org-slug/events-stats/',
  57. statusCode: 200,
  58. });
  59. });
  60. it('makes an EventsRequest with all selected multi y axis', function () {
  61. const yAxis = ['count()', 'failure_count()'];
  62. const wrapper = mountWithTheme(
  63. <MiniGraph
  64. location={location}
  65. eventView={eventView}
  66. organization={organization}
  67. yAxis={yAxis}
  68. />,
  69. initialData.routerContext
  70. );
  71. const eventsRequestProps = wrapper.find('EventsRequest').props();
  72. expect(eventsRequestProps.yAxis).toEqual(yAxis);
  73. });
  74. it('uses low fidelity interval for bar charts', function () {
  75. const yAxis = ['count()', 'failure_count()'];
  76. eventView.display = 'bar';
  77. const wrapper = mountWithTheme(
  78. <MiniGraph
  79. location={location}
  80. eventView={eventView}
  81. organization={organization}
  82. yAxis={yAxis}
  83. />,
  84. initialData.routerContext
  85. );
  86. const eventsRequestProps = wrapper.find('EventsRequest').props();
  87. expect(eventsRequestProps.interval).toEqual('12h');
  88. });
  89. it('renders WorldMapChart', function () {
  90. const yAxis = ['count()', 'failure_count()'];
  91. eventView.display = 'worldmap';
  92. const wrapper = mountWithTheme(
  93. <MiniGraph
  94. location={location}
  95. eventView={eventView}
  96. organization={organization}
  97. yAxis={yAxis}
  98. />,
  99. initialData.routerContext
  100. );
  101. const worldMapChartProps = wrapper.find('WorldMapChart').props();
  102. expect(worldMapChartProps.series).toEqual([
  103. {
  104. data: [
  105. {name: 'PE', value: 9215},
  106. {name: 'VI', value: 1},
  107. ],
  108. seriesName: 'Country',
  109. },
  110. ]);
  111. });
  112. it('renders error message', async function () {
  113. const errorMessage = 'something went wrong';
  114. const api = new MockApiClient();
  115. MockApiClient.clearMockResponses();
  116. MockApiClient.addMockResponse({
  117. url: '/organizations/org-slug/events-stats/',
  118. body: {
  119. detail: errorMessage,
  120. },
  121. statusCode: 400,
  122. });
  123. const wrapper = mountWithTheme(
  124. <MiniGraph
  125. location={location}
  126. eventView={eventView}
  127. organization={organization}
  128. api={api}
  129. />,
  130. initialData.routerContext
  131. );
  132. await tick();
  133. wrapper.update();
  134. expect(wrapper.find('MiniGraph').text()).toBe(errorMessage);
  135. });
  136. });