index.spec.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {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', () => {
  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: `/organizations/${organization.slug}/events/latest/`,
  21. statusCode: 200,
  22. body: {
  23. ...event,
  24. },
  25. });
  26. MockApiClient.warnOnMissingMocks();
  27. render(
  28. <OrganizationContext.Provider value={organization}>
  29. <EventDetails
  30. organization={organization}
  31. params={{orgId: organization.slug, eventSlug: 'latest'}}
  32. location={routerContext.context.location}
  33. />
  34. </OrganizationContext.Provider>
  35. );
  36. expect(screen.getByText(alertText)).toBeInTheDocument();
  37. });
  38. it('does not reender alert if already received transaction', () => {
  39. const project = TestStubs.Project();
  40. ProjectsStore.loadInitialData([project]);
  41. const organization = TestStubs.Organization({
  42. features: ['performance-view'],
  43. projects: [project],
  44. });
  45. const event = TestStubs.Event();
  46. const routerContext = TestStubs.routerContext([]);
  47. MockApiClient.addMockResponse({
  48. url: `/organizations/${organization.slug}/events/latest/`,
  49. statusCode: 200,
  50. body: {
  51. ...event,
  52. },
  53. });
  54. MockApiClient.warnOnMissingMocks();
  55. render(
  56. <OrganizationContext.Provider value={organization}>
  57. <EventDetails
  58. organization={organization}
  59. params={{orgId: organization.slug, eventSlug: 'latest'}}
  60. location={routerContext.context.location}
  61. />
  62. </OrganizationContext.Provider>
  63. );
  64. expect(screen.queryByText(alertText)).not.toBeInTheDocument();
  65. });
  66. });