aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/karma.conf.js5
-rw-r--r--test/unit/specs/Hello.spec.js13
-rw-r--r--test/unit/specs/boot/routes.spec.js29
-rw-r--r--test/unit/specs/components/user_profile.spec.js219
-rw-r--r--test/unit/specs/services/user_profile_link_generator/user_profile_link_generator.spec.js15
5 files changed, 267 insertions, 14 deletions
diff --git a/test/unit/karma.conf.js b/test/unit/karma.conf.js
index 89f21b2e..d19a2229 100644
--- a/test/unit/karma.conf.js
+++ b/test/unit/karma.conf.js
@@ -56,7 +56,10 @@ module.exports = function (config) {
browsers: ['PhantomJS'],
frameworks: ['mocha', 'sinon-chai'],
reporters: ['mocha'],
- files: ['./index.js'],
+ files: [
+ '../../node_modules/@babel/polyfill/dist/polyfill.js',
+ './index.js'
+ ],
preprocessors: {
'./index.js': ['webpack', 'sourcemap']
},
diff --git a/test/unit/specs/Hello.spec.js b/test/unit/specs/Hello.spec.js
deleted file mode 100644
index d66e39ef..00000000
--- a/test/unit/specs/Hello.spec.js
+++ /dev/null
@@ -1,13 +0,0 @@
-// import Vue from 'vue'
-// import Hello from 'src/components/Hello'
-
-// describe('Hello.vue', () => {
-// xit('should render correct contents', () => {
-// const vm = new Vue({
-// el: document.createElement('div'),
-// render: (h) => h(Hello)
-// })
-// expect(vm.$el.querySelector('.hello h1').textContent)
-// .to.equal('Welcome to Your Vue.js App')
-// })
-// })
diff --git a/test/unit/specs/boot/routes.spec.js b/test/unit/specs/boot/routes.spec.js
new file mode 100644
index 00000000..9963555f
--- /dev/null
+++ b/test/unit/specs/boot/routes.spec.js
@@ -0,0 +1,29 @@
+import routes from 'src/boot/routes'
+import { createLocalVue } from '@vue/test-utils'
+import VueRouter from 'vue-router'
+
+const localVue = createLocalVue()
+localVue.use(VueRouter)
+
+describe('routes', () => {
+ const router = new VueRouter({
+ mode: 'abstract',
+ routes: routes({})
+ })
+
+ it('root path', () => {
+ router.push('/~/main/all')
+
+ const matchedComponents = router.getMatchedComponents()
+
+ expect(matchedComponents[0].components.hasOwnProperty('Timeline')).to.eql(true)
+ })
+
+ it('user\'s profile', () => {
+ router.push('/fake-user-name')
+
+ const matchedComponents = router.getMatchedComponents()
+
+ expect(matchedComponents[0].components.hasOwnProperty('UserCardContent')).to.eql(true)
+ })
+})
diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js
new file mode 100644
index 00000000..04092716
--- /dev/null
+++ b/test/unit/specs/components/user_profile.spec.js
@@ -0,0 +1,219 @@
+import { mount, createLocalVue } from '@vue/test-utils'
+import Vuex from 'vuex'
+import UserProfile from 'src/components/user_profile/user_profile.vue'
+import backendInteractorService from 'src/services/backend_interactor_service/backend_interactor_service.js'
+
+const localVue = createLocalVue()
+localVue.use(Vuex)
+
+const mutations = {
+ clearTimeline: () => {}
+}
+
+const externalProfileStore = new Vuex.Store({
+ mutations,
+ state: {
+ api: {
+ backendInteractor: backendInteractorService('')
+ },
+ config: {
+ colors: '',
+ highlight: {}
+ },
+ instance: {
+ hideUserStats: true
+ },
+ statuses: {
+ timelines: {
+ user: {
+ statuses: [],
+ statusesObject: {},
+ faves: [],
+ visibleStatuses: [],
+ visibleStatusesObject: {},
+ newStatusCount: 0,
+ maxId: 0,
+ minVisibleId: 0,
+ loading: false,
+ followers: [],
+ friends: [],
+ viewing: 'statuses',
+ userId: 701,
+ flushMarker: 0
+ }
+ }
+ },
+ users: {
+ currentUser: {
+ credentials: ''
+ },
+ usersObject: [
+ {
+ background_image: null,
+ cover_photo: 'https://playvicious.social/system/accounts/headers/000/000/001/original/7dae4fc0e8330e83.jpg?1507329206',
+ created_at: 'Mon Dec 18 16:01:35 +0000 2017',
+ default_scope: 'public',
+ description: "Your favorite person's favorite person.",
+ description_html: "<p>Your favorite person's favorite person.</p>",
+ favourites_count: 0,
+ fields: [
+ {
+ name: '✌🏾',
+ value: '<a href="https://thetwelfth.house" rel="me nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">thetwelfth.house</span><span class="invisible"></span></a>'
+ },
+ {
+ name: '🚧',
+ value: '<a href="https://code.playvicio.us" rel="me nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">code.playvicio.us</span><span class="invisible"></span></a>'
+ },
+ {
+ name: '❤️',
+ value: '<a href="https://www.patreon.com/Are0h" rel="me nofollow noopener" target="_blank"><span class="invisible">https://www.</span><span class="">patreon.com/Are0h</span><span class="invisible"></span></a>'
+ }
+ ],
+ followers_count: 2,
+ following: false,
+ follows_you: false,
+ friends_count: 0,
+ id: 701,
+ is_local: false,
+ locked: false,
+ name: 'Are0h',
+ name_html: 'Are0h',
+ no_rich_text: false,
+ profile_image_url: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
+ profile_image_url_https: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
+ profile_image_url_original: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
+ profile_image_url_profile_size: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
+ rights: {
+ delete_others_notice: false
+ },
+ screen_name: 'Are0h@playvicious.social',
+ statuses_count: 6727,
+ statusnet_blocking: false,
+ statusnet_profile_url: 'https://playvicious.social/users/Are0h'
+ }
+ ]
+ }
+ }
+})
+
+const localProfileStore = new Vuex.Store({
+ mutations,
+ state: {
+ api: {
+ backendInteractor: backendInteractorService('')
+ },
+ config: {
+ colors: '',
+ highlight: {}
+ },
+ instance: {
+ hideUserStats: true
+ },
+ statuses: {
+ timelines: {
+ user: {
+ statuses: [],
+ statusesObject: {},
+ faves: [],
+ visibleStatuses: [],
+ visibleStatusesObject: {},
+ newStatusCount: 0,
+ maxId: 0,
+ minVisibleId: 0,
+ loading: false,
+ followers: [],
+ friends: [],
+ viewing: 'statuses',
+ userId: 701,
+ flushMarker: 0
+ }
+ }
+ },
+ users: {
+ currentUser: {
+ credentials: ''
+ },
+ usersObject: [
+ {
+ background_image: null,
+ cover_photo: 'https://playvicious.social/system/accounts/headers/000/000/001/original/7dae4fc0e8330e83.jpg?1507329206',
+ created_at: 'Mon Dec 18 16:01:35 +0000 2017',
+ default_scope: 'public',
+ description: "Your favorite person's favorite person.",
+ description_html: "<p>Your favorite person's favorite person.</p>",
+ favourites_count: 0,
+ fields: [
+ {
+ name: '✌🏾',
+ value: '<a href="https://thetwelfth.house" rel="me nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">thetwelfth.house</span><span class="invisible"></span></a>'
+ },
+ {
+ name: '🚧',
+ value: '<a href="https://code.playvicio.us" rel="me nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">code.playvicio.us</span><span class="invisible"></span></a>'
+ },
+ {
+ name: '❤️',
+ value: '<a href="https://www.patreon.com/Are0h" rel="me nofollow noopener" target="_blank"><span class="invisible">https://www.</span><span class="">patreon.com/Are0h</span><span class="invisible"></span></a>'
+ }
+ ],
+ followers_count: 2,
+ following: false,
+ follows_you: false,
+ friends_count: 0,
+ id: 701,
+ is_local: false,
+ locked: false,
+ name: 'Are0h',
+ name_html: 'Are0h',
+ no_rich_text: false,
+ profile_image_url: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
+ profile_image_url_https: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
+ profile_image_url_original: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
+ profile_image_url_profile_size: 'https://playvicious.social/system/accounts/avatars/000/000/001/original/33e9983bc2d96aeb.png?1520872572',
+ rights: {
+ delete_others_notice: false
+ },
+ screen_name: 'Are0h',
+ statuses_count: 6727,
+ statusnet_blocking: false,
+ statusnet_profile_url: 'https://playvicious.social/users/Are0h'
+ }
+ ]
+ }
+ }
+})
+
+describe('UserProfile', () => {
+ it('renders external profile', () => {
+ const wrapper = mount(UserProfile, {
+ localVue,
+ store: externalProfileStore,
+ mocks: {
+ $route: {
+ params: { id: 701 },
+ name: 'external-user-profile'
+ },
+ $t: (msg) => msg
+ }
+ })
+
+ expect(wrapper.find('.user-screen-name').text()).to.eql('@Are0h@playvicious.social')
+ })
+
+ it('renders local profile', () => {
+ const wrapper = mount(UserProfile, {
+ localVue,
+ store: localProfileStore,
+ mocks: {
+ $route: {
+ params: { name: 'Are0h' },
+ name: 'user-profile'
+ },
+ $t: (msg) => msg
+ }
+ })
+
+ expect(wrapper.find('.user-screen-name').text()).to.eql('@Are0h')
+ })
+})
diff --git a/test/unit/specs/services/user_profile_link_generator/user_profile_link_generator.spec.js b/test/unit/specs/services/user_profile_link_generator/user_profile_link_generator.spec.js
new file mode 100644
index 00000000..4366f799
--- /dev/null
+++ b/test/unit/specs/services/user_profile_link_generator/user_profile_link_generator.spec.js
@@ -0,0 +1,15 @@
+import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
+
+describe('generateProfileLink', () => {
+ it('returns obj for local user', () => {
+ expect(generateProfileLink(1, 'jack')).to.eql({
+ name: 'user-profile', params: { name: 'jack' }
+ })
+ })
+
+ it('returns obj for external user', () => {
+ expect(generateProfileLink(1, 'john@domain')).to.eql({
+ name: 'external-user-profile', params: { id: 1 }
+ })
+ })
+})