summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.eslintrc.js6
-rw-r--r--src/components/Sidebar.vue3
-rw-r--r--src/components/SidebarFeedLinkActions.vue2
-rw-r--r--src/store/feed.ts73
-rw-r--r--src/store/folder.ts54
-rw-r--r--src/store/item.ts88
-rw-r--r--tests/javascript/unit/store/feed.spec.ts8
-rw-r--r--tests/javascript/unit/store/folder.spec.ts4
-rw-r--r--tests/javascript/unit/store/item.spec.ts26
9 files changed, 211 insertions, 53 deletions
diff --git a/.eslintrc.js b/.eslintrc.js
index 1021c7404..48070d761 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -42,5 +42,11 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
},
},
+ {
+ files: ['src/store/*.ts'],
+ rules: {
+ 'function-paren-newline': ['error', 'multiline'],
+ },
+ },
],
}
diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue
index a7ab51dfd..3ffb8c0ca 100644
--- a/src/components/Sidebar.vue
+++ b/src/components/Sidebar.vue
@@ -148,6 +148,7 @@ const SideBarState = {
})
navItems = navItems.concat(state.folders)
+ // bring pinned items to the top
return navItems.sort((item, item2) => {
if ((item as Feed).pinned && !(item2 as Feed).pinned) {
return -1
@@ -215,7 +216,7 @@ export default Vue.extend({
renameFolder(folder: Folder) {
const name = window.prompt(t('news', 'Rename Folder'), folder.name)
- // null on escape
+ // null when user presses escape (do nothing)
if (name !== null) {
this.$store.dispatch(ACTIONS.FOLDER_SET_NAME, { folder, name })
}
diff --git a/src/components/SidebarFeedLinkActions.vue b/src/components/SidebarFeedLinkActions.vue
index e9f8bd521..444254cc4 100644
--- a/src/components/SidebarFeedLinkActions.vue
+++ b/src/components/SidebarFeedLinkActions.vue
@@ -131,7 +131,7 @@ export default Vue.extend({
rename() {
const title = window.prompt(t('news', 'Rename Feed'), this.feed.title)
- // null on escape
+ // null when user presses escape (do nothing)
if (title !== null) {
this.$store.dispatch(ACTIONS.FEED_SET_TITLE, { feed: this.feed, title })
}
diff --git a/src/store/feed.ts b/src/store/feed.ts
index ad8b30fad..9fea76a72 100644
--- a/src/store/feed.ts
+++ b/src/store/feed.ts
@@ -42,6 +42,7 @@ export const actions = {
return total + feed.unreadCount
}, 0)))
},
+
async [FEED_ACTION_TYPES.ADD_FEED](
{ commit }: ActionParams,
{ feedReq }: {
@@ -80,9 +81,9 @@ export const actions = {
} catch (e) {
// TODO: show error to user if failure
console.log(e)
-
}
},
+
async [FEED_ACTION_TYPES.FEED_MARK_READ]({ commit }: ActionParams, { feed }: { feed: Feed }) {
// want to fetch feed so that we can retrieve the "highestItemId"
const response = await ItemService.fetchFeedItems(feed.id as number)
@@ -95,43 +96,64 @@ export const actions = {
commit(FEED_MUTATION_TYPES.SET_FEED_ALL_READ, feed)
},
- async [FEED_ACTION_TYPES.FEED_SET_PINNED]({ commit }: ActionParams, { feed, pinned }: { feed: Feed, pinned: boolean }) {
+ async [FEED_ACTION_TYPES.FEED_SET_PINNED](
+ { commit }: ActionParams,
+ { feed, pinned }: { feed: Feed, pinned: boolean },
+ ) {
await FeedService.updateFeed({ feedId: feed.id as number, pinned })
commit(FEED_MUTATION_TYPES.UPDATE_FEED, { id: feed.id, pinned })
},
- async [FEED_ACTION_TYPES.FEED_SET_ORDERING]({ commit }: ActionParams, { feed, ordering }: { feed: Feed, ordering: FEED_ORDER }) {
+ async [FEED_ACTION_TYPES.FEED_SET_ORDERING](
+ { commit }: ActionParams,
+ { feed, ordering }: { feed: Feed, ordering: FEED_ORDER },
+ ) {
await FeedService.updateFeed({ feedId: feed.id as number, ordering })
commit(FEED_MUTATION_TYPES.UPDATE_FEED, { id: feed.id, ordering })
},
- async [FEED_ACTION_TYPES.FEED_SET_FULL_TEXT]({ commit }: ActionParams, { feed, fullTextEnabled }: { feed: Feed, fullTextEnabled: boolean }) {
+ async [FEED_ACTION_TYPES.FEED_SET_FULL_TEXT](
+ { commit }: ActionParams,
+ { feed, fullTextEnabled }: { feed: Feed, fullTextEnabled: boolean },
+ ) {
await FeedService.updateFeed({ feedId: feed.id as number, fullTextEnabled })
commit(FEED_MUTATION_TYPES.UPDATE_FEED, { id: feed.id, fullTextEnabled })
},
- async [FEED_ACTION_TYPES.FEED_SET_UPDATE_MODE]({ commit }: ActionParams, { feed, updateMode }: { feed: Feed, updateMode: FEED_UPDATE_MODE }) {
+ async [FEED_ACTION_TYPES.FEED_SET_UPDATE_MODE](
+ { commit }: ActionParams,
+ { feed, updateMode }: { feed: Feed, updateMode: FEED_UPDATE_MODE },
+ ) {
await FeedService.updateFeed({ feedId: feed.id as number, updateMode })
commit(FEED_MUTATION_TYPES.UPDATE_FEED, { id: feed.id, updateMode })
},
- async [FEED_ACTION_TYPES.FEED_SET_TITLE]({ commit }: ActionParams, { feed, title }: { feed: Feed, title: string }) {
+ async [FEED_ACTION_TYPES.FEED_SET_TITLE](
+ { commit }: ActionParams,
+ { feed, title }: { feed: Feed, title: string },
+ ) {
await FeedService.updateFeed({ feedId: feed.id as number, title })
commit(FEED_MUTATION_TYPES.UPDATE_FEED, { id: feed.id, title })
},
- async [FEED_ACTION_TYPES.FEED_DELETE]({ commit }: ActionParams, { feed }: { feed: Feed }) {
+ async [FEED_ACTION_TYPES.FEED_DELETE](
+ { commit }: ActionParams,
+ { feed }: { feed: Feed },
+ ) {
await FeedService.deleteFeed({ feedId: feed.id as number })
commit(FEED_MUTATION_TYPES.FEED_DELETE, feed.id)
},
- async [FEED_ACTION_TYPES.MODIFY_FEED_UNREAD_COUNT]({ commit, state }: ActionParams, { feedId, delta }: { feedId: number, delta: number }) {
+ async [FEED_ACTION_TYPES.MODIFY_FEED_UNREAD_COUNT](
+ { commit, state }: ActionParams,
+ { feedId, delta }: { feedId: number, delta: number },
+ ) {
commit(FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT, { feedId, delta })
const feed = state.feeds.find((feed: Feed) => {
@@ -146,21 +168,36 @@ export const actions = {
}
export const mutations = {
- [FEED_MUTATION_TYPES.SET_FEEDS](state: AppState, feeds: Feed[]) {
+ [FEED_MUTATION_TYPES.SET_FEEDS](
+ state: AppState,
+ feeds: Feed[],
+ ) {
feeds.forEach(it => {
state.feeds.push(it)
})
},
- [FEED_MUTATION_TYPES.ADD_FEED](state: AppState, feed: Feed) {
+
+ [FEED_MUTATION_TYPES.ADD_FEED](
+ state: AppState,
+ feed: Feed,
+ ) {
state.feeds.push(feed)
},
- [FEED_MUTATION_TYPES.UPDATE_FEED](state: AppState, newFeed: Feed) {
+
+ [FEED_MUTATION_TYPES.UPDATE_FEED](
+ state: AppState,
+ newFeed: Feed,
+ ) {
const feed = state.feeds.find((feed: Feed) => {
return feed.id === newFeed.id
})
_.assign(feed, newFeed)
},
- [FEED_MUTATION_TYPES.SET_FEED_ALL_READ](state: AppState, feed: Feed) {
+
+ [FEED_MUTATION_TYPES.SET_FEED_ALL_READ](
+ state: AppState,
+ feed: Feed,
+ ) {
const priorFeed = state.feeds.find((stateFeed: Feed) => {
return stateFeed.id === feed.id
})
@@ -170,7 +207,11 @@ export const mutations = {
state.unreadCount -= priorUnread
}
},
- [FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT](state: AppState, { feedId, delta }: { feedId: number, delta: number }) {
+
+ [FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT](
+ state: AppState,
+ { feedId, delta }: { feedId: number, delta: number },
+ ) {
const feed = state.feeds.find((feed: Feed) => {
return feed.id === feedId
})
@@ -178,7 +219,11 @@ export const mutations = {
_.assign(feed, { unreadCount: feed.unreadCount + delta })
}
},
- [FEED_MUTATION_TYPES.FEED_DELETE](state: AppState, feedId: number) {
+
+ [FEED_MUTATION_TYPES.FEED_DELETE](
+ state: AppState,
+ feedId: number,
+ ) {
state.feeds = state.feeds.filter((feed: Feed) => {
return feed.id !== feedId
})
diff --git a/src/store/folder.ts b/src/store/folder.ts
index ca4b3d4e7..33604d4f1 100644
--- a/src/store/folder.ts
+++ b/src/store/folder.ts
@@ -30,11 +30,17 @@ export const actions = {
commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, folders.data.folders)
},
- async [FOLDER_ACTION_TYPES.ADD_FOLDERS]({ commit }: ActionParams, { folder }: { folder: Folder }) {
+ async [FOLDER_ACTION_TYPES.ADD_FOLDERS](
+ { commit }: ActionParams,
+ { folder }: { folder: Folder },
+ ) {
const response = await FolderService.createFolder({ name: folder.name })
commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, response.data.folders)
},
- async [FOLDER_ACTION_TYPES.DELETE_FOLDER]({ commit }: ActionParams, { folder }: { folder: Folder }) {
+ async [FOLDER_ACTION_TYPES.DELETE_FOLDER](
+ { commit }: ActionParams,
+ { folder }: { folder: Folder },
+ ) {
/**
* TODO: look into reversiblyDelete?
this.getByFolderId(folderId).forEach(function (feed) {
@@ -44,25 +50,39 @@ export const actions = {
await FolderService.deleteFolder({ id: folder.id })
commit(FOLDER_MUTATION_TYPES.DELETE_FOLDER, folder)
},
- async [FOLDER_ACTION_TYPES.FOLDER_SET_NAME]({ commit }: ActionParams, { folder, name }: { folder: Folder, name: string }) {
+ async [FOLDER_ACTION_TYPES.FOLDER_SET_NAME](
+ { commit }: ActionParams,
+ { folder, name }: { folder: Folder, name: string },
+ ) {
await FolderService.renameFolder({ id: folder.id, name })
commit(FOLDER_MUTATION_TYPES.UPDATE_FOLDER, { id: folder.id, name })
},
}
export const mutations = {
- [FOLDER_MUTATION_TYPES.SET_FOLDERS](state: AppState, folders: Folder[]) {
+ [FOLDER_MUTATION_TYPES.SET_FOLDERS](
+ state: AppState,
+ folders: Folder[],
+ ) {
folders.forEach(it => {
it.feedCount = 0
it.feeds = []
state.folders.push(it)
})
},
- [FOLDER_MUTATION_TYPES.DELETE_FOLDER](state: AppState, folder: Folder) {
+
+ [FOLDER_MUTATION_TYPES.DELETE_FOLDER](
+ state: AppState,
+ folder: Folder,
+ ) {
const index = state.folders.indexOf(folder)
state.folders.splice(index, 1)
},
- [FEED_MUTATION_TYPES.SET_FEEDS](state: AppState, feeds: Feed[]) {
+
+ [FEED_MUTATION_TYPES.SET_FEEDS](
+ state: AppState,
+ feeds: Feed[],
+ ) {
feeds.forEach(it => {
const folder = state.folders.find((folder: Folder) => { return folder.id === it.folderId })
if (folder) {
@@ -71,28 +91,42 @@ export const mutations = {
}
})
},
- [FEED_MUTATION_TYPES.ADD_FEED](state: AppState, feed: Feed) {
+
+ [FEED_MUTATION_TYPES.ADD_FEED](
+ state: AppState,
+ feed: Feed,
+ ) {
const folder = state.folders.find((folder: Folder) => { return folder.id === feed.folderId })
if (folder) {
folder.feeds.push(feed)
folder.feedCount += feed.unreadCount
}
},
- [FOLDER_MUTATION_TYPES.UPDATE_FOLDER](state: AppState, newFolder: Folder) {
+
+ [FOLDER_MUTATION_TYPES.UPDATE_FOLDER](
+ state: AppState,
+ newFolder: Folder,
+ ) {
const folder = state.folders.find((f: Folder) => { return f.id === newFolder.id })
if (folder) {
_.assign(folder, newFolder)
}
},
- [FOLDER_MUTATION_TYPES.MODIFY_FOLDER_UNREAD_COUNT](state: AppState, { folderId, delta }: {folderId: number; delta: number }) {
+ [FOLDER_MUTATION_TYPES.MODIFY_FOLDER_UNREAD_COUNT](
+ state: AppState,
+ { folderId, delta }: {folderId: number; delta: number },
+ ) {
const folder = state.folders.find((f: Folder) => { return f.id === folderId })
if (folder) {
folder.feedCount += delta
}
},
- [FEED_MUTATION_TYPES.SET_FEED_ALL_READ](state: AppState, feed: Feed) {
+ [FEED_MUTATION_TYPES.SET_FEED_ALL_READ](
+ state: AppState,
+ feed: Feed,
+ ) {
const folder = state.folders.find((folder: Folder) => {
return folder.id === feed.folderId
})
diff --git a/src/store/item.ts b/src/store/item.ts
index 07e79a39d..14ae20658 100644
--- a/src/store/item.ts
+++ b/src/store/item.ts
@@ -67,7 +67,10 @@ export const actions = {
* @param param1 ActionArgs
* @param param1.start
*/
- async [FEED_ITEM_ACTION_TYPES.FETCH_UNREAD]({ commit }: ActionParams, { start }: { start: number } = { start: 0 }) {
+ async [FEED_ITEM_ACTION_TYPES.FETCH_UNREAD](
+ { commit }: ActionParams,
+ { start }: { start: number } = { start: 0 },
+ ) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'unread', fetching: true })
const response = await ItemService.debounceFetchUnread(start || state.lastItemLoaded.unread)
@@ -91,7 +94,10 @@ export const actions = {
* @param param1 ActionArgs
* @param param1.start
*/
- async [FEED_ITEM_ACTION_TYPES.FETCH_ITEMS]({ commit }: ActionParams, { start }: { start: number } = { start: 0 }) {
+ async [FEED_ITEM_ACTION_TYPES.FETCH_ITEMS](
+ { commit }: ActionParams,
+ { start }: { start: number } = { start: 0 },
+ ) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'all', fetching: true })
const response = await ItemService.debounceFetchAll(start || state.lastItemLoaded.all)
@@ -117,7 +123,10 @@ export const actions = {
* @param param1 ActionArgs
* @param param1.start
*/
- async [FEED_ITEM_ACTION_TYPES.FETCH_STARRED]({ commit }: ActionParams, { start }: { start: number } = { start: 0 }) {
+ async [FEED_ITEM_ACTION_TYPES.FETCH_STARRED](
+ { commit }: ActionParams,
+ { start }: { start: number } = { start: 0 },
+ ) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'starred', fetching: true })
const response = await ItemService.debounceFetchStarred(start || state.lastItemLoaded.starred)
@@ -145,7 +154,10 @@ export const actions = {
* @param param1.start
* @param param1.feedId
*/
- async [FEED_ITEM_ACTION_TYPES.FETCH_FEED_ITEMS]({ commit }: ActionParams, { feedId, start }: { feedId: number; start: number }) {
+ async [FEED_ITEM_ACTION_TYPES.FETCH_FEED_ITEMS](
+ { commit }: ActionParams,
+ { feedId, start }: { feedId: number; start: number },
+ ) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'feed-' + feedId, fetching: true })
const response = await ItemService.debounceFetchFeedItems(feedId, start || state.lastItemLoaded['feed-' + feedId])
@@ -169,7 +181,10 @@ export const actions = {
* @param param1.start
* @param param1.folderId
*/
- async [FEED_ITEM_ACTION_TYPES.FETCH_FOLDER_FEED_ITEMS]({ commit }: ActionParams, { folderId, start }: { folderId: number; start: number }) {
+ async [FEED_ITEM_ACTION_TYPES.FETCH_FOLDER_FEED_ITEMS](
+ { commit }: ActionParams,
+ { folderId, start }: { folderId: number; start: number },
+ ) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'folder-' + folderId, fetching: true })
const response = await ItemService.debounceFetchFolderFeedItems(folderId, start || state.lastItemLoaded['folder-' + folderId])
@@ -193,7 +208,10 @@ export const actions = {
* @param param1 ActionArgs
* @param param1.item
*/
- [FEED_ITEM_ACTION_TYPES.MARK_READ]({ commit, dispatch }: ActionParams, { item }: { item: FeedItem }) {
+ [FEED_ITEM_ACTION_TYPES.MARK_READ](
+ { commit, dispatch }: ActionParams,
+ { item }: { item: FeedItem },
+ ) {
ItemService.markRead(item, true)
if (item.unread) {
@@ -214,7 +232,10 @@ export const actions = {
* @param param1 ActionArgs
* @param param1.item
*/
- [FEED_ITEM_ACTION_TYPES.MARK_UNREAD]({ commit, dispatch }: ActionParams, { item }: { item: FeedItem}) {
+ [FEED_ITEM_ACTION_TYPES.MARK_UNREAD](
+ { commit, dispatch }: ActionParams,
+ { item }: { item: FeedItem},
+ ) {
ItemService.markRead(item, false)
if (!item.unread) {
@@ -234,7 +255,10 @@ export const actions = {
* @param param1 ActionArgs
* @param param1.item
*/
- [FEED_ITEM_ACTION_TYPES.STAR_ITEM]({ commit }: ActionParams, { item }: { item: FeedItem}) {
+ [FEED_ITEM_ACTION_TYPES.STAR_ITEM](
+ { commit }: ActionParams,
+ { item }: { item: FeedItem},
+ ) {
ItemService.markStarred(item, true)
item.starred = true
@@ -250,7 +274,10 @@ export const actions = {
* @param param1 ActionArgs
* @param param1.item
*/
- [FEED_ITEM_ACTION_TYPES.UNSTAR_ITEM]({ commit }: ActionParams, { item }: { item: FeedItem}) {
+ [FEED_ITEM_ACTION_TYPES.UNSTAR_ITEM](
+ { commit }: ActionParams,
+ { item }: { item: FeedItem},
+ ) {
ItemService.markStarred(item, false)
item.starred = false
@@ -263,6 +290,7 @@ export const mutations = {
[FEED_ITEM_MUTATION_TYPES.SET_SELECTED_ITEM](state: ItemState, { id }: { id: string }) {
state.selectedId = id
},
+
[FEED_ITEM_MUTATION_TYPES.SET_ITEMS](state: ItemState, items: FeedItem[]) {
if (items) {
items.forEach(it => {
@@ -272,26 +300,54 @@ export const mutations = {
})
}
},
- [FEED_ITEM_MUTATION_TYPES.SET_STARRED_COUNT](state: ItemState, count: number) {
+
+ [FEED_ITEM_MUTATION_TYPES.SET_STARRED_COUNT](
+ state: ItemState,
+ count: number,
+ ) {
state.starredCount = count
},
- [FEED_ITEM_MUTATION_TYPES.SET_UNREAD_COUNT](state: ItemState, count: number) {
+
+ [FEED_ITEM_MUTATION_TYPES.SET_UNREAD_COUNT](
+ state: ItemState,
+ count: number,
+ ) {
state.unreadCount = count
},
- [FEED_ITEM_MUTATION_TYPES.UPDATE_ITEM](state: ItemState, { item }: { item: FeedItem }) {
+
+ [FEED_ITEM_MUTATION_TYPES.UPDATE_ITEM](
+ state: ItemState,
+ { item }: { item: FeedItem },
+ ) {
const idx = state.allItems.findIndex((it) => it.id === item.id)
state.allItems.splice(idx, 1, item)
},
- [FEED_ITEM_MUTATION_TYPES.SET_FETCHING](state: ItemState, { fetching, key }: { fetching: boolean; key: string; }) {
+
+ [FEED_ITEM_MUTATION_TYPES.SET_FETCHING](
+ state: ItemState,
+ { fetching, key }: { fetching: boolean; key: string; },
+ ) {
state.fetchingItems[key] = fetching
},
- [FEED_ITEM_MUTATION_TYPES.SET_ALL_LOADED](state: ItemState, { loaded, key }: { loaded: boolean; key: string; }) {
+
+ [FEED_ITEM_MUTATION_TYPES.SET_ALL_LOADED](
+ state: ItemState,
+ { loaded, key }: { loaded: boolean; key: string; },
+ ) {
state.allItemsLoaded[key] = loaded
},
- [FEED_ITEM_MUTATION_TYPES.SET_LAST_ITEM_LOADED](state: ItemState, { lastItem, key }: { lastItem: number; key: string; }) {
+
+ [FEED_ITEM_MUTATION_TYPES.SET_LAST_ITEM_LOADED](
+ state: ItemState,
+ { lastItem, key }: { lastItem: number; key: string; },
+ ) {
state.lastItemLoaded[key] = lastItem
},
- [FEED_MUTATION_TYPES.SET_FEED_ALL_READ](state: ItemState, feed: Feed) {
+
+ [FEED_MUTATION_TYPES.SET_FEED_ALL_READ](
+ state: ItemState,
+ feed: Feed,
+ ) {
state.allItems.forEach((item: FeedItem) => {
if (item.feedId === feed.id) {
item.unread = false
diff --git a/tests/javascript/unit/store/feed.spec.ts b/tests/javascript/unit/store/feed.spec.ts
index 451d04d7a..db4431b20 100644
--- a/tests/javascript/unit/store/feed.spec.ts
+++ b/tests/javascript/unit/store/feed.spec.ts
@@ -22,20 +22,20 @@ describe('feed.ts', () => {
})
describe('ADD_FEED', () => {
- it('should call FeedService.addF and commit feed to state', async () => {
+ it('should call FeedService.addFeed and commit feed to state', async () => {
FeedService.addFeed = jest.fn();
(FeedService.addFeed as any).mockResolvedValue({ data: { feeds: [] } })
const commit = jest.fn()
- await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } })
+ await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit } as any, { feedReq: { url: '' } } as any)
expect(FeedService.addFeed).toBeCalled()
expect(commit).toBeCalled()
})
- it('should call FeedService.addF and not call commit if error', async () => {
+ it('should call FeedService.addFeed and not call commit if error', async () => {
FeedService.addFeed = jest.fn();
(FeedService.addFeed as any).mockRejectedValue()
const commit = jest.fn()
- await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } })
+ await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit } as any, { feedReq: { url: '' } } as any)
expect(FeedService.addFeed).toBeCalled()
expect(commit).not.toBeCalled()
diff --git a/tests/javascript/unit/store/folder.spec.ts b/tests/javascript/unit/store/folder.spec.ts
index 8fd2ad34f..796908587 100644
--- a/tests/javascript/unit/store/folder.spec.ts
+++ b/tests/javascript/unit/store/folder.spec.ts
@@ -28,7 +28,7 @@ describe('folder.ts', () => {
const folder = {} as Folder
const commit = jest.fn()
- await actions[FOLDER_ACTION_TYPES.ADD_FOLDERS]({ commit }, { folder })
+ await actions[FOLDER_ACTION_TYPES.ADD_FOLDERS]({ commit } as any, { folder })
expect(FolderService.createFolder).toBeCalled()
expect(commit).toBeCalled()
})
@@ -40,7 +40,7 @@ describe('folder.ts', () => {
const folder = {} as Folder
const commit = jest.fn()
- await actions[FOLDER_ACTION_TYPES.DELETE_FOLDER]({ commit }, { folder })
+ await actions[FOLDER_ACTION_TYPES.DELETE_FOLDER]({ commit } as any, { folder })
expect(FolderService.deleteFolder).toBeCalled()
expect(commit).toBeCalled()
})
diff --git a/tests/javascript/unit/store/item.spec.ts b/tests/javascript/unit/store/item.spec.ts
index 8d22d69a1..b0c5fa412 100644
--- a/tests/javascript/unit/store/item.spec.ts
+++ b/tests/javascript/unit/store/item.spec.ts
@@ -1,7 +1,7 @@
import { AppState } from '../../../../src/store'
import { FEED_ITEM_ACTION_TYPES, mutations, actions } from '../../../../src/store/item'
-import { FEED_ITEM_MUTATION_TYPES } from '../../../../src/types/MutationTypes'
+import { FEED_ITEM_MUTATION_TYPES, FEED_MUTATION_TYPES } from '../../../../src/types/MutationTypes'
import { ItemService } from '../../../../src/dataservices/item.service'
describe('item.ts', () => {
@@ -68,27 +68,31 @@ describe('item.ts', () => {
})
it('MARK_READ should call GET and commit returned feeds to state', async () => {
- const item = { id: 1 }
+ const item = { id: 1, feedId: 123, unread: true }
const commit = jest.fn()
+ const dispatch = jest.fn()
const serviceMock = jest.fn()
ItemService.markRead = serviceMock
- await (actions[FEED_ITEM_ACTION_TYPES.MARK_READ] as any)({ commit }, { item })
+ await (actions[FEED_ITEM_ACTION_TYPES.MARK_READ] as any)({ commit, dispatch }, { item })
expect(serviceMock).toBeCalledWith(item, true)
expect(commit).toBeCalled()
+ expect(dispatch).toBeCalledWith(FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT, { feedId: 123, delta: -1 })
})
it('MARK_UNREAD should call GET and commit returned feeds to state', async () => {
- const item = { id: 1 }
+ const item = { id: 1, feedId: 123 }
const commit = jest.fn()
+ const dispatch = jest.fn()
const serviceMock = jest.fn()
ItemService.markRead = serviceMock
- await (actions[FEED_ITEM_ACTION_TYPES.MARK_UNREAD] as any)({ commit }, { item })
+ await (actions[FEED_ITEM_ACTION_TYPES.MARK_UNREAD] as any)({ commit, dispatch }, { item })
expect(serviceMock).toBeCalledWith(item, false)
expect(commit).toBeCalledWith(FEED_ITEM_MUTATION_TYPES.UPDATE_ITEM, { item })
+ expect(dispatch).toBeCalledWith(FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT, { feedId: 123, delta: 1 })
})
it('STAR_ITEM should call GET and commit returned feeds to state', async () => {
@@ -213,5 +217,17 @@ describe('item.ts', () => {
expect(state.allItemsLoaded.starred).toEqual(false)
})
})
+
+ describe('SET_FEED_ALL_READ', () => {
+ it('should set allItems with feedId as read', () => {
+ const state = { allItems: [{ id: 1, feedId: 123, unread: true }, { id: 2, feedId: 345, unread: true }] } as any
+
+ (mutations[FEED_MUTATION_TYPES.SET_FEED_ALL_READ] as any)(state, { id: 123 })
+ expect(state.allItems[0].unread).toEqual(false);
+
+ (mutations[FEED_MUTATION_TYPES.SET_FEED_ALL_READ] as any)(state, { id: 345 })
+ expect(state.allItems[1].unread).toEqual(false)
+ })
+ })
})
})