-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from eea/develop
Release
- Loading branch information
Showing
6 changed files
with
402 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
getZoteroSettings, | ||
fetchZoteroCollections, | ||
fetchZoteroItems, | ||
} from './actions'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { ZOTERO_SETTINGS } from '../constants'; | ||
|
||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
|
||
global.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
ok: true, | ||
json: () => Promise.resolve({}), | ||
headers: { | ||
get: jest.fn().mockReturnValue(0), | ||
}, | ||
}), | ||
); | ||
|
||
jest.mock('react-toastify', () => ({ | ||
toast: { | ||
error: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('Zotero and Openaire actions', () => { | ||
afterEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
|
||
it('getZoteroSettings returns correct action', () => { | ||
const expectedAction = { | ||
type: ZOTERO_SETTINGS, | ||
request: { | ||
op: 'get', | ||
path: `/@zotero`, | ||
}, | ||
}; | ||
expect(getZoteroSettings()).toEqual(expectedAction); | ||
}); | ||
|
||
it('fetchZoteroCollections dispatches correct actions on success', async () => { | ||
const store = mockStore({}); | ||
await store.dispatch(fetchZoteroCollections('url', {})); | ||
expect(store.getActions()).toContainEqual({ | ||
type: 'ZOTERO_COLLECTIONS_PENDING', | ||
}); | ||
expect(store.getActions()).toContainEqual({ | ||
type: 'ZOTERO_COLLECTIONS_SUCCESS', | ||
result: { results: {}, totalResults: 0 }, | ||
}); | ||
}); | ||
|
||
it('fetchZoteroItems dispatches correct actions on success', async () => { | ||
const store = mockStore({}); | ||
await store.dispatch(fetchZoteroItems('url', {})); | ||
expect(store.getActions()).toContainEqual({ type: 'ZOTERO_ITEMS_PENDING' }); | ||
expect(store.getActions()).toContainEqual({ | ||
type: 'ZOTERO_ITEMS_SUCCESS', | ||
result: { results: {}, totalResults: 0 }, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.