eventDetailsHeader.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {EventsStatsFixture} from 'sentry-fixture/events';
  3. import {GroupFixture} from 'sentry-fixture/group';
  4. import {LocationFixture} from 'sentry-fixture/locationFixture';
  5. import {OrganizationFixture} from 'sentry-fixture/organization';
  6. import {ProjectFixture} from 'sentry-fixture/project';
  7. import {RouterFixture} from 'sentry-fixture/routerFixture';
  8. import {TagsFixture} from 'sentry-fixture/tags';
  9. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  10. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  11. import ProjectsStore from 'sentry/stores/projectsStore';
  12. import {EventDetailsHeader} from './eventDetailsHeader';
  13. const mockUseNavigate = jest.fn();
  14. jest.mock('sentry/utils/useNavigate', () => ({
  15. useNavigate: () => mockUseNavigate,
  16. }));
  17. describe('EventDetailsHeader', () => {
  18. const organization = OrganizationFixture();
  19. const project = ProjectFixture({
  20. environments: ['production', 'staging', 'development'],
  21. });
  22. const group = GroupFixture();
  23. const event = EventFixture({id: 'event-id'});
  24. const defaultProps = {group, event};
  25. const router = RouterFixture({
  26. location: LocationFixture({query: {streamline: '1'}}),
  27. });
  28. beforeEach(() => {
  29. MockApiClient.clearMockResponses();
  30. MockApiClient.addMockResponse({
  31. url: `/organizations/${organization.slug}/issues/${group.id}/tags/`,
  32. body: TagsFixture(),
  33. method: 'GET',
  34. });
  35. MockApiClient.addMockResponse({
  36. url: `/organizations/${organization.slug}/releases/stats/`,
  37. body: [],
  38. });
  39. PageFiltersStore.init();
  40. PageFiltersStore.onInitializeUrlState(
  41. {
  42. projects: [],
  43. environments: [],
  44. datetime: {start: null, end: null, period: '14d', utc: null},
  45. },
  46. new Set(['environments'])
  47. );
  48. ProjectsStore.loadInitialData([project]);
  49. MockApiClient.addMockResponse({
  50. url: `/organizations/${organization.slug}/events-stats/`,
  51. body: {'count()': EventsStatsFixture(), 'count_unique(user)': EventsStatsFixture()},
  52. method: 'GET',
  53. });
  54. MockApiClient.addMockResponse({
  55. url: `/organizations/${organization.slug}/events/`,
  56. body: {data: [{'count_unique(user)': 21}]},
  57. });
  58. });
  59. it('renders filters alongside the graph', async function () {
  60. render(<EventDetailsHeader {...defaultProps} />, {organization, router});
  61. expect(await screen.findByTestId('event-graph-loading')).not.toBeInTheDocument();
  62. expect(screen.getByRole('button', {name: 'All Envs'})).toBeInTheDocument();
  63. expect(screen.getByRole('button', {name: '14D'})).toBeInTheDocument();
  64. expect(screen.getByPlaceholderText('Filter events...')).toBeInTheDocument();
  65. expect(
  66. screen.getByRole('button', {
  67. name: 'Toggle graph series - Events',
  68. })
  69. ).toBeInTheDocument();
  70. expect(
  71. screen.getByRole('button', {name: 'Toggle graph series - Users'})
  72. ).toBeInTheDocument();
  73. expect(screen.getByRole('figure')).toBeInTheDocument();
  74. expect(screen.getByRole('button', {name: 'Close Sidebar'})).toBeInTheDocument();
  75. });
  76. it('updates the query params with search tokens', async function () {
  77. const [tagKey, tagValue] = ['user.email', 'leander.rodrigues@sentry.io'];
  78. const locationQuery = {
  79. query: {
  80. ...router.location.query,
  81. query: `${tagKey}:${tagValue}`,
  82. },
  83. };
  84. MockApiClient.addMockResponse({
  85. url: `/organizations/${organization.slug}/tags/${tagKey}/values/`,
  86. body: [
  87. {
  88. key: tagKey,
  89. name: tagValue,
  90. value: tagValue,
  91. },
  92. ],
  93. method: 'GET',
  94. });
  95. render(<EventDetailsHeader {...defaultProps} />, {organization, router});
  96. expect(await screen.findByTestId('event-graph-loading')).not.toBeInTheDocument();
  97. const search = screen.getByPlaceholderText('Filter events...');
  98. await userEvent.type(search, `${tagKey}:`);
  99. await userEvent.keyboard(`${tagValue}{enter}{enter}`);
  100. expect(mockUseNavigate).toHaveBeenCalledWith(expect.objectContaining(locationQuery), {
  101. replace: true,
  102. });
  103. });
  104. });