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
|
import Vuex, { Store } from 'vuex'
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
import All from '../../../../../src/components/routes/All.vue'
import ContentTemplate from '../../../../../src/components/ContentTemplate.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', () => {
console.warn('PROPS', wrapper.findComponent(ContentTemplate).props());
expect((wrapper.findComponent(ContentTemplate)).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()
})
})
|