actorAvatar.spec.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React from 'react';
  2. import {mountWithTheme, mount} from 'sentry-test/enzyme';
  3. import ActorAvatar from 'app/components/avatar/actorAvatar';
  4. import MemberListStore from 'app/stores/memberListStore';
  5. import TeamStore from 'app/stores/teamStore';
  6. describe('ActorAvatar', function () {
  7. const USER = {
  8. id: '1',
  9. name: 'JanActore Bloggs',
  10. email: 'janebloggs@example.com',
  11. };
  12. const TEAM_1 = {
  13. id: '3',
  14. slug: 'cool-team',
  15. name: 'COOL TEAM',
  16. projects: [
  17. {
  18. slug: 2,
  19. },
  20. ],
  21. };
  22. beforeEach(function () {
  23. MemberListStore.loadInitialData([USER]);
  24. TeamStore.loadInitialData([TEAM_1]);
  25. });
  26. afterEach(function () {});
  27. describe('render()', function () {
  28. it('should show a gravatar when actor type is a user', function () {
  29. const avatar = mountWithTheme(
  30. <ActorAvatar
  31. actor={{
  32. id: '1',
  33. name: 'Jane Bloggs',
  34. type: 'user',
  35. }}
  36. />
  37. );
  38. expect(avatar).toSnapshot();
  39. });
  40. it('should show a gravatar when actor type is a team', function () {
  41. const avatar = mountWithTheme(
  42. <ActorAvatar
  43. actor={{
  44. id: '3',
  45. name: 'COOL TEAM',
  46. type: 'team',
  47. }}
  48. />
  49. );
  50. expect(avatar).toSnapshot();
  51. });
  52. it('should return null when actor type is a unknown', function () {
  53. window.console.error = jest.fn();
  54. const avatar = mount(
  55. <ActorAvatar
  56. actor={{
  57. id: '3',
  58. name: 'COOL TEAM',
  59. type: 'teapot',
  60. }}
  61. />
  62. );
  63. expect(avatar.html()).toBe(null);
  64. //proptype warning
  65. expect(window.console.error.mock.calls.length).toBeGreaterThan(0);
  66. window.console.error.mockRestore();
  67. });
  68. });
  69. });