summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/store/feed.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/javascript/unit/store/feed.spec.ts')
-rw-r--r--tests/javascript/unit/store/feed.spec.ts36
1 files changed, 32 insertions, 4 deletions
diff --git a/tests/javascript/unit/store/feed.spec.ts b/tests/javascript/unit/store/feed.spec.ts
index 1a4fb0fee..94f45d42d 100644
--- a/tests/javascript/unit/store/feed.spec.ts
+++ b/tests/javascript/unit/store/feed.spec.ts
@@ -9,20 +9,48 @@ describe('feed.ts', () => {
'use strict'
describe('actions', () => {
- it('ADD_FEED', async () => {
+ 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()
})
+
+ it('FETCH_FEEDS should call GET and commit returned feeds to state', async () => {
+ (axios as any).get.mockResolvedValue({ data: { feeds: [] } })
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.FETCH_FEEDS] as any)({ commit })
+ expect(axios.get).toBeCalled()
+ expect(commit).toBeCalled()
+ })
})
describe('mutations', () => {
- it('', () => {
- const state = { feeds: [] as Feed[] } as AppState
- const feeds = [] as Feed[]
+ 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])
+ })
+
+ 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)
})
})
})