summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/components/routes/Folder.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/javascript/unit/components/routes/Folder.spec.ts')
-rw-r--r--tests/javascript/unit/components/routes/Folder.spec.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/javascript/unit/components/routes/Folder.spec.ts b/tests/javascript/unit/components/routes/Folder.spec.ts
new file mode 100644
index 000000000..c2c966adb
--- /dev/null
+++ b/tests/javascript/unit/components/routes/Folder.spec.ts
@@ -0,0 +1,89 @@
+import Vuex, { Store } from 'vuex'
+import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'
+
+import Folder from '../../../../../src/components/routes/Folder.vue'
+import FeedItemDisplayList from '../../../../../src/components/feed-display/FeedItemDisplayList.vue'
+
+jest.mock('@nextcloud/axios')
+
+describe('Folder.vue', () => {
+ 'use strict'
+ const localVue = createLocalVue()
+ localVue.use(Vuex)
+ let wrapper: Wrapper<Folder>
+
+ const mockFeed = {
+ id: 789,
+ title: 'feed name',
+ unreadCount: 2,
+ folderId: 123,
+ }
+
+ const mockFeed2 = {
+ id: 456,
+ title: 'feed name 2',
+ unreadCount: 2,
+ folderId: 123,
+ }
+
+ const mockFolder = {
+ id: 123,
+ name: 'folder name',
+ }
+
+ let store: Store<any>
+ beforeAll(() => {
+ store = new Vuex.Store({
+ state: {
+ items: {
+ fetchingItems: {
+ 'folder-123': false,
+ },
+ allItems: [{
+ feedId: 789,
+ title: 'feed item',
+ }, {
+ feedId: 456,
+ title: 'feed item 2',
+ }],
+ },
+ },
+ actions: {
+ },
+ getters: {
+ feeds: () => [mockFeed, mockFeed2],
+ folders: () => [mockFolder],
+ },
+ })
+
+ store.dispatch = jest.fn()
+ store.commit = jest.fn()
+
+ wrapper = shallowMount(Folder, {
+ propsData: {
+ folderId: '123',
+ },
+ mocks: {
+ $route: {
+ params: {},
+ },
+ },
+ localVue,
+ store,
+ })
+ })
+
+ it('should display feed title and unread count', () => {
+ expect(wrapper.find('.header').text()).toContain(mockFolder.name)
+ expect(wrapper.find('.header').text()).toContain((mockFeed.unreadCount + mockFeed2.unreadCount).toString())
+ })
+
+ it('should get folder items from state', () => {
+ expect((wrapper.findComponent(FeedItemDisplayList)).props().items.length).toEqual(2)
+ })
+
+ it('should dispatch FETCH_FOLDER_FEED_ITEMS action on fetchMore', () => {
+ (wrapper.vm as any).fetchMore()
+ expect(store.dispatch).toBeCalled()
+ })
+})