diff options
Diffstat (limited to 'tests/javascript/unit/components/routes')
4 files changed, 230 insertions, 0 deletions
diff --git a/tests/javascript/unit/components/routes/Explore.spec.ts b/tests/javascript/unit/components/routes/Explore.spec.ts new file mode 100644 index 000000000..04c7d6508 --- /dev/null +++ b/tests/javascript/unit/components/routes/Explore.spec.ts @@ -0,0 +1,32 @@ +import axios from '@nextcloud/axios' +import { shallowMount, createLocalVue } from '@vue/test-utils' + +import * as router from '@nextcloud/router' + +import Explore from '../../../../../src/components/routes/Explore.vue' + +jest.mock('@nextcloud/axios') + +describe('Explore.vue', () => { + 'use strict' + const localVue = createLocalVue() + + it('should initialize without showing AddFeed Component', () => { + (axios as any).get.mockResolvedValue({ data: { } }); + (router as any).generateUrl = jest.fn().mockReturnValue('') + + const wrapper = shallowMount(Explore, { + localVue, + mocks: { + $store: { + state: { + feeds: [], + folders: [], + }, + }, + }, + }) + + expect(wrapper.vm.$data.showAddFeed).toBeFalsy() + }) +}) 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/routes/Starred.spec.ts b/tests/javascript/unit/components/routes/Starred.spec.ts new file mode 100644 index 000000000..44c9acd75 --- /dev/null +++ b/tests/javascript/unit/components/routes/Starred.spec.ts @@ -0,0 +1,58 @@ +import Vuex, { Store } from 'vuex' +import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils' + +import Starred from '../../../../../src/components/routes/Starred.vue' +import FeedItemDisplayList from '../../../../../src/components/FeedItemDisplayList.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(FeedItemDisplayList)).props().items.length).toEqual(1) + }) + + it('should dispatch FETCH_STARRED action if not fetchingItems.starred', () => { + (wrapper.vm as any).fetchMore() + expect(store.dispatch).toBeCalled() + }) +}) diff --git a/tests/javascript/unit/components/routes/Unread.spec.ts b/tests/javascript/unit/components/routes/Unread.spec.ts new file mode 100644 index 000000000..149fc015f --- /dev/null +++ b/tests/javascript/unit/components/routes/Unread.spec.ts @@ -0,0 +1,65 @@ +import Vuex, { Store } from 'vuex' +import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils' + +import Unread from '../../../../../src/components/routes/Unread.vue' +import FeedItemDisplayList from '../../../../../src/components/FeedItemDisplayList.vue' + +jest.mock('@nextcloud/axios') + +describe('Unread.vue', () => { + 'use strict' + const localVue = createLocalVue() + localVue.use(Vuex) + let wrapper: Wrapper<Unread> + + const mockItem = { + feedId: 1, + title: 'feed item', + pubDate: Date.now() / 1000, + } + + let store: Store<any> + beforeAll(() => { + store = new Vuex.Store({ + state: { + items: { + fetchingItems: { + unread: false, + }, + }, + }, + actions: { + }, + getters: { + unread: () => [mockItem, mockItem], + }, + }) + + store.dispatch = jest.fn() + store.commit = jest.fn() + + wrapper = shallowMount(Unread, { + propsData: { + item: mockItem, + }, + localVue, + store, + }) + }) + + it('should get unread items from state', () => { + expect((wrapper.findComponent(FeedItemDisplayList)).props().items.length).toEqual(2) + }) + + it('should dispatch FETCH_UNREAD action if not fetchingItems.unread', () => { + (wrapper.vm as any).$store.state.items.fetchingItems.unread = true; + + (wrapper.vm as any).fetchMore() + expect(store.dispatch).not.toBeCalled(); + + (wrapper.vm as any).$store.state.items.fetchingItems.unread = false; + + (wrapper.vm as any).fetchMore() + expect(store.dispatch).toBeCalled() + }) +}) |