platformList.spec.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import PlatformList from 'sentry/components/platformList';
  3. import type {PlatformKey} from 'sentry/types';
  4. describe('PlatformList', function () {
  5. const platforms: PlatformKey[] = ['java', 'php', 'javascript', 'cocoa-swift', 'ruby'];
  6. it('renders max of three icons from platforms', function () {
  7. render(<PlatformList platforms={platforms} />);
  8. expect(screen.getAllByRole('img')).toHaveLength(3);
  9. });
  10. it('renders default if no platforms', function () {
  11. render(<PlatformList platforms={[]} />);
  12. expect(screen.getByRole('img')).toBeInTheDocument();
  13. });
  14. it('displays counter', async function () {
  15. render(<PlatformList platforms={platforms} showCounter />);
  16. const icons = screen.getAllByRole('img');
  17. expect(icons).toHaveLength(3);
  18. // Check tooltip content,
  19. const extra = screen.getByText('2');
  20. await userEvent.hover(extra);
  21. expect(await screen.findByText('2 other platforms')).toBeInTheDocument();
  22. });
  23. it('displays counter according to the max value', function () {
  24. const max = 2;
  25. render(<PlatformList platforms={platforms} max={max} showCounter />);
  26. const icons = screen.getAllByRole('img');
  27. expect(icons).toHaveLength(max);
  28. const extraCounter = platforms.length - max;
  29. expect(screen.getByText(extraCounter)).toBeInTheDocument();
  30. });
  31. });