summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevlin Junker <devlin.junker@gmail.com>2022-10-26 23:13:27 -0700
committerBenjamin Brahmer <info@b-brahmer.de>2022-11-02 11:27:20 +0100
commit3bf3bc17ce2848bcb682e1c37ce36c11984a4d1c (patch)
tree5b25e5f344cbc15612f1a0c21e590d8dde0098a9
parent431236bbd84fbdcf130100c7d5f861e3d54c5542 (diff)
fix tests with proper mocking
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
-rw-r--r--package-lock.json2
-rw-r--r--package.json2
-rw-r--r--src/components/Explore.vue4
-rw-r--r--src/components/Sidebar.vue2
-rw-r--r--tests/javascript/unit/OC.ts38
-rw-r--r--tests/javascript/unit/components/Explore.spec.ts11
-rw-r--r--tests/javascript/unit/setup.ts6
7 files changed, 52 insertions, 13 deletions
diff --git a/package-lock.json b/package-lock.json
index d2bce808a..56244019b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -7,7 +7,7 @@
"name": "nextcloud-news",
"license": "AGPL-3.0",
"dependencies": {
- "@nextcloud/axios": "^1.10.0",
+ "@nextcloud/axios": "^1.11.0",
"@nextcloud/dialogs": "^3.1.2",
"@nextcloud/router": "^2.0.0",
"@nextcloud/vue": "^7.0.1",
diff --git a/package.json b/package.json
index 789de98a6..ec9b8ea92 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
"private": true,
"homepage": "https://github.com/nextcloud/news",
"dependencies": {
- "@nextcloud/axios": "^1.10.0",
+ "@nextcloud/axios": "^1.11.0",
"@nextcloud/dialogs": "^3.1.2",
"@nextcloud/router": "^2.0.0",
"@nextcloud/vue": "^7.0.1",
diff --git a/src/components/Explore.vue b/src/components/Explore.vue
index 81ce3c060..691498fd3 100644
--- a/src/components/Explore.vue
+++ b/src/components/Explore.vue
@@ -56,8 +56,8 @@ const ExploreComponent = Vue.extend({
showAddFeed,
}
},
- created() {
- this.sites()
+ async created() {
+ await this.sites()
},
methods: {
diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue
index af57b181b..108d3e790 100644
--- a/src/components/Sidebar.vue
+++ b/src/components/Sidebar.vue
@@ -169,7 +169,7 @@ export default Vue.extend({
},
deleteFolder(folder: Folder) {
this.$store.dispatch('deleteFolder', { folder })
- window.location.reload()
+ // TODO: Reload
},
showShowAddFeed() {
this.showAddFeed = true
diff --git a/tests/javascript/unit/OC.ts b/tests/javascript/unit/OC.ts
new file mode 100644
index 000000000..cbc7c642e
--- /dev/null
+++ b/tests/javascript/unit/OC.ts
@@ -0,0 +1,38 @@
+export class OC {
+
+ generateUrl(url: any) {
+ return ''
+ }
+
+ imagePath(app: any, img: any) {
+ return ''
+ }
+
+ linkToRemote(app: any) {
+ return ''
+ }
+
+ getLanguage() {
+ return 'en-GB'
+ }
+
+ getLocale() {
+ return 'en_GB'
+ }
+
+ isUserAdmin() {
+ return false
+ }
+
+ L10N = {
+ translate(app: any, text: any) {
+ return text
+ },
+
+ translatePlural(app: any, text: any) {
+ return text
+ },
+ }
+
+ config = {}
+}
diff --git a/tests/javascript/unit/components/Explore.spec.ts b/tests/javascript/unit/components/Explore.spec.ts
index b0fe86a28..bd50fe592 100644
--- a/tests/javascript/unit/components/Explore.spec.ts
+++ b/tests/javascript/unit/components/Explore.spec.ts
@@ -1,18 +1,21 @@
-
+import axios from '@nextcloud/axios'
import { shallowMount } from '@vue/test-utils'
import { store, localVue } from '../setupStore'
-import axios from '@nextcloud/axios'
import * as router from '@nextcloud/router'
import Explore from 'Components/Explore.vue'
+jest.mock('@nextcloud/axios')
+
describe('Explore.vue', () => {
'use strict'
+
+
it('should initialize without showing AddFeed Component', () => {
- axios.get = jest.fn().mockResolvedValue({ data: { } })
- (router as any).generateUrl = jest.fn().mockReturnedValue('');
+ (axios as any).get.mockResolvedValue({ data: { } })
+ (router as any).generateUrl = jest.fn().mockReturnValue('');
const wrapper = shallowMount(Explore, { localVue, store })
diff --git a/tests/javascript/unit/setup.ts b/tests/javascript/unit/setup.ts
index ec9d61f8f..f3b734953 100644
--- a/tests/javascript/unit/setup.ts
+++ b/tests/javascript/unit/setup.ts
@@ -1,10 +1,8 @@
import { config } from '@vue/test-utils'
// Note: This was copied from nextcloud/tasks repo
-// import { OC } from './OC.js'
-
-// TODO: will this be used?
-// global.OC = new OC()
+import { OC } from './OC'
+(global as any).OC = new OC()
// Mock nextcloud translate functions
config.mocks.$t = function(_app: any, string: any) {