avatarList.spec.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import AvatarList from 'sentry/components/avatar/avatarList';
  3. function renderComponent(
  4. avatarUsersSixUsers: React.ComponentProps<typeof AvatarList>['users']
  5. ) {
  6. return render(<AvatarList users={avatarUsersSixUsers} />);
  7. }
  8. describe('AvatarList', () => {
  9. const user = TestStubs.User();
  10. it('renders with user letter avatars', () => {
  11. const users = [
  12. {...user, id: '1', name: 'AB'},
  13. {...user, id: '2', name: 'BC'},
  14. ];
  15. const {container} = renderComponent(users);
  16. expect(screen.getByText('A')).toBeInTheDocument();
  17. expect(screen.getByText('B')).toBeInTheDocument();
  18. expect(screen.queryByTestId('avatarList-collapsedusers')).not.toBeInTheDocument();
  19. expect(container).toSnapshot();
  20. });
  21. it('renders with collapsed avatar count if > 5 users', () => {
  22. const users = [
  23. {...user, id: '1', name: 'AB'},
  24. {...user, id: '2', name: 'BC'},
  25. {...user, id: '3', name: 'CD'},
  26. {...user, id: '4', name: 'DE'},
  27. {...user, id: '5', name: 'EF'},
  28. {...user, id: '6', name: 'FG'},
  29. ];
  30. const {container} = renderComponent(users);
  31. expect(screen.getByText(users[0].name.charAt(0))).toBeInTheDocument();
  32. expect(screen.getByText(users[1].name.charAt(0))).toBeInTheDocument();
  33. expect(screen.getByText(users[2].name.charAt(0))).toBeInTheDocument();
  34. expect(screen.getByText(users[3].name.charAt(0))).toBeInTheDocument();
  35. expect(screen.getByText(users[4].name.charAt(0))).toBeInTheDocument();
  36. expect(screen.queryByText(users[5].name.charAt(0))).not.toBeInTheDocument();
  37. expect(screen.getByTestId('avatarList-collapsedusers')).toBeInTheDocument();
  38. expect(container).toSnapshot();
  39. });
  40. });