|
|
@@ -0,0 +1,37 @@
|
|
|
+import reducer from '../reducers';
|
|
|
+import actions from '../actions';
|
|
|
+
|
|
|
+describe('Select works', () => {
|
|
|
+ it('Default state is set', () => {
|
|
|
+ expect(reducer(undefined, {}).selectedSubreddit).toBe('reactjs');
|
|
|
+ });
|
|
|
+ it('Selected reddit should change on new selections', () => {
|
|
|
+ const testReddit = 'Darksouls';
|
|
|
+ const action = actions.selectSubreddit(testReddit);
|
|
|
+ const newState = reducer(undefined, action);
|
|
|
+ expect(newState.selectedSubreddit).toEqual(testReddit);
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+describe('Request works', () => {
|
|
|
+ it('Default post state is empty', () => {
|
|
|
+ const testReddit = 'Darksouls';
|
|
|
+ const defaultState = reducer(undefined, []).postsBySubreddit;
|
|
|
+ expect(defaultState).toEqual({});
|
|
|
+ });
|
|
|
+ it('Request a subreddit should change isFetching status to true', () => {
|
|
|
+ const testReddit = 'Darksouls';
|
|
|
+ const action = actions.requestPost(testReddit);
|
|
|
+ const result = {
|
|
|
+ [testReddit]: {
|
|
|
+ isFetching: true,
|
|
|
+ didInvalidate: false,
|
|
|
+ items: []
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const posts = reducer(undefined, action).postsBySubreddit;
|
|
|
+ expect(posts).toEqual(result);
|
|
|
+ const isFetching = posts[testReddit].isFetching;
|
|
|
+ expect(isFetching).toBeTrue;
|
|
|
+ });
|
|
|
+});
|