index.spec.tsx 2.6 KB

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