vitalDetailPanel.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  3. import {PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  4. import {
  5. PerformanceScore,
  6. type VitalItem,
  7. type VitalStatus,
  8. } from 'sentry/views/insights/mobile/screens/utils';
  9. import {VitalDetailPanel} from './vitalDetailPanel';
  10. jest.mock('sentry/views/insights/mobile/common/queries/useCrossPlatformProject', () => ({
  11. __esModule: true,
  12. default: () => ({selectedPlatform: 'Android'}),
  13. }));
  14. const mockStatus: VitalStatus = {
  15. formattedValue: '100ms',
  16. score: PerformanceScore.GOOD,
  17. description: 'Good performance',
  18. value: {
  19. type: 'duration',
  20. unit: 'ms',
  21. value: 100,
  22. },
  23. };
  24. const mockVital: VitalItem = {
  25. title: 'title',
  26. description: 'description',
  27. docs: 'docs',
  28. setup: 'setup',
  29. platformDocLinks: {
  30. Android: 'https://example.com/platform-docs',
  31. },
  32. sdkDocLinks: {
  33. Android: 'https://example.com/sdk-docs',
  34. },
  35. field: 'avg(measurements.app_start_cold)',
  36. dataset: DiscoverDatasets.METRICS,
  37. getStatus: () => mockStatus,
  38. };
  39. describe('VitalDetailPanel', () => {
  40. test('renders correctly with given props', () => {
  41. render(
  42. <PageAlertProvider>
  43. <VitalDetailPanel vital={mockVital} status={mockStatus} onClose={jest.fn()} />
  44. </PageAlertProvider>
  45. );
  46. expect(screen.getByText('title')).toBeInTheDocument();
  47. expect(screen.getByText('100ms')).toBeInTheDocument();
  48. expect(screen.getByText('Good performance')).toBeInTheDocument();
  49. expect(screen.getByText('docs')).toBeInTheDocument();
  50. expect(screen.getByText('setup')).toBeInTheDocument();
  51. expect(screen.getByText('Sentry SDK documentation')).toHaveAttribute(
  52. 'href',
  53. 'https://example.com/sdk-docs'
  54. );
  55. expect(screen.getByText('Platform documentation')).toHaveAttribute(
  56. 'href',
  57. 'https://example.com/platform-docs'
  58. );
  59. });
  60. test('calls onClose when close action is triggered', async () => {
  61. const onCloseMock = jest.fn();
  62. render(
  63. <PageAlertProvider>
  64. <VitalDetailPanel vital={mockVital} status={mockStatus} onClose={onCloseMock} />
  65. </PageAlertProvider>
  66. );
  67. const closeButton = screen.getByLabelText('Close Details');
  68. await userEvent.click(closeButton);
  69. expect(onCloseMock).toHaveBeenCalled();
  70. });
  71. });