diff options
Diffstat (limited to 'tests/javascript/unit/store/feed.spec.ts')
-rw-r--r-- | tests/javascript/unit/store/feed.spec.ts | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/tests/javascript/unit/store/feed.spec.ts b/tests/javascript/unit/store/feed.spec.ts index 29df4b105..928820085 100644 --- a/tests/javascript/unit/store/feed.spec.ts +++ b/tests/javascript/unit/store/feed.spec.ts @@ -9,14 +9,27 @@ describe('feed.ts', () => { 'use strict' describe('actions', () => { - it('ADD_FEED should call POST and commit feed to state', async () => { - (axios as any).post.mockResolvedValue() - const commit = jest.fn() - await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } }) - expect(axios.post).toBeCalled() - expect(commit).toBeCalled() + describe('ADD_FEED', () => { + it('should call POST and commit feed to state', async () => { + (axios as any).post.mockResolvedValue({ data: { feeds: [] }}) + const commit = jest.fn() + await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } }) + expect(axios.post).toBeCalled() + expect(commit).toBeCalled() + }) + + it('should call POST and not call commit if error', async () => { + (axios as any).post.mockRejectedValue() + const commit = jest.fn() + await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } }) + expect(axios.post).toBeCalled() + + expect(commit).not.toBeCalled() + }) }) + + it('FETCH_FEEDS should call GET and commit returned feeds to state', async () => { (axios as any).get.mockResolvedValue({ data: { feeds: [] } }) const commit = jest.fn() @@ -27,29 +40,31 @@ describe('feed.ts', () => { }) describe('mutations', () => { - it('SET_FEEDS should add feeds to state', () => { - const state = { feeds: [] as Feed[], folders: [] as any[] } as AppState - let feeds = [] as Feed[] - - mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds) - expect(state.feeds.length).toEqual(0) - - feeds = [{ title: 'test' }] as Feed[] - - mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds) - expect(state.feeds.length).toEqual(1) - expect(state.feeds[0]).toEqual(feeds[0]) + describe('SET_FEEDS', () => { + it('should add feeds to state', () => { + const state = { feeds: [] as Feed[], folders: [] as any[] } as AppState + let feeds = [] as any + + mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds) + expect(state.feeds.length).toEqual(0) + + feeds = [{ title: 'test' }] as Feed[] + + mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds) + expect(state.feeds.length).toEqual(1) + expect(state.feeds[0]).toEqual(feeds[0]) + }) }) - - it('SET_FEEDS should add feeds and unreadCount to folder if exists and folder set', () => { - const state = { feeds: [] as Feed[], folders: [{ id: 1, feedCount: 3, feeds: [] as Feed[] }] } as AppState - const feeds = [{ title: 'test', folderId: 1, unreadCount: 2 }] as Feed[] - - mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds) - expect(state.feeds.length).toEqual(1) - expect(state.feeds[0]).toEqual(feeds[0]) - expect(state.folders[0].feeds[0]).toEqual(feeds[0]) - expect(state.folders[0].feedCount).toEqual(5) + + describe('ADD_FEED', () => { + it('should add a single feed to state', () => { + const state = { feeds: [] as Feed[], folders: [] as any[] } as AppState + let feed = { title: 'test' } as any; + + mutations[FEED_MUTATION_TYPES.ADD_FEED](state, feed) + expect(state.feeds.length).toEqual(1) + expect(state.feeds[0]).toEqual(feed) + }) }) }) }) |