vitalCard.spec.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import VitalCard from 'sentry/views/insights/mobile/screens/components/vitalCard';
  3. describe('VitalCard', function () {
  4. const mockProps = {
  5. description: 'This is a test description',
  6. formattedValue: '123ms',
  7. status: 'good',
  8. statusLabel: 'Good',
  9. title: 'Test Vital',
  10. };
  11. it('renders correctly', function () {
  12. render(<VitalCard {...mockProps} />);
  13. expect(screen.getByText(mockProps.title)).toBeInTheDocument();
  14. expect(screen.getByText(mockProps.formattedValue)).toBeInTheDocument();
  15. expect(screen.getByText(mockProps.statusLabel)).toBeInTheDocument();
  16. });
  17. it('displays the description tooltip on hover', async function () {
  18. render(<VitalCard {...mockProps} />);
  19. await userEvent.hover(await screen.findByTestId('more-information'));
  20. expect(await screen.findByText(mockProps.description)).toBeInTheDocument();
  21. });
  22. it('displays default values when props are undefined', async function () {
  23. const defaultProps = {
  24. description: '',
  25. formattedValue: undefined,
  26. status: undefined,
  27. statusLabel: undefined,
  28. title: 'Default Vital',
  29. };
  30. render(<VitalCard {...defaultProps} />);
  31. expect(await screen.findByText(defaultProps.title)).toBeInTheDocument();
  32. expect(await screen.findAllByText('-')).toHaveLength(2);
  33. });
  34. });