miniGraph.spec.tsx 3.4 KB

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