actorAvatar.spec.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {Team} from 'sentry-fixture/team';
  3. import {User} from 'sentry-fixture/user';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import ActorAvatar from 'sentry/components/avatar/actorAvatar';
  6. import MemberListStore from 'sentry/stores/memberListStore';
  7. import OrganizationStore from 'sentry/stores/organizationStore';
  8. import TeamStore from 'sentry/stores/teamStore';
  9. import type {Team as TeamType, User as UserType} from 'sentry/types';
  10. describe('ActorAvatar', function () {
  11. const user: UserType = {
  12. ...User(),
  13. id: '1',
  14. name: 'JanActore Bloggs',
  15. email: 'janebloggs@example.com',
  16. };
  17. const team1: TeamType = {
  18. ...Team(),
  19. id: '3',
  20. slug: 'cool-team',
  21. name: 'COOL TEAM',
  22. };
  23. beforeEach(function () {
  24. MemberListStore.loadInitialData([user]);
  25. TeamStore.loadInitialData([team1]);
  26. });
  27. it('should show a gravatar when actor type is a user', function () {
  28. render(
  29. <ActorAvatar
  30. actor={{
  31. id: '1',
  32. name: 'Jane Bloggs',
  33. type: 'user',
  34. }}
  35. />
  36. );
  37. });
  38. it('should not show a gravatar when actor type is a team', function () {
  39. render(
  40. <ActorAvatar
  41. actor={{
  42. id: '3',
  43. name: 'COOL TEAM',
  44. type: 'team',
  45. }}
  46. />
  47. );
  48. expect(screen.getByText('CT')).toBeInTheDocument();
  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 = Organization();
  65. OrganizationStore.onUpdate(organization, {replace: true});
  66. const team2 = 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. expect(await screen.findByText('CT')).toBeInTheDocument();
  82. expect(mockRequest).toHaveBeenCalled();
  83. });
  84. });