index.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {Event as EventFixture} from 'sentry-fixture/event';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {act, render, screen} from 'sentry-test/reactTestingLibrary';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import EventDetails from 'sentry/views/performance/transactionDetails';
  6. const alertText =
  7. 'You are viewing a sample transaction. Configure performance to start viewing real transactions.';
  8. describe('EventDetails', () => {
  9. const project = TestStubs.Project();
  10. const organization = Organization({
  11. features: ['performance-view'],
  12. projects: [project],
  13. });
  14. beforeEach(() => {
  15. ProjectsStore.loadInitialData([project]);
  16. MockApiClient.addMockResponse({
  17. url: `/organizations/${organization.slug}/projects/`,
  18. statusCode: 200,
  19. body: [],
  20. });
  21. MockApiClient.addMockResponse({
  22. url: `/projects/${organization.slug}/latest/events/1/grouping-info/`,
  23. statusCode: 200,
  24. body: {},
  25. });
  26. MockApiClient.addMockResponse({
  27. url: `/projects/${organization.slug}/latest/events/1/committers/`,
  28. statusCode: 200,
  29. body: [],
  30. });
  31. });
  32. afterEach(() => {
  33. ProjectsStore.reset();
  34. MockApiClient.clearMockResponses();
  35. });
  36. it('renders alert for sample transaction', async () => {
  37. const event = EventFixture();
  38. event.tags.push({key: 'sample_event', value: 'yes'});
  39. MockApiClient.addMockResponse({
  40. url: `/organizations/${organization.slug}/events/latest/`,
  41. statusCode: 200,
  42. body: {
  43. ...event,
  44. },
  45. });
  46. render(
  47. <EventDetails
  48. {...TestStubs.routeComponentProps({params: {eventSlug: 'latest'}})}
  49. />,
  50. {organization}
  51. );
  52. expect(screen.getByText(alertText)).toBeInTheDocument();
  53. // Expect stores to be updated
  54. await act(tick);
  55. });
  56. it('does not reender alert if already received transaction', async () => {
  57. const event = EventFixture();
  58. MockApiClient.addMockResponse({
  59. url: `/organizations/${organization.slug}/events/latest/`,
  60. statusCode: 200,
  61. body: {
  62. ...event,
  63. },
  64. });
  65. render(
  66. <EventDetails
  67. {...TestStubs.routeComponentProps({params: {eventSlug: 'latest'}})}
  68. />,
  69. {organization}
  70. );
  71. expect(screen.queryByText(alertText)).not.toBeInTheDocument();
  72. // Expect stores to be updated
  73. await act(tick);
  74. });
  75. });