index.spec.jsx 2.8 KB

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