summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/components/routes/Feed.spec.ts
blob: 4e0e69f2b5005724ad0c29863875444be100c612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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()
	})
})