vitalCard.spec.tsx 1.4 KB

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