Add new tests
This commit is contained in:
parent
2630d67b76
commit
0bc27a5ff6
4 changed files with 95 additions and 7 deletions
|
|
@ -96,7 +96,6 @@ export const toggleSaved = (post, token) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO add tests
|
|
||||||
export const fetchSavedPosts = (next = false) => {
|
export const fetchSavedPosts = (next = false) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestPosts());
|
dispatch(requestPosts());
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,12 @@ describe('post actions', () => {
|
||||||
expect(actions.markingPostRead()).toEqual(expectedAction);
|
expect(actions.markingPostRead()).toEqual(expectedAction);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create an action to toggle post saved state', () => {
|
||||||
|
const expectedAction = { type: actions.TOGGLING_POST };
|
||||||
|
|
||||||
|
expect(actions.togglingPost()).toEqual(expectedAction);
|
||||||
|
});
|
||||||
|
|
||||||
it('should create an action receive a post', () => {
|
it('should create an action receive a post', () => {
|
||||||
const post = {
|
const post = {
|
||||||
id: 2067,
|
id: 2067,
|
||||||
|
|
@ -131,10 +137,11 @@ describe('post actions', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedAction = {
|
const expectedAction = {
|
||||||
type: actions.TOGGLING_POST,
|
type: actions.TOGGLED_POST,
|
||||||
|
post,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(actions.togglingPost(post)).toEqual(expectedAction);
|
expect(actions.postToggled(post)).toEqual(expectedAction);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create multiple actions to mark post read', () => {
|
it('should create multiple actions to mark post read', () => {
|
||||||
|
|
@ -300,7 +307,7 @@ describe('post actions', () => {
|
||||||
fetchMock.getOnce('/api/rules/4/posts/?read=false', {
|
fetchMock.getOnce('/api/rules/4/posts/?read=false', {
|
||||||
body: {
|
body: {
|
||||||
count: 2,
|
count: 2,
|
||||||
next: 'https://durp.com/api/rules/4/posts/?page=2&read=false',
|
next: 'https://durp.com/api/rules/4/posts/?cursor=jabadabar&read=false',
|
||||||
previous: null,
|
previous: null,
|
||||||
results: posts,
|
results: posts,
|
||||||
},
|
},
|
||||||
|
|
@ -318,7 +325,7 @@ describe('post actions', () => {
|
||||||
{ type: actions.REQUEST_POSTS },
|
{ type: actions.REQUEST_POSTS },
|
||||||
{
|
{
|
||||||
type: actions.RECEIVE_POSTS,
|
type: actions.RECEIVE_POSTS,
|
||||||
next: 'https://durp.com/api/rules/4/posts/?page=2&read=false',
|
next: 'https://durp.com/api/rules/4/posts/?cursor=jabadabar&read=false',
|
||||||
posts,
|
posts,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -369,7 +376,7 @@ describe('post actions', () => {
|
||||||
fetchMock.getOnce('/api/categories/1/posts/?read=false', {
|
fetchMock.getOnce('/api/categories/1/posts/?read=false', {
|
||||||
body: {
|
body: {
|
||||||
count: 2,
|
count: 2,
|
||||||
next: 'https://durp.com/api/categories/4/posts/?page=2&read=false',
|
next: 'https://durp.com/api/categories/4/posts/?cursor=jabadabar&read=false',
|
||||||
previous: null,
|
previous: null,
|
||||||
results: posts,
|
results: posts,
|
||||||
},
|
},
|
||||||
|
|
@ -387,7 +394,7 @@ describe('post actions', () => {
|
||||||
{ type: actions.REQUEST_POSTS },
|
{ type: actions.REQUEST_POSTS },
|
||||||
{
|
{
|
||||||
type: actions.RECEIVE_POSTS,
|
type: actions.RECEIVE_POSTS,
|
||||||
next: 'https://durp.com/api/categories/4/posts/?page=2&read=false',
|
next: 'https://durp.com/api/categories/4/posts/?cursor=jabadabar&read=false',
|
||||||
posts,
|
posts,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -397,6 +404,67 @@ describe('post actions', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create multiple actions to fetch posts by saved state', () => {
|
||||||
|
const posts = [
|
||||||
|
{
|
||||||
|
id: 2067,
|
||||||
|
remoteIdentifier: 'https://arstechnica.com/?p=1648607',
|
||||||
|
title:
|
||||||
|
'This amazing glitch puts Star Fox 64 ships in an unmodified Zelda cartridge',
|
||||||
|
body:
|
||||||
|
'"Stale-reference manipulation," 300-character file names, and a clash between worlds.',
|
||||||
|
author: 'Kyle Orland',
|
||||||
|
publicationDate: '2020-01-24T19:50:12Z',
|
||||||
|
url: 'https://arstechnica.com/?p=1648607',
|
||||||
|
rule: 4,
|
||||||
|
read: false,
|
||||||
|
saved: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2141,
|
||||||
|
remoteIdentifier: 'https://arstechnica.com/?p=1648757',
|
||||||
|
title: 'The most complete brain map ever is here: A fly’s “connectome”',
|
||||||
|
body:
|
||||||
|
'It took 12 years and at least $40 million to chart a region about 250µm across.',
|
||||||
|
author: 'WIRED',
|
||||||
|
publicationDate: '2020-01-25T11:06:46Z',
|
||||||
|
url: 'https://arstechnica.com/?p=1648757',
|
||||||
|
rule: 4,
|
||||||
|
read: false,
|
||||||
|
saved: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
fetchMock.getOnce('/api/posts/?saved=true', {
|
||||||
|
body: {
|
||||||
|
next: 'https://durp.com/api/posts/?cursor=jabadabar&saved=true',
|
||||||
|
previous: null,
|
||||||
|
results: posts,
|
||||||
|
},
|
||||||
|
headers: { 'content-type': 'application/json' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const store = mockStore({
|
||||||
|
categories: { items: {}, isFetching: false },
|
||||||
|
rules: { items: {}, isFetching: false },
|
||||||
|
posts: { items: {}, isFetching: false, isUpdating: false },
|
||||||
|
selected: { item: {}, next: false, lastReached: false, post: {} },
|
||||||
|
});
|
||||||
|
|
||||||
|
const expectedActions = [
|
||||||
|
{ type: actions.REQUEST_POSTS },
|
||||||
|
{
|
||||||
|
type: actions.RECEIVE_POSTS,
|
||||||
|
next: 'https://durp.com/api/posts/?cursor=jabadabar&saved=true',
|
||||||
|
posts,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return store.dispatch(actions.fetchSavedPosts()).then(() => {
|
||||||
|
expect(store.getActions()).toEqual(expectedActions);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should create no actions when fetching posts and section is read', () => {
|
it('should create no actions when fetching posts and section is read', () => {
|
||||||
const rule = {
|
const rule = {
|
||||||
id: 4,
|
id: 4,
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,14 @@ describe('selected actions', () => {
|
||||||
expect(actions.markSectionRead(category)).toEqual(expectedAction);
|
expect(actions.markSectionRead(category)).toEqual(expectedAction);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create an action to select saved items', () => {
|
||||||
|
const expectedAction = {
|
||||||
|
type: actions.SELECT_SAVED,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(actions.selectSaved()).toEqual(expectedAction);
|
||||||
|
});
|
||||||
|
|
||||||
it('should mark a category as read', () => {
|
it('should mark a category as read', () => {
|
||||||
const category = { id: 1, name: 'Test category', unread: 100 };
|
const category = { id: 1, name: 'Test category', unread: 100 };
|
||||||
const rules = {
|
const rules = {
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,19 @@ describe('selected reducer', () => {
|
||||||
expect(reducer(undefined, action)).toEqual(expectedState);
|
expect(reducer(undefined, action)).toEqual(expectedState);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return state after selecting saved items', () => {
|
||||||
|
const action = {
|
||||||
|
type: actions.SELECT_SAVED,
|
||||||
|
};
|
||||||
|
|
||||||
|
const expectedState = {
|
||||||
|
...defaultState,
|
||||||
|
item: { type: constants.SAVED_TYPE },
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(reducer(undefined, action)).toEqual(expectedState);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return state after selecting a category twice', () => {
|
it('should return state after selecting a category twice', () => {
|
||||||
const category = { id: 9, name: 'Tech', unread: 291 };
|
const category = { id: 9, name: 'Tech', unread: 291 };
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue