-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests and little more cleanup of uncessary lines
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
- Loading branch information
1 parent
7e21dc8
commit dce0701
Showing
6 changed files
with
213 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Vuex, { Store } from 'vuex' | ||
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils' | ||
|
||
import All from '../../../../../src/components/routes/All.vue' | ||
import FeedItemDisplayList from '../../../../../src/components/feed-display/FeedItemDisplayList.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', () => { | ||
expect((wrapper.findComponent(FeedItemDisplayList)).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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters