actorAvatar.spec.jsx 2.5 KB

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