UNPKG

2.51 kBJavaScriptView Raw
1import React from 'react';
2import {shallow, mount} from 'enzyme';
3
4import {SmartUserCardTooltip, UserCard, UserCardTooltip} from './user-card';
5
6describe('UserCard', () => {
7 const fakeUser = {
8 login: 'testuser',
9 name: 'Test User',
10 email: 'testuser@mail.com',
11 avatarUrl: 'http://some-url',
12 href: 'http://foo'
13 };
14
15 describe('Card', () => {
16 const shallowCard = props => shallow(
17 <UserCard user={fakeUser} {...props}/>
18 );
19 const mountCard = props => mount(<UserCard user={fakeUser} {...props}/>);
20
21 it('should create component', () => {
22 mountCard().should.have.type(UserCard);
23 });
24
25 it('should wrap children with span', () => {
26 shallowCard().should.have.tagName('div');
27 });
28
29 it('should render link', () => {
30 shallowCard({user: {...fakeUser, href: null}}).
31 should.not.have.descendants('a[href="http://foo"]');
32 });
33
34 it('should not render link if user has no href', () => {
35 shallowCard({user: {...fakeUser, href: null}}).
36 should.not.have.descendants('a');
37 });
38
39 it('should use passed className', () => {
40 shallowCard({className: 'test-class'}).should.have.className('test-class');
41 });
42
43 it('should use pass rest props to dom node', () => {
44 shallowCard({'data-test': 'foo'}).should.have.data('test', 'foo');
45 });
46 });
47
48 describe('UserCardTooltip', () => {
49 const anchor = <span data-test="anchor">{'foo'}</span>;
50
51 const mountTooltip = props => mount(
52 <UserCardTooltip user={fakeUser} {...props}>
53 {anchor}
54 </UserCardTooltip>
55 );
56
57 it('should render anchor', () => {
58 const wrapper = mountTooltip();
59
60 wrapper.should.have.descendants('[data-test="anchor"]');
61 });
62 });
63
64 describe('SmartUserCardTooltip', () => {
65 const anchor = <span>{'foo'}</span>;
66
67 function userSource() {
68 return fakeUser;
69 }
70
71 const mountTooltip = props => mount(
72 <SmartUserCardTooltip userDataSource={userSource} {...props}>
73 {anchor}
74 </SmartUserCardTooltip>
75 );
76
77 it('should load user on hover', () => {
78 const wrapper = mountTooltip();
79 sandbox.stub(wrapper.instance(), 'loadUser').callsFake(() => {});
80
81 // Force the component and wrapper to update so that the stub is used https://github.com/airbnb/enzyme/issues/586
82 wrapper.instance().forceUpdate();
83 wrapper.update();
84
85 wrapper.simulate('mouseenter');
86
87 wrapper.instance().loadUser.should.have.been.called;
88 });
89 });
90});
91
\No newline at end of file