eventViewHierarchy.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {EventAttachmentFixture} from 'sentry-fixture/eventAttachment';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import {EventViewHierarchy} from './eventViewHierarchy';
  7. // Mocks for useVirtualizedTree hook
  8. class ResizeObserver {
  9. observe() {}
  10. unobserve() {}
  11. disconnect() {}
  12. }
  13. window.ResizeObserver = ResizeObserver;
  14. window.Element.prototype.scrollTo = jest.fn();
  15. const DEFAULT_VALUES = {alpha: 1, height: 1, width: 1, x: 1, y: 1, visible: true};
  16. const MOCK_DATA = JSON.stringify({
  17. rendering_system: 'test-rendering-system',
  18. windows: [
  19. {
  20. ...DEFAULT_VALUES,
  21. id: 'parent',
  22. type: 'Container',
  23. identifier: 'test_identifier',
  24. x: 200,
  25. children: [
  26. {
  27. ...DEFAULT_VALUES,
  28. id: 'intermediate',
  29. type: 'Nested Container',
  30. identifier: 'nested',
  31. children: [
  32. {
  33. ...DEFAULT_VALUES,
  34. id: 'leaf',
  35. type: 'Text',
  36. children: [],
  37. },
  38. ],
  39. },
  40. ],
  41. },
  42. ],
  43. });
  44. const organization = OrganizationFixture({
  45. features: ['event-attachments'],
  46. });
  47. const event = EventFixture();
  48. describe('Event View Hierarchy', function () {
  49. let mockAttachment;
  50. let mockProject;
  51. beforeEach(function () {
  52. mockAttachment = EventAttachmentFixture({type: 'event.view_hierarchy'});
  53. mockProject = ProjectFixture();
  54. MockApiClient.addMockResponse({
  55. url: `/projects/${organization.slug}/${mockProject.slug}/events/${event.id}/attachments/`,
  56. body: [mockAttachment],
  57. });
  58. MockApiClient.addMockResponse({
  59. url: `/projects/${organization.slug}/${mockProject.slug}/events/${mockAttachment.event_id}/attachments/${mockAttachment.id}/?download`,
  60. body: MOCK_DATA,
  61. });
  62. });
  63. it('renders nothing when no view_hierarchy attachments', async () => {
  64. MockApiClient.clearMockResponses();
  65. MockApiClient.addMockResponse({
  66. url: `/projects/org-slug/${mockProject.slug}/events/${event.id}/attachments/`,
  67. body: [EventAttachmentFixture()],
  68. });
  69. const {container} = render(
  70. <EventViewHierarchy project={mockProject} event={event} />,
  71. {
  72. organization,
  73. }
  74. );
  75. // No loading state so nothing to wait for
  76. await tick();
  77. expect(container).toBeEmptyDOMElement();
  78. });
  79. it('does not collapse all nodes when update triggers re-render', async function () {
  80. const {rerender} = render(
  81. <EventViewHierarchy project={mockProject} event={event} />,
  82. {
  83. organization,
  84. }
  85. );
  86. expect(await screen.findByText('Nested Container - nested')).toBeInTheDocument();
  87. rerender(<EventViewHierarchy project={mockProject} event={event} />);
  88. expect(await screen.findByText('Nested Container - nested')).toBeInTheDocument();
  89. });
  90. });