index.spec.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
  5. import {act, render, screen} from 'sentry-test/reactTestingLibrary';
  6. import ProjectsStore from 'sentry/stores/projectsStore';
  7. import EventDetails from 'sentry/views/performance/transactionDetails';
  8. const alertText =
  9. 'You are viewing a sample transaction. Configure performance to start viewing real transactions.';
  10. describe('EventDetails', () => {
  11. const project = ProjectFixture();
  12. const organization = OrganizationFixture({
  13. features: ['performance-view'],
  14. projects: [project],
  15. });
  16. beforeEach(() => {
  17. ProjectsStore.loadInitialData([project]);
  18. MockApiClient.addMockResponse({
  19. url: `/organizations/${organization.slug}/projects/`,
  20. statusCode: 200,
  21. body: [],
  22. });
  23. MockApiClient.addMockResponse({
  24. url: `/projects/${organization.slug}/latest/events/1/grouping-info/`,
  25. statusCode: 200,
  26. body: {},
  27. });
  28. MockApiClient.addMockResponse({
  29. url: `/projects/${organization.slug}/latest/events/1/committers/`,
  30. statusCode: 200,
  31. body: [],
  32. });
  33. });
  34. afterEach(() => {
  35. ProjectsStore.reset();
  36. MockApiClient.clearMockResponses();
  37. });
  38. it('renders alert for sample transaction', async () => {
  39. const event = EventFixture();
  40. event.tags.push({key: 'sample_event', value: 'yes'});
  41. MockApiClient.addMockResponse({
  42. url: `/organizations/${organization.slug}/events/latest/`,
  43. statusCode: 200,
  44. body: {
  45. ...event,
  46. },
  47. });
  48. render(
  49. <EventDetails {...RouteComponentPropsFixture({params: {eventSlug: 'latest'}})} />,
  50. {organization}
  51. );
  52. expect(await screen.findByText(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 {...RouteComponentPropsFixture({params: {eventSlug: 'latest'}})} />,
  67. {organization}
  68. );
  69. expect(screen.queryByText(alertText)).not.toBeInTheDocument();
  70. // Expect stores to be updated
  71. await act(tick);
  72. });
  73. });