actorAvatar.spec.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from 'react';
  2. import {shallow, mount} from 'enzyme';
  3. import ActorAvatar from 'app/components/actorAvatar';
  4. import MemberListStore from 'app/stores/memberListStore';
  5. import TeamStore from 'app/stores/teamStore';
  6. describe('Avatar', function() {
  7. let sandbox;
  8. const USER = {
  9. id: '1',
  10. name: 'Jane Doe',
  11. email: 'janedoe@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. beforeEach(function() {
  24. sandbox = sinon.sandbox.create();
  25. MemberListStore.loadInitialData([USER]);
  26. TeamStore.loadInitialData([TEAM_1]);
  27. });
  28. afterEach(function() {
  29. sandbox.restore();
  30. });
  31. describe('render()', function() {
  32. it('should show a gravatar when actor type is a user', function() {
  33. let avatar = shallow(
  34. <ActorAvatar
  35. actor={{
  36. id: '1',
  37. name: 'Jane Doe',
  38. type: 'user',
  39. }}
  40. />
  41. );
  42. expect(avatar).toMatchSnapshot();
  43. });
  44. it('should show a gravatar when actor type is a team', function() {
  45. let avatar = shallow(
  46. <ActorAvatar
  47. actor={{
  48. id: '3',
  49. name: 'COOL TEAM',
  50. type: 'team',
  51. }}
  52. />
  53. );
  54. expect(avatar).toMatchSnapshot();
  55. });
  56. it('should return null when actor type is a unknown', function() {
  57. window.console.error = jest.fn();
  58. let avatar = mount(
  59. <ActorAvatar
  60. actor={{
  61. id: '3',
  62. name: 'COOL TEAM',
  63. type: 'teapot',
  64. }}
  65. />
  66. );
  67. expect(avatar.html()).toBe(null);
  68. //proptype warning
  69. expect(window.console.error.mock.calls.length).toBeGreaterThan(0);
  70. window.console.error.mockRestore();
  71. });
  72. });
  73. });