avatarList.spec.tsx 1.7 KB

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