summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/App.vue1
-rw-r--r--src/components/feed-display/FeedItemDisplayList.vue15
-rw-r--r--tests/javascript/unit/components/routes/All.spec.ts65
-rw-r--r--tests/javascript/unit/components/routes/Folder.spec.ts89
-rw-r--r--tests/javascript/unit/services/item.service.spec.ts33
-rw-r--r--tests/javascript/unit/store/item.spec.ts15
6 files changed, 213 insertions, 5 deletions
diff --git a/src/App.vue b/src/App.vue
index 97383c440..930c8b048 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -24,7 +24,6 @@ export default Vue.extend({
async created() {
await this.$store.dispatch(ACTIONS.FETCH_FOLDERS)
await this.$store.dispatch(ACTIONS.FETCH_FEEDS)
- await this.$store.dispatch(ACTIONS.FETCH_STARRED)
},
})
</script>
diff --git a/src/components/feed-display/FeedItemDisplayList.vue b/src/components/feed-display/FeedItemDisplayList.vue
index 8fc58281e..44e4b070a 100644
--- a/src/components/feed-display/FeedItemDisplayList.vue
+++ b/src/components/feed-display/FeedItemDisplayList.vue
@@ -1,6 +1,6 @@
<template>
- <div style="height: 100%; display: flex; flex-direction: column;">
- <div style="justify-content: right; display: flex">
+ <div class="feed-item-display-list">
+ <div class="header">
<NcActions class="filter-container" :force-menu="true">
<template #icon>
<FilterIcon />
@@ -180,6 +180,12 @@ export default Vue.extend({
</script>
<style scoped>
+ .feed-item-display-list {
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ }
+
.virtual-scroll {
border-top: 1px solid var(--color-border);
width: 100%;
@@ -196,6 +202,11 @@ export default Vue.extend({
height: calc(100vh - 50px - 50px - 10px)
}
+ .header {
+ justify-content: right;
+ display: flex;
+ }
+
.filter-container {
padding: 5px;
}
diff --git a/tests/javascript/unit/components/routes/All.spec.ts b/tests/javascript/unit/components/routes/All.spec.ts
new file mode 100644
index 000000000..ff9b2b169
--- /dev/null
+++ b/tests/javascript/unit/components/routes/All.spec.ts
@@ -0,0 +1,65 @@
+import Vuex, { Store } from 'vuex'
+import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
+
+import All from '../../../../../src/components/routes/All.vue'
+import FeedItemDisplayList from '../../../../../src/components/feed-display/FeedItemDisplayList.vue'
+
+jest.mock('@nextcloud/axios')
+
+describe('All.vue', () => {
+ 'use strict'
+ const localVue = createLocalVue()
+ localVue.use(Vuex)
+ let wrapper: Wrapper<All>
+
+ const mockItem = {
+ feedId: 1,
+ title: 'feed item',
+ pubDate: Date.now() / 1000,
+ }
+
+ let store: Store<any>
+ beforeAll(() => {
+ store = new Vuex.Store({
+ state: {
+ items: {
+ fetchingItems: {
+ all: false,
+ },
+ },
+ },
+ actions: {
+ },
+ getters: {
+ allItems: () => [mockItem, mockItem, mockItem],
+ },
+ })
+
+ store.dispatch = jest.fn()
+ store.commit = jest.fn()
+
+ wrapper = shallowMount(All, {
+ propsData: {
+ item: mockItem,
+ },
+ localVue,
+ store,
+ })
+ })
+
+ it('should get all items from state', () => {
+ expect((wrapper.findComponent(FeedItemDisplayList)).props().items.length).toEqual(3)
+ })
+
+ it('should dispatch FETCH_ITEMS action if not fetchingItems.all', () => {
+ (wrapper.vm as any).$store.state.items.fetchingItems.all = true;
+
+ (wrapper.vm as any).fetchMore()
+ expect(store.dispatch).not.toBeCalled();
+
+ (wrapper.vm as any).$store.state.items.fetchingItems.all = false;
+
+ (wrapper.vm as any).fetchMore()
+ expect(store.dispatch).toBeCalled()
+ })
+})
diff --git a/tests/javascript/unit/components/routes/Folder.spec.ts b/tests/javascript/unit/components/routes/Folder.spec.ts
new file mode 100644
index 000000000..c2c966adb
--- /dev/null
+++ b/tests/javascript/unit/components/routes/Folder.spec.ts
@@ -0,0 +1,89 @@
+import Vuex, { Store } from 'vuex'
+import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
+
+import Folder from '../../../../../src/components/routes/Folder.vue'
+import FeedItemDisplayList from '../../../../../src/components/feed-display/FeedItemDisplayList.vue'
+
+jest.mock('@nextcloud/axios')
+
+describe('Folder.vue', () => {
+ 'use strict'
+ const localVue = createLocalVue()
+ localVue.use(Vuex)
+ let wrapper: Wrapper<Folder>
+
+ const mockFeed = {
+ id: 789,
+ title: 'feed name',
+ unreadCount: 2,
+ folderId: 123,
+ }
+
+ const mockFeed2 = {
+ id: 456,
+ title: 'feed name 2',
+ unreadCount: 2,
+ folderId: 123,
+ }
+
+ const mockFolder = {
+ id: 123,
+ name: 'folder name',
+ }
+
+ let store: Store<any>
+ beforeAll(() => {
+ store = new Vuex.Store({
+ state: {
+ items: {
+ fetchingItems: {
+ 'folder-123': false,
+ },
+ allItems: [{
+ feedId: 789,
+ title: 'feed item',
+ }, {
+ feedId: 456,
+ title: 'feed item 2',
+ }],
+ },
+ },
+ actions: {
+ },
+ getters: {
+ feeds: () => [mockFeed, mockFeed2],
+ folders: () => [mockFolder],
+ },
+ })
+
+ store.dispatch = jest.fn()
+ store.commit = jest.fn()
+
+ wrapper = shallowMount(Folder, {
+ propsData: {
+ folderId: '123',
+ },
+ mocks: {
+ $route: {
+ params: {},
+ },
+ },
+ localVue,
+ store,
+ })
+ })
+
+ it('should display feed title and unread count', () => {
+ expect(wrapper.find('.header').text()).toContain(mockFolder.name)
+ expect(wrapper.find('.header').text()).toContain((mockFeed.unreadCount + mockFeed2.unreadCount).toString())
+ })
+
+ it('should get folder items from state', () => {
+ expect((wrapper.findComponent(FeedItemDisplayList)).props().items.length).toEqual(2)
+ })
+
+ it('should dispatch FETCH_FOLDER_FEED_ITEMS action on fetchMore', () => {
+ (wrapper.vm as any).fetchMore()
+ expect(store.dispatch).toBeCalled()
+ })
+})
diff --git a/tests/javascript/unit/services/item.service.spec.ts b/tests/javascript/unit/services/item.service.spec.ts
index 005248709..66a5b5484 100644
--- a/tests/javascript/unit/services/item.service.spec.ts
+++ b/tests/javascript/unit/services/item.service.spec.ts
@@ -11,6 +11,20 @@ describe('item.service.ts', () => {
(axios.post as any).mockReset()
})
+ describe('fetchAll', () => {
+ it('should call GET with offset set to start param, ALL item type', async () => {
+ (axios as any).get.mockResolvedValue({ data: { feeds: [] } })
+
+ await ItemService.fetchAll(0)
+
+ expect(axios.get).toBeCalled()
+ const queryParams = (axios.get as any).mock.calls[0][1].params
+
+ expect(queryParams.offset).toEqual(0)
+ expect(queryParams.type).toEqual(ITEM_TYPES.ALL)
+ })
+ })
+
describe('fetchStarred', () => {
it('should call GET with offset set to start param and STARRED item type', async () => {
(axios as any).get.mockResolvedValue({ data: { feeds: [] } })
@@ -40,7 +54,7 @@ describe('item.service.ts', () => {
})
describe('fetchFeedItems', () => {
- it('should call GET with offset set to start param, UNREAD item type, and id set to feedId', async () => {
+ it('should call GET with offset set to start param, FEED item type, and id set to feedId', async () => {
(axios as any).get.mockResolvedValue({ data: { feeds: [] } })
await ItemService.fetchFeedItems(123, 0)
@@ -50,7 +64,22 @@ describe('item.service.ts', () => {
expect(queryParams.id).toEqual(123)
expect(queryParams.offset).toEqual(0)
- expect(queryParams.type).toEqual(ITEM_TYPES.ALL)
+ expect(queryParams.type).toEqual(ITEM_TYPES.FEED)
+ })
+ })
+
+ describe('fetchFolderItems', () => {
+ it('should call GET with offset set to start param, FOLDER item type, and id set to folderId', async () => {
+ (axios as any).get.mockResolvedValue({ data: { feeds: [] } })
+
+ await ItemService.fetchFolderItems(123, 0)
+
+ expect(axios.get).toBeCalled()
+ const queryParams = (axios.get as any).mock.calls[0][1].params
+
+ expect(queryParams.id).toEqual(123)
+ expect(queryParams.offset).toEqual(0)
+ expect(queryParams.type).toEqual(ITEM_TYPES.FOLDER)
})
})
diff --git a/tests/javascript/unit/store/item.spec.ts b/tests/javascript/unit/store/item.spec.ts
index 7866cff5b..8d22d69a1 100644
--- a/tests/javascript/unit/store/item.spec.ts
+++ b/tests/javascript/unit/store/item.spec.ts
@@ -52,6 +52,21 @@ describe('item.ts', () => {
})
})
+ describe('FETCH_FOLDER_FEED_ITEMS', () => {
+ it('should call ItemService and commit items to state', async () => {
+ const mockItems = [{ id: 123, title: 'feed item' }]
+ const fetchMock = jest.fn()
+ fetchMock.mockResolvedValue({ data: { items: mockItems } })
+ ItemService.debounceFetchFolderFeedItems = fetchMock as any
+ const commit = jest.fn()
+
+ await (actions[FEED_ITEM_ACTION_TYPES.FETCH_FOLDER_FEED_ITEMS] as any)({ commit }, { feedId: 123 })
+
+ expect(fetchMock).toBeCalled()
+ expect(commit).toBeCalledWith(FEED_ITEM_MUTATION_TYPES.SET_ITEMS, mockItems)
+ })
+ })
+
it('MARK_READ should call GET and commit returned feeds to state', async () => {
const item = { id: 1 }
const commit = jest.fn()