summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDevlin Junker <devlin.junker@gmail.com>2023-08-26 22:31:24 -0700
committerBenjamin Brahmer <info@b-brahmer.de>2023-08-28 07:03:07 +0200
commit83f99debaa1a6bfde88b62e43e6a0852ce928063 (patch)
tree40b7fa5d8ef9d67071d79885fbf34a7c2697a992 /tests
parentbb154d0a49d30932bb8b2aedfbcbf34f3aeee46c (diff)
basic unit tests
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/javascript/unit/components/routes/Explore.spec.ts (renamed from tests/javascript/unit/components/Explore.spec.ts)2
-rw-r--r--tests/javascript/unit/components/routes/Feed.spec.ts75
-rw-r--r--tests/javascript/unit/components/routes/Starred.spec.ts (renamed from tests/javascript/unit/components/Starred.spec.ts)4
-rw-r--r--tests/javascript/unit/components/routes/Unread.spec.ts (renamed from tests/javascript/unit/components/Unread.spec.ts)4
-rw-r--r--tests/javascript/unit/services/item.service.spec.ts19
-rw-r--r--tests/javascript/unit/store/item.spec.ts15
6 files changed, 112 insertions, 7 deletions
diff --git a/tests/javascript/unit/components/Explore.spec.ts b/tests/javascript/unit/components/routes/Explore.spec.ts
index b2ab052d5..04c7d6508 100644
--- a/tests/javascript/unit/components/Explore.spec.ts
+++ b/tests/javascript/unit/components/routes/Explore.spec.ts
@@ -3,7 +3,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'
import * as router from '@nextcloud/router'
-import Explore from '../../../../src/components/Explore.vue'
+import Explore from '../../../../../src/components/routes/Explore.vue'
jest.mock('@nextcloud/axios')
diff --git a/tests/javascript/unit/components/routes/Feed.spec.ts b/tests/javascript/unit/components/routes/Feed.spec.ts
new file mode 100644
index 000000000..4e0e69f2b
--- /dev/null
+++ b/tests/javascript/unit/components/routes/Feed.spec.ts
@@ -0,0 +1,75 @@
+import Vuex, { Store } from 'vuex'
+import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
+
+import Feed from '../../../../../src/components/routes/Feed.vue'
+import FeedItemDisplayList from '../../../../../src/components/FeedItemDisplayList.vue'
+
+jest.mock('@nextcloud/axios')
+
+describe('Feed.vue', () => {
+ 'use strict'
+ const localVue = createLocalVue()
+ localVue.use(Vuex)
+ let wrapper: Wrapper<Feed>
+
+ const mockFeed = {
+ id: 123,
+ title: 'feed name',
+ unreadCount: 2,
+ }
+
+ let store: Store<any>
+ beforeAll(() => {
+ store = new Vuex.Store({
+ state: {
+ items: {
+ fetchingItems: {
+ 'feed-123': false,
+ },
+ allItems: [{
+ feedId: 123,
+ title: 'feed item',
+ }, {
+ feedId: 123,
+ title: 'feed item 2',
+ }],
+ },
+ },
+ actions: {
+ },
+ getters: {
+ feeds: () => [mockFeed],
+ },
+ })
+
+ store.dispatch = jest.fn()
+ store.commit = jest.fn()
+
+ wrapper = shallowMount(Feed, {
+ propsData: {
+ feedId: '123',
+ },
+ mocks: {
+ $route: {
+ params: {},
+ },
+ },
+ localVue,
+ store,
+ })
+ })
+
+ it('should display feed title and unread count', () => {
+ expect(wrapper.find('.header').text()).toContain(mockFeed.title)
+ expect(wrapper.find('.header').text()).toContain(mockFeed.unreadCount.toString())
+ })
+
+ it('should get starred items from state', () => {
+ expect((wrapper.findComponent(FeedItemDisplayList)).props().items.length).toEqual(2)
+ })
+
+ it('should dispatch FETCH_FEED_ITEMS action if not fetchingItems.starred', () => {
+ (wrapper.vm as any).fetchMore()
+ expect(store.dispatch).toBeCalled()
+ })
+})
diff --git a/tests/javascript/unit/components/Starred.spec.ts b/tests/javascript/unit/components/routes/Starred.spec.ts
index 4f09f4e3c..44c9acd75 100644
--- a/tests/javascript/unit/components/Starred.spec.ts
+++ b/tests/javascript/unit/components/routes/Starred.spec.ts
@@ -1,8 +1,8 @@
import Vuex, { Store } from 'vuex'
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
-import Starred from '../../../../src/components/Starred.vue'
-import FeedItemDisplayList from '../../../../src/components/FeedItemDisplayList.vue'
+import Starred from '../../../../../src/components/routes/Starred.vue'
+import FeedItemDisplayList from '../../../../../src/components/FeedItemDisplayList.vue'
jest.mock('@nextcloud/axios')
diff --git a/tests/javascript/unit/components/Unread.spec.ts b/tests/javascript/unit/components/routes/Unread.spec.ts
index 6de4d8565..149fc015f 100644
--- a/tests/javascript/unit/components/Unread.spec.ts
+++ b/tests/javascript/unit/components/routes/Unread.spec.ts
@@ -1,8 +1,8 @@
import Vuex, { Store } from 'vuex'
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
-import Unread from '../../../../src/components/Unread.vue'
-import FeedItemDisplayList from '../../../../src/components/FeedItemDisplayList.vue'
+import Unread from '../../../../../src/components/routes/Unread.vue'
+import FeedItemDisplayList from '../../../../../src/components/FeedItemDisplayList.vue'
jest.mock('@nextcloud/axios')
diff --git a/tests/javascript/unit/services/item.service.spec.ts b/tests/javascript/unit/services/item.service.spec.ts
index 29de8f1a3..005248709 100644
--- a/tests/javascript/unit/services/item.service.spec.ts
+++ b/tests/javascript/unit/services/item.service.spec.ts
@@ -12,7 +12,7 @@ describe('item.service.ts', () => {
})
describe('fetchStarred', () => {
- it('should call GET with offset set to start param', async () => {
+ it('should call GET with offset set to start param and STARRED item type', async () => {
(axios as any).get.mockResolvedValue({ data: { feeds: [] } })
await ItemService.fetchStarred(0)
@@ -26,7 +26,7 @@ describe('item.service.ts', () => {
})
describe('fetchUnread', () => {
- it('should call GET with offset set to start param', async () => {
+ it('should call GET with offset set to start param and UNREAD item type', async () => {
(axios as any).get.mockResolvedValue({ data: { feeds: [] } })
await ItemService.fetchUnread(2)
@@ -39,6 +39,21 @@ 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 () => {
+ (axios as any).get.mockResolvedValue({ data: { feeds: [] } })
+
+ await ItemService.fetchFeedItems(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.ALL)
+ })
+ })
+
describe('markRead', () => {
it('should call POST with item id in URL and read param', async () => {
await ItemService.markRead({ id: 123 } as any, true)
diff --git a/tests/javascript/unit/store/item.spec.ts b/tests/javascript/unit/store/item.spec.ts
index c393a03f4..84869c4d8 100644
--- a/tests/javascript/unit/store/item.spec.ts
+++ b/tests/javascript/unit/store/item.spec.ts
@@ -37,6 +37,21 @@ describe('item.ts', () => {
})
})
+ describe('FETCH_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.debounceFetchFeedItems = fetchMock as any
+ const commit = jest.fn()
+
+ await (actions[FEED_ITEM_ACTION_TYPES.FETCH_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()