Skip to content

Commit 6653325

Browse files
authored
Merge branch 'master' into add-notifications-reducer-tests
2 parents f6f8445 + 0f7accc commit 6653325

File tree

3 files changed

+168
-1
lines changed

3 files changed

+168
-1
lines changed

__tests__/data/api/search.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
export const repos = {
2+
total_count: 40,
3+
incomplete_results: false,
4+
items: [
5+
{
6+
id: 3081286,
7+
name: 'Tetris',
8+
full_name: 'dtrupenn/Tetris',
9+
owner: {
10+
login: 'dtrupenn',
11+
id: 872147,
12+
avatar_url:
13+
'https://secure.gravatar.com/avatar/e7956084e75f239de85d3a31bc172ace?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png',
14+
gravatar_id: '',
15+
url: 'https://api.github.com/users/dtrupenn',
16+
received_events_url:
17+
'https://api.github.com/users/dtrupenn/received_events',
18+
type: 'User',
19+
},
20+
private: false,
21+
html_url: 'https://github.com/dtrupenn/Tetris',
22+
description: 'A C implementation of Tetris using Pennsim through LC4',
23+
fork: false,
24+
url: 'https://api.github.com/repos/dtrupenn/Tetris',
25+
created_at: '2012-01-01T00:31:50Z',
26+
updated_at: '2013-01-05T17:58:47Z',
27+
pushed_at: '2012-01-01T00:37:02Z',
28+
homepage: '',
29+
size: 524,
30+
stargazers_count: 1,
31+
watchers_count: 1,
32+
language: 'Assembly',
33+
forks_count: 0,
34+
open_issues_count: 0,
35+
master_branch: 'master',
36+
default_branch: 'master',
37+
score: 10.309712,
38+
},
39+
],
40+
};
41+
42+
export const users = {
43+
total_count: 12,
44+
incomplete_results: false,
45+
items: [
46+
{
47+
login: 'mojombo',
48+
id: 1,
49+
avatar_url:
50+
'https://secure.gravatar.com/avatar/25c7c18223fb42a4c6ae1c8db6f50f9b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png',
51+
gravatar_id: '',
52+
url: 'https://api.github.com/users/mojombo',
53+
html_url: 'https://github.com/mojombo',
54+
followers_url: 'https://api.github.com/users/mojombo/followers',
55+
subscriptions_url: 'https://api.github.com/users/mojombo/subscriptions',
56+
organizations_url: 'https://api.github.com/users/mojombo/orgs',
57+
repos_url: 'https://api.github.com/users/mojombo/repos',
58+
received_events_url:
59+
'https://api.github.com/users/mojombo/received_events',
60+
type: 'User',
61+
score: 105.47857,
62+
},
63+
],
64+
};
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React from 'react';
2+
import { searchReducer, initialState } from 'search/search.reducer';
3+
import { SEARCH_REPOS, SEARCH_USERS } from 'search/search.type';
4+
import { repos, users } from 'testData/api/search';
5+
import { authError } from 'testData/api/error';
6+
7+
describe('Search Reducer', () => {
8+
it('should return the initial state', () => {
9+
expect(searchReducer(undefined, {})).toEqual(initialState);
10+
});
11+
12+
/**
13+
* Search repositories.
14+
*/
15+
it('should set repos to empty and set isPendingSearchRepos to true when SEARCH_REPOS.PENDING action is dispatched', () => {
16+
const expectedState = {
17+
...initialState,
18+
repos: [],
19+
isPendingSearchRepos: true,
20+
};
21+
const action = {
22+
type: SEARCH_REPOS.PENDING,
23+
};
24+
25+
expect(searchReducer(initialState, action)).toEqual(expectedState);
26+
});
27+
28+
it('should set repos from payload of SEARCH_REPOS.SUCCESS action and set isPendingSearchRepos to false', () => {
29+
const expectedState = {
30+
...initialState,
31+
repos: repos.items,
32+
isPendingSearchRepos: false,
33+
};
34+
// The 'searchRepos' action creator dispatches this action with repos.items payload.
35+
const action = {
36+
type: SEARCH_REPOS.SUCCESS,
37+
payload: repos.items,
38+
};
39+
40+
expect(searchReducer(initialState, action)).toEqual(expectedState);
41+
});
42+
43+
it('should set an error from payload of SEARCH_REPOS.ERROR action and set isPendingSearchRepos to false', () => {
44+
const expectedState = {
45+
...initialState,
46+
error: authError,
47+
isPendingSearchRepos: false,
48+
};
49+
// The 'searchRepos' action creator dispatches this action with data.items payload.
50+
const action = {
51+
type: SEARCH_REPOS.ERROR,
52+
payload: authError,
53+
};
54+
55+
expect(searchReducer(initialState, action)).toEqual(expectedState);
56+
});
57+
58+
/**
59+
* Search users.
60+
*/
61+
it('should set users to empty and set isPendingSearchUsers to true when SEARCH_USERS.PENDING action is dispatched', () => {
62+
const expectedState = {
63+
...initialState,
64+
users: [],
65+
isPendingSearchUsers: true,
66+
};
67+
const action = {
68+
type: SEARCH_USERS.PENDING,
69+
};
70+
71+
expect(searchReducer(initialState, action)).toEqual(expectedState);
72+
});
73+
74+
it('should set users from payload of SEARCH_USERS.SUCCESS action and set isPendingSearchUsers to false', () => {
75+
const expectedState = {
76+
...initialState,
77+
users: users.items,
78+
isPendingSearchUsers: false,
79+
};
80+
// The 'searchUsers' action creator dispatches this action with data.items payload.
81+
const action = {
82+
type: SEARCH_USERS.SUCCESS,
83+
payload: users.items,
84+
};
85+
86+
expect(searchReducer(initialState, action)).toEqual(expectedState);
87+
});
88+
89+
it('should set an error from payload of SEARCH_USERS.ERROR action and set isPendingSearchUsers to false', () => {
90+
const expectedState = {
91+
...initialState,
92+
error: authError,
93+
isPendingSearchUsers: false,
94+
};
95+
// The 'searchRepos' action creator dispatches this action with repos.items payload.
96+
const action = {
97+
type: SEARCH_REPOS.ERROR,
98+
payload: authError,
99+
};
100+
101+
expect(searchReducer(initialState, action)).toEqual(expectedState);
102+
});
103+
});

src/search/search.reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SEARCH_REPOS, SEARCH_USERS } from './search.type';
22

3-
const initialState = {
3+
export const initialState = {
44
users: [],
55
repos: [],
66
isPendingSearchUsers: false,

0 commit comments

Comments
 (0)