summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--package.json3
-rw-r--r--src/components/AddFeed.vue7
-rw-r--r--tests/javascript/helpers/CSSStub.js0
-rw-r--r--tests/javascript/unit/components/AddFeed.spec.ts79
-rw-r--r--tests/javascript/unit/store/feed.spec.ts71
5 files changed, 117 insertions, 43 deletions
diff --git a/package.json b/package.json
index 0cf1f6f76..3d58fb272 100644
--- a/package.json
+++ b/package.json
@@ -138,7 +138,8 @@
],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1",
- "^Components/(.*)$": "<rootDir>/src/components/$1"
+ "^Components/(.*)$": "<rootDir>/src/components/$1",
+ "^.+\\.(css|less)$": "<rootDir>/tests/javascript/helpers/CSSStub.js"
},
"testEnvironment": "jsdom",
"transform": {
diff --git a/src/components/AddFeed.vue b/src/components/AddFeed.vue
index 589d6650d..de688ba7f 100644
--- a/src/components/AddFeed.vue
+++ b/src/components/AddFeed.vue
@@ -154,13 +154,7 @@ export default Vue.extend({
}
},
methods: {
- created() {
-
- },
-
async addFeed() {
- let url = this.feedUrl;
-
this.$store.dispatch(ACTIONS.ADD_FEED, {
feedReq: {
url: this.feedUrl,
@@ -170,6 +164,7 @@ export default Vue.extend({
password: this.feedPassword === '' ? undefined : this.feedPassword
},
});
+
this.$emit('close');
},
diff --git a/tests/javascript/helpers/CSSStub.js b/tests/javascript/helpers/CSSStub.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/javascript/helpers/CSSStub.js
diff --git a/tests/javascript/unit/components/AddFeed.spec.ts b/tests/javascript/unit/components/AddFeed.spec.ts
index 66105e3f8..ce1a9581d 100644
--- a/tests/javascript/unit/components/AddFeed.spec.ts
+++ b/tests/javascript/unit/components/AddFeed.spec.ts
@@ -1,23 +1,86 @@
import { shallowMount, createLocalVue } from '@vue/test-utils'
-
import AddFeed from '../../../../src/components/AddFeed.vue'
+import { FEED_ACTION_TYPES } from '@/store/feed'
describe('AddFeed.vue', () => {
'use strict'
- it('should initialize without showing createNewFolder', () => {
+ let mockDispatch = jest.fn();
+ let mockStore = {
+ state: {
+ folders: { folders: [] },
+ feeds: { feeds: [] }
+ },
+ dispatch: mockDispatch
+ }
+
+ let wrapper: any
+ beforeEach(() => {
const localVue = createLocalVue()
- const wrapper = shallowMount(AddFeed, {
+ wrapper = shallowMount(AddFeed, {
localVue,
mocks: {
- $store: {
- state: {
- folders: [],
- },
- },
+ $store: mockStore,
},
})
+ })
+ it('should initialize with default values', () => {
expect(wrapper.vm.$data.createNewFolder).toBeFalsy()
+ expect(wrapper.vm.$data.autoDiscover).toBeTruthy()
+ expect(wrapper.vm.$data.withBasicAuth).toBeFalsy()
+ })
+
+ it('should dispatch ADD_FEED action to store', async () => {
+ wrapper.vm.$emit = jest.fn()
+
+ await wrapper.vm.addFeed()
+
+ expect(wrapper.vm.$emit).toBeCalled()
+ expect(mockDispatch).toBeCalled()
+ expect(mockDispatch.mock.calls[0][0]).toEqual(FEED_ACTION_TYPES.ADD_FEED);
+ })
+
+ it('should check if feed url exists and return true', () => {
+ wrapper.vm.$data.feedUrl = ''
+ let response = wrapper.vm.feedUrlExists()
+
+ expect(response).toBeFalsy()
+
+ wrapper.vm.$data.feedUrl = 'http://test.com'
+ response = wrapper.vm.feedUrlExists()
+
+ expect(response).toBeFalsy()
+
+ wrapper.vm.$data.feedUrl = 'http://test.com'
+ wrapper.vm.$store.state.feeds.feeds = [{ url: 'http://test.com'}]
+ response = wrapper.vm.feedUrlExists()
+
+ expect(response).toBeTruthy()
+ })
+
+ it('should check if folder name exists when creating folder and return true', () => {
+ wrapper.vm.$data.newFolderName = ''
+ let response = wrapper.vm.folderNameExists()
+
+ expect(response).toBeFalsy()
+
+ wrapper.vm.$data.newFolderName = 'test'
+ response = wrapper.vm.folderNameExists()
+
+ expect(response).toBeFalsy()
+
+ wrapper.vm.$data.newFolderName = 'test'
+ wrapper.vm.$store.state.folders.folders = [{ name: 'test'}]
+ response = wrapper.vm.folderNameExists()
+
+ expect(response).toBeFalsy()
+
+ wrapper.vm.$data.newFolderName = 'test'
+ wrapper.vm.$data.createNewFolder = 'test'
+ wrapper.vm.$store.state.folders.folders = [{ name: 'test'}]
+ response = wrapper.vm.folderNameExists()
+
+ expect(response).toBeTruthy()
})
})
diff --git a/tests/javascript/unit/store/feed.spec.ts b/tests/javascript/unit/store/feed.spec.ts
index 29df4b105..928820085 100644
--- a/tests/javascript/unit/store/feed.spec.ts
+++ b/tests/javascript/unit/store/feed.spec.ts
@@ -9,14 +9,27 @@ describe('feed.ts', () => {
'use strict'
describe('actions', () => {
- it('ADD_FEED should call POST and commit feed to state', async () => {
- (axios as any).post.mockResolvedValue()
- const commit = jest.fn()
- await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } })
- expect(axios.post).toBeCalled()
- expect(commit).toBeCalled()
+ describe('ADD_FEED', () => {
+ it('should call POST and commit feed to state', async () => {
+ (axios as any).post.mockResolvedValue({ data: { feeds: [] }})
+ const commit = jest.fn()
+ await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } })
+ expect(axios.post).toBeCalled()
+ expect(commit).toBeCalled()
+ })
+
+ it('should call POST and not call commit if error', async () => {
+ (axios as any).post.mockRejectedValue()
+ const commit = jest.fn()
+ await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } })
+ expect(axios.post).toBeCalled()
+
+ expect(commit).not.toBeCalled()
+ })
})
+
+
it('FETCH_FEEDS should call GET and commit returned feeds to state', async () => {
(axios as any).get.mockResolvedValue({ data: { feeds: [] } })
const commit = jest.fn()
@@ -27,29 +40,31 @@ describe('feed.ts', () => {
})
describe('mutations', () => {
- it('SET_FEEDS should add feeds to state', () => {
- const state = { feeds: [] as Feed[], folders: [] as any[] } as AppState
- let feeds = [] as Feed[]
-
- mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds)
- expect(state.feeds.length).toEqual(0)
-
- feeds = [{ title: 'test' }] as Feed[]
-
- mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds)
- expect(state.feeds.length).toEqual(1)
- expect(state.feeds[0]).toEqual(feeds[0])
+ describe('SET_FEEDS', () => {
+ it('should add feeds to state', () => {
+ const state = { feeds: [] as Feed[], folders: [] as any[] } as AppState
+ let feeds = [] as any
+
+ mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds)
+ expect(state.feeds.length).toEqual(0)
+
+ feeds = [{ title: 'test' }] as Feed[]
+
+ mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds)
+ expect(state.feeds.length).toEqual(1)
+ expect(state.feeds[0]).toEqual(feeds[0])
+ })
})
-
- it('SET_FEEDS should add feeds and unreadCount to folder if exists and folder set', () => {
- const state = { feeds: [] as Feed[], folders: [{ id: 1, feedCount: 3, feeds: [] as Feed[] }] } as AppState
- const feeds = [{ title: 'test', folderId: 1, unreadCount: 2 }] as Feed[]
-
- mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds)
- expect(state.feeds.length).toEqual(1)
- expect(state.feeds[0]).toEqual(feeds[0])
- expect(state.folders[0].feeds[0]).toEqual(feeds[0])
- expect(state.folders[0].feedCount).toEqual(5)
+
+ describe('ADD_FEED', () => {
+ it('should add a single feed to state', () => {
+ const state = { feeds: [] as Feed[], folders: [] as any[] } as AppState
+ let feed = { title: 'test' } as any;
+
+ mutations[FEED_MUTATION_TYPES.ADD_FEED](state, feed)
+ expect(state.feeds.length).toEqual(1)
+ expect(state.feeds[0]).toEqual(feed)
+ })
})
})
})