index.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. });
  15. beforeEach(() => {
  16. ProjectsStore.loadInitialData([project]);
  17. MockApiClient.addMockResponse({
  18. url: `/organizations/${organization.slug}/projects/`,
  19. statusCode: 200,
  20. body: [],
  21. });
  22. MockApiClient.addMockResponse({
  23. url: `/projects/${organization.slug}/latest/events/1/grouping-info/`,
  24. statusCode: 200,
  25. body: {},
  26. });
  27. MockApiClient.addMockResponse({
  28. url: `/projects/${organization.slug}/latest/events/1/committers/`,
  29. statusCode: 200,
  30. body: [],
  31. });
  32. MockApiClient.addMockResponse({
  33. url: `/projects/${organization.slug}/latest/events/1/actionable-items/`,
  34. body: {
  35. errors: [],
  36. },
  37. });
  38. });
  39. afterEach(() => {
  40. ProjectsStore.reset();
  41. MockApiClient.clearMockResponses();
  42. });
  43. it('renders alert for sample transaction', async () => {
  44. const event = EventFixture();
  45. event.tags.push({key: 'sample_event', value: 'yes'});
  46. MockApiClient.addMockResponse({
  47. url: `/organizations/${organization.slug}/events/latest/`,
  48. statusCode: 200,
  49. body: {
  50. ...event,
  51. },
  52. });
  53. render(
  54. <EventDetails {...RouteComponentPropsFixture({params: {eventSlug: 'latest'}})} />,
  55. {organization}
  56. );
  57. expect(await screen.findByText(alertText)).toBeInTheDocument();
  58. // Expect stores to be updated
  59. await act(tick);
  60. });
  61. it('does not reender alert if already received transaction', async () => {
  62. const event = EventFixture();
  63. MockApiClient.addMockResponse({
  64. url: `/organizations/${organization.slug}/events/latest/`,
  65. statusCode: 200,
  66. body: {
  67. ...event,
  68. },
  69. });
  70. render(
  71. <EventDetails {...RouteComponentPropsFixture({params: {eventSlug: 'latest'}})} />,
  72. {organization}
  73. );
  74. expect(screen.queryByText(alertText)).not.toBeInTheDocument();
  75. // Expect stores to be updated
  76. await act(tick);
  77. });
  78. });