detailsPanel.spec.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import {DetailsPanel} from './detailsPanel';
  3. const DEFAULT_VALUES = {alpha: 1, height: 1, width: 1, x: 1, y: 1, visible: true};
  4. const MOCK_DATA = {
  5. ...DEFAULT_VALUES,
  6. identifier: 'parent',
  7. type: 'Container',
  8. x: 200,
  9. y: 201,
  10. width: 202,
  11. height: 203,
  12. children: [
  13. {
  14. ...DEFAULT_VALUES,
  15. identifier: 'intermediate',
  16. type: 'Nested Container',
  17. children: [
  18. {
  19. ...DEFAULT_VALUES,
  20. identifier: 'leaf',
  21. type: 'Text',
  22. children: [],
  23. },
  24. ],
  25. },
  26. ],
  27. };
  28. describe('View Hierarchy Details Panel', function () {
  29. it('omits children from rendered data', function () {
  30. render(<DetailsPanel data={MOCK_DATA} />);
  31. expect(screen.getByRole('cell', {name: '200'})).toBeInTheDocument();
  32. expect(screen.getByRole('cell', {name: '201'})).toBeInTheDocument();
  33. expect(screen.getByRole('cell', {name: '202'})).toBeInTheDocument();
  34. expect(screen.getByRole('cell', {name: '203'})).toBeInTheDocument();
  35. expect(screen.queryByRole('cell', {name: 'children'})).not.toBeInTheDocument();
  36. });
  37. it('accepts a custom title renderer', function () {
  38. const testGetTitle = jest.fn().mockImplementation(data => {
  39. return `${data.type} - ${data.identifier}`;
  40. });
  41. render(<DetailsPanel data={MOCK_DATA} getTitle={testGetTitle} />);
  42. expect(testGetTitle).toHaveBeenCalled();
  43. expect(screen.getByText('Container - parent')).toBeInTheDocument();
  44. });
  45. });