eventViewHierarchy.spec.tsx 2.9 KB

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