eventDetailsHeader.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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, project};
  25. const router = RouterFixture({
  26. location: LocationFixture({query: {streamline: '1'}}),
  27. });
  28. beforeEach(() => {
  29. MockApiClient.clearMockResponses();
  30. MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/flags/logs/',
  32. body: {data: []},
  33. });
  34. MockApiClient.addMockResponse({
  35. url: `/organizations/${organization.slug}/issues/${group.id}/tags/`,
  36. body: TagsFixture(),
  37. method: 'GET',
  38. });
  39. MockApiClient.addMockResponse({
  40. url: `/organizations/${organization.slug}/releases/stats/`,
  41. body: [],
  42. });
  43. PageFiltersStore.init();
  44. PageFiltersStore.onInitializeUrlState(
  45. {
  46. projects: [],
  47. environments: [],
  48. datetime: {start: null, end: null, period: '14d', utc: null},
  49. },
  50. new Set(['environments'])
  51. );
  52. ProjectsStore.loadInitialData([project]);
  53. MockApiClient.addMockResponse({
  54. url: `/organizations/${organization.slug}/events-stats/`,
  55. body: {'count()': EventsStatsFixture(), 'count_unique(user)': EventsStatsFixture()},
  56. method: 'GET',
  57. });
  58. MockApiClient.addMockResponse({
  59. url: `/organizations/${organization.slug}/events/`,
  60. body: {data: [{'count_unique(user)': 21}]},
  61. });
  62. });
  63. it('renders filters alongside the graph', async function () {
  64. render(<EventDetailsHeader {...defaultProps} />, {organization, router});
  65. expect(await screen.findByTestId('event-graph-loading')).not.toBeInTheDocument();
  66. expect(screen.getByRole('button', {name: 'All Envs'})).toBeInTheDocument();
  67. expect(screen.getByRole('button', {name: '14D'})).toBeInTheDocument();
  68. expect(screen.getByPlaceholderText('Filter events\u2026')).toBeInTheDocument();
  69. expect(
  70. screen.getByRole('button', {
  71. name: 'Toggle graph series - Events',
  72. })
  73. ).toBeInTheDocument();
  74. expect(
  75. screen.getByRole('button', {name: 'Toggle graph series - Users'})
  76. ).toBeInTheDocument();
  77. expect(screen.getByRole('figure')).toBeInTheDocument();
  78. expect(screen.getByRole('button', {name: 'Close sidebar'})).toBeInTheDocument();
  79. });
  80. it('updates the query params with search tokens', async function () {
  81. const [tagKey, tagValue] = ['user.email', 'leander.rodrigues@sentry.io'];
  82. const locationQuery = {
  83. query: {
  84. ...router.location.query,
  85. query: `${tagKey}:${tagValue}`,
  86. },
  87. };
  88. MockApiClient.addMockResponse({
  89. url: `/organizations/${organization.slug}/tags/${tagKey}/values/`,
  90. body: [
  91. {
  92. key: tagKey,
  93. name: tagValue,
  94. value: tagValue,
  95. },
  96. ],
  97. method: 'GET',
  98. });
  99. render(<EventDetailsHeader {...defaultProps} />, {organization, router});
  100. expect(await screen.findByTestId('event-graph-loading')).not.toBeInTheDocument();
  101. const search = screen.getByPlaceholderText('Filter events\u2026');
  102. await userEvent.type(search, `${tagKey}:`);
  103. await userEvent.keyboard(`${tagValue}{enter}{enter}`);
  104. expect(mockUseNavigate).toHaveBeenCalledWith(expect.objectContaining(locationQuery), {
  105. replace: true,
  106. });
  107. });
  108. });