miniGraph.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. project: 1,
  54. projects: [],
  55. });
  56. eventView = EventView.fromSavedQueryOrLocation(undefined, location);
  57. MockApiClient.clearMockResponses();
  58. MockApiClient.addMockResponse({
  59. url: '/organizations/org-slug/events-stats/',
  60. statusCode: 200,
  61. });
  62. });
  63. it('makes an EventsRequest with all selected multi y axis', function () {
  64. const yAxis = ['count()', 'failure_count()'];
  65. render(
  66. <MiniGraph
  67. location={location}
  68. eventView={eventView}
  69. organization={organization}
  70. yAxis={yAxis}
  71. />,
  72. {context: initialData.routerContext}
  73. );
  74. expect(eventRequest.default).toHaveBeenCalledWith(
  75. expect.objectContaining({yAxis}),
  76. expect.anything()
  77. );
  78. });
  79. it('uses low fidelity interval for bar charts', function () {
  80. const yAxis = ['count()', 'failure_count()'];
  81. eventView.display = 'bar';
  82. render(
  83. <MiniGraph
  84. location={location}
  85. eventView={eventView}
  86. organization={organization}
  87. yAxis={yAxis}
  88. />,
  89. {context: initialData.routerContext}
  90. );
  91. expect(eventRequest.default).toHaveBeenCalledWith(
  92. expect.objectContaining({interval: '12h'}),
  93. expect.anything()
  94. );
  95. });
  96. it('renders WorldMapChart', async function () {
  97. const yAxis = ['count()', 'failure_count()'];
  98. eventView.display = 'worldmap';
  99. jest.spyOn(worldMaps, 'WorldMapChart');
  100. render(
  101. <MiniGraph
  102. location={location}
  103. eventView={eventView}
  104. organization={organization}
  105. yAxis={yAxis}
  106. />,
  107. {context: initialData.routerContext}
  108. );
  109. await waitFor(() =>
  110. expect(worldMaps.WorldMapChart).toHaveBeenCalledWith(
  111. {
  112. height: 100,
  113. fromDiscoverQueryList: true,
  114. series: [
  115. {
  116. data: [
  117. {name: 'PE', value: 9215},
  118. {name: 'VI', value: 1},
  119. ],
  120. seriesName: 'Country',
  121. },
  122. ],
  123. },
  124. expect.anything()
  125. )
  126. );
  127. });
  128. });