actorAvatar.spec.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import ActorAvatar from 'sentry/components/avatar/actorAvatar';
  3. import MemberListStore from 'sentry/stores/memberListStore';
  4. import OrganizationStore from 'sentry/stores/organizationStore';
  5. import TeamStore from 'sentry/stores/teamStore';
  6. import {Team, User} from 'sentry/types';
  7. describe('ActorAvatar', function () {
  8. const user: User = {
  9. ...TestStubs.User(),
  10. id: '1',
  11. name: 'JanActore Bloggs',
  12. email: 'janebloggs@example.com',
  13. };
  14. const team1: Team = {
  15. ...TestStubs.Team(),
  16. id: '3',
  17. slug: 'cool-team',
  18. name: 'COOL TEAM',
  19. };
  20. beforeEach(function () {
  21. MemberListStore.loadInitialData([user]);
  22. TeamStore.loadInitialData([team1]);
  23. });
  24. describe('render()', function () {
  25. it('should show a gravatar when actor type is a user', function () {
  26. const {container} = render(
  27. <ActorAvatar
  28. actor={{
  29. id: '1',
  30. name: 'Jane Bloggs',
  31. type: 'user',
  32. }}
  33. />
  34. );
  35. expect(container).toSnapshot();
  36. });
  37. it('should not show a gravatar when actor type is a team', function () {
  38. const {container} = render(
  39. <ActorAvatar
  40. actor={{
  41. id: '3',
  42. name: 'COOL TEAM',
  43. type: 'team',
  44. }}
  45. />
  46. );
  47. expect(screen.getByText('CT')).toBeInTheDocument();
  48. expect(container).toSnapshot();
  49. });
  50. it('should return null when actor type is a unknown', function () {
  51. render(
  52. <ActorAvatar
  53. actor={{
  54. id: '3',
  55. name: 'COOL TEAM',
  56. // @ts-expect-error (type shall be incorrect here)
  57. type: 'teapot',
  58. }}
  59. />
  60. );
  61. expect(screen.queryByText('CT')).not.toBeInTheDocument();
  62. });
  63. it('should fetch a team not in the store', async function () {
  64. const organization = TestStubs.Organization();
  65. OrganizationStore.onUpdate(organization, {replace: true});
  66. const team2 = TestStubs.Team({id: '2', name: 'COOL TEAM', slug: 'cool-team'});
  67. const mockRequest = MockApiClient.addMockResponse({
  68. url: `/organizations/${organization.slug}/teams/`,
  69. method: 'GET',
  70. body: [team2],
  71. });
  72. render(
  73. <ActorAvatar
  74. actor={{
  75. id: team2.id,
  76. name: team2.name,
  77. type: 'team',
  78. }}
  79. />
  80. );
  81. await waitFor(() => expect(mockRequest).toHaveBeenCalled());
  82. expect(screen.getByText('CT')).toBeInTheDocument();
  83. });
  84. });
  85. });