Skip to content

Commit ab176fa

Browse files
committed
Add friends to profile
1 parent fd7f7bb commit ab176fa

File tree

9 files changed

+67
-9
lines changed

9 files changed

+67
-9
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from 'react'
2+
import { shallow } from 'enzyme'
3+
import FriendsList from './FriendsList'
4+
5+
describe('FriendsList', () => {
6+
describe('when there are friends', () => {
7+
const friends = [
8+
{ name: 'Bob' },
9+
{ name: 'Frankie' }
10+
]
11+
12+
it('should list friends', () => {
13+
const friendsList = shallow(<FriendsList friends={friends} />)
14+
expect(friendsList).toIncludeText('Bob')
15+
expect(friendsList).toIncludeText('Frankie')
16+
})
17+
})
18+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react'
2+
3+
interface Friend {
4+
name: string
5+
}
6+
7+
interface FriendsListProps {
8+
friends: Array<Friend>
9+
}
10+
11+
export default ({ friends }: FriendsListProps) =>
12+
<ul>
13+
{friends.map(({ name }, i) => <li key={i}>{name}</li>)}
14+
</ul>

components/User/components/Profile/components/Profile.test.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import * as React from 'react'
22
import { shallow } from 'enzyme'
33
import Profile from './Profile'
4+
import FriendsList from './FriendsList'
45

56
describe('<Profile />', () => {
7+
const props = {
8+
name: 'Luke',
9+
biography: 'My bio',
10+
twitter: '@Cool',
11+
friends: [
12+
{ name: 'Jenny' }
13+
]
14+
}
15+
616
let profile
717

818
beforeEach(() => {
9-
profile = shallow(<Profile name='Luke' biography='My bio' twitter='@Cool' />)
19+
profile = shallow(<Profile {...props} />)
1020
})
1121

1222
it('should display name', () => {
@@ -20,4 +30,8 @@ describe('<Profile />', () => {
2030
it('should display twitter', () => {
2131
expect(profile).toIncludeText('@Cool')
2232
})
33+
34+
it('should display friends', () => {
35+
expect(profile).toContainReact(<FriendsList friends={props.friends} />)
36+
})
2337
})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import * as React from 'react'
2+
import FriendsList from './FriendsList'
23

3-
export default ({ name, biography, twitter }) =>
4+
export default ({ name, biography, twitter, friends }) =>
45
<div>
56
<p>{name}</p>
67
<p>{biography}</p>
78
<p>Follow on twitter: {twitter}</p>
9+
10+
<FriendsList friends={friends} />
811
</div>

lib/user/FakeUserGateway.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export async function findById (id: string) : Promise<User> {
55
name: 'Mr Luke Fake',
66
77
biography: 'Coool',
8-
twitter: '@Cool'
8+
twitter: '@Cool',
9+
friends: []
910
}
1011
}

lib/user/HTTPUserGateway.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import * as HTTPUserGateway from './HTTPUserGateway'
22
import mockExecute from '../../test/support/mockExecute'
33

44
describe('HTTPUserGateway', () => {
5-
const fakeUser = { basicInfo: { name: 'Jim', email: '[email protected]' } }
5+
const fakeUser = {
6+
basicInfo: { name: 'Jim', email: '[email protected]' },
7+
friends: []
8+
}
69

710
describe('when finding by id', () => {
811
test('user has name', async () => {
912
mockExecute('findUserById', { userId: 'guid' }).reply(200, fakeUser)
1013
const user = await HTTPUserGateway.findById('guid')
11-
expect(user.name).toBe('Jim')
12-
expect(user.email).toBe('[email protected]')
14+
expect(user.name).toEqual('Jim')
15+
expect(user.email).toEqual('[email protected]')
16+
expect(user.friends).toEqual([])
1317
})
1418
})
1519
})

lib/user/HTTPUserGateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ const API_ORIGIN = process.env.API_ORIGIN
55

66
export async function findById (userId: string) : Promise<User> {
77
const user = await execute('findUserById', { userId })
8-
return user.basicInfo
8+
return { ...user.basicInfo, friends: user.friends }
99
}

lib/user/User.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export default interface User {
22
name: string
33
email: string
44
biography: string
5-
twitter: string
5+
twitter: string,
6+
friends: Array<User>
67
}

test/acceptance/users/viewingProfile.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import UserProfile from '../../../pages/users/profile'
55

66
describe('Viewing profile', () => {
77
const userId = 'uniq-guid'
8-
const fakeUser = { basicInfo: { name: 'Luke', email: '[email protected]' } }
8+
const fakeUser = {
9+
basicInfo: { name: 'Luke', email: '[email protected]' },
10+
friends: []
11+
}
912

1013
describe('when user views the page', () => {
1114
test('user can see user name', async () => {

0 commit comments

Comments
 (0)