miniGraph.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render} from 'sentry-test/reactTestingLibrary';
  3. import * as eventRequest from 'sentry/components/charts/eventsRequest';
  4. import EventView from 'sentry/utils/discover/eventView';
  5. import MiniGraph from 'sentry/views/discover/miniGraph';
  6. jest.mock('sentry/components/charts/eventsRequest');
  7. jest.mock('sentry/components/charts/eventsGeoRequest', () =>
  8. jest.fn(({children}) =>
  9. children({
  10. errored: false,
  11. loading: false,
  12. reloading: false,
  13. tableData: [
  14. {
  15. data: [
  16. {
  17. 'geo.country_code': 'PE',
  18. count: 9215,
  19. },
  20. {
  21. 'geo.country_code': 'VI',
  22. count: 1,
  23. },
  24. ],
  25. meta: {
  26. 'geo.country_code': 'string',
  27. count: 'integer',
  28. },
  29. title: 'Country',
  30. },
  31. ],
  32. })
  33. )
  34. );
  35. describe('Discover > MiniGraph', function () {
  36. const features = ['discover-basic'];
  37. const location = TestStubs.location({
  38. query: {query: 'tag:value'},
  39. pathname: '/',
  40. });
  41. let organization, eventView, initialData;
  42. beforeEach(() => {
  43. organization = TestStubs.Organization({
  44. features,
  45. projects: [TestStubs.Project()],
  46. });
  47. initialData = initializeOrg({
  48. organization,
  49. router: {
  50. location,
  51. },
  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. render(
  64. <MiniGraph
  65. location={location}
  66. eventView={eventView}
  67. organization={organization}
  68. yAxis={yAxis}
  69. />,
  70. {context: initialData.routerContext}
  71. );
  72. expect(eventRequest.default).toHaveBeenCalledWith(
  73. expect.objectContaining({yAxis}),
  74. expect.anything()
  75. );
  76. });
  77. it('uses low fidelity interval for bar charts', function () {
  78. const yAxis = ['count()', 'failure_count()'];
  79. eventView.display = 'bar';
  80. render(
  81. <MiniGraph
  82. location={location}
  83. eventView={eventView}
  84. organization={organization}
  85. yAxis={yAxis}
  86. />,
  87. {context: initialData.routerContext}
  88. );
  89. expect(eventRequest.default).toHaveBeenCalledWith(
  90. expect.objectContaining({interval: '12h'}),
  91. expect.anything()
  92. );
  93. });
  94. });