participantList.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {TeamFixture} from 'sentry-fixture/team';
  2. import {UserFixture} from 'sentry-fixture/user';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import ParticipantList from 'sentry/views/issueDetails/streamline/sidebar/participantList';
  5. describe('ParticipantList', () => {
  6. const users = [
  7. UserFixture({
  8. id: '1',
  9. name: 'John Doe',
  10. email: 'john.doe@example.com',
  11. lastSeen: '2024-01-01T00:00:00.000Z',
  12. }),
  13. UserFixture({
  14. id: '2',
  15. name: 'Bob Alice',
  16. email: 'bob.alice@example.com',
  17. lastSeen: '2024-01-02T00:00:00.000Z',
  18. }),
  19. ];
  20. const teams = [
  21. TeamFixture({id: '1', slug: 'team-1', memberCount: 3}),
  22. TeamFixture({id: '2', slug: 'team-2', memberCount: 5}),
  23. ];
  24. it('expands and collapses the list when clicked', async () => {
  25. render(<ParticipantList teams={teams} users={users} />);
  26. expect(screen.queryByText('#team-1')).not.toBeInTheDocument();
  27. await userEvent.click(screen.getByText('JD'), {skipHover: true});
  28. expect(await screen.findByText('#team-1')).toBeInTheDocument();
  29. expect(await screen.findByText('Bob Alice')).toBeInTheDocument();
  30. expect(screen.getByText('Teams (2)')).toBeInTheDocument();
  31. expect(screen.getByText('Individuals (2)')).toBeInTheDocument();
  32. await userEvent.click(screen.getAllByText('JD')[0]!, {skipHover: true});
  33. expect(screen.queryByText('Bob Alice')).not.toBeInTheDocument();
  34. });
  35. it('does not display section headers when there is only users or teams', async () => {
  36. render(<ParticipantList users={users} />);
  37. await userEvent.click(screen.getByText('JD'), {skipHover: true});
  38. expect(await screen.findByText('Bob Alice')).toBeInTheDocument();
  39. expect(screen.queryByText('Teams')).not.toBeInTheDocument();
  40. });
  41. it('skips duplicate information between name and email', async () => {
  42. const duplicateInfoUsers = [
  43. UserFixture({id: '1', name: 'john.doe@example.com', email: 'john.doe@example.com'}),
  44. ];
  45. render(<ParticipantList users={duplicateInfoUsers} />);
  46. await userEvent.click(screen.getByText('J'), {skipHover: true});
  47. // Would find two elements if it was duplicated
  48. expect(await screen.findByText('john.doe@example.com')).toBeInTheDocument();
  49. });
  50. it('displays information about last seen, if available', async () => {
  51. render(<ParticipantList users={users} teams={teams} />);
  52. await userEvent.click(screen.getByText('JD'), {skipHover: true});
  53. expect(await screen.findByText('John Doe')).toBeInTheDocument();
  54. expect(await screen.findByText('Jan 1, 2024 12:00 AM')).toBeInTheDocument();
  55. expect(await screen.findByText('Bob Alice')).toBeInTheDocument();
  56. expect(await screen.findByText('Jan 2, 2024 12:00 AM')).toBeInTheDocument();
  57. // Still display teams/users without timestamps
  58. expect(await screen.findByText('#team-1')).toBeInTheDocument();
  59. expect(await screen.findByText('#team-2')).toBeInTheDocument();
  60. });
  61. });