summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/components/routes/Starred.spec.ts
blob: b5a87251dfffe1cb6dffbac5528625165adcd647 (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
import Vuex, { Store } from 'vuex'
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'

import Starred from '../../../../../src/components/routes/Starred.vue'
import ContentTemplate from '../../../../../src/components/ContentTemplate.vue'

jest.mock('@nextcloud/axios')

describe('Starred.vue', () => {
	'use strict'
	const localVue = createLocalVue()
	localVue.use(Vuex)
	let wrapper: Wrapper<Starred>

	const mockItem = {
		feedId: 1,
		title: 'feed item',
		pubDate: Date.now() / 1000,
	}

	let store: Store<any>
	beforeAll(() => {
		store = new Vuex.Store({
			state: {
				items: {
					fetchingItems: {
						starred: false,
					},
				},
			},
			actions: {
			},
			getters: {
				starred: () => [mockItem],
			},
		})

		store.dispatch = jest.fn()
		store.commit = jest.fn()

		wrapper = shallowMount(Starred, {
			propsData: {
				item: mockItem,
			},
			localVue,
			store,
		})
	})

	it('should get starred items from state', () => {
		expect((wrapper.findComponent(ContentTemplate)).props().items.length).toEqual(1)
	})

	it('should dispatch FETCH_STARRED action if not fetchingItems.starred', () => {
		(wrapper.vm as any).fetchMore()
		expect(store.dispatch).toBeCalled()
	})
})