miniGraph.spec.tsx 3.9 KB

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