From f7cfe8867c498e63f3142e3221a0c421bf8fff43 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Mon, 28 Oct 2019 23:19:58 +0900 Subject: [PATCH] refs #1065 Add a spec to test isOwnProfile getter --- .../Contents/SideBar/AccountProfile.spec.ts | 198 ++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 spec/renderer/integration/store/TimelineSpace/Contents/SideBar/AccountProfile.spec.ts diff --git a/spec/renderer/integration/store/TimelineSpace/Contents/SideBar/AccountProfile.spec.ts b/spec/renderer/integration/store/TimelineSpace/Contents/SideBar/AccountProfile.spec.ts new file mode 100644 index 00000000..78996218 --- /dev/null +++ b/spec/renderer/integration/store/TimelineSpace/Contents/SideBar/AccountProfile.spec.ts @@ -0,0 +1,198 @@ +import { Account } from 'megalodon' +import { createLocalVue } from '@vue/test-utils' +import Vuex from 'vuex' +import AccountProfile, { AccountProfileState } from '~/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile' + +const state = (account: Account | null): AccountProfileState => { + return { + loading: false, + relationship: null, + account: account + } +} + +const timelineSpace = { + namespaced: true, + state: { + account: { + baseURL: 'https://example.com', + domain: 'example.com', + clientId: 'sampleId', + clientSecret: 'sampleSecret', + accessToken: 'sampleAccessToken', + refreshToken: null, + username: 'h3poteto', + accountID: '1', + avatar: null, + order: 1 + } + } +} + +const initStore = (account: Account | null) => { + return { + namespaced: true, + state: state(account), + actions: AccountProfile.actions, + mutations: AccountProfile.mutations, + getters: AccountProfile.getters + } +} + +describe('AccountProfile', () => { + let store + let localVue + + beforeEach(() => { + localVue = createLocalVue() + localVue.use(Vuex) + store = new Vuex.Store({ + modules: { + AccountProfile: initStore(null), + TimelineSpace: timelineSpace + } + }) + }) + + describe('isOwnProfile', () => { + describe('target is a same Mastodon account', () => { + const account: Account = { + id: '1', + username: 'h3poteto', + acct: 'h3poteto@example.com', + display_name: 'h3poteto', + locked: false, + created_at: '2019-10-28T23:11:54', + followers_count: 100, + following_count: 200, + statuses_count: 500, + note: '', + url: 'https://example.com/@h3poteto', + avatar: '', + avatar_static: '', + header: '', + header_static: '', + emojis: [], + moved: null, + fields: null, + bot: false + } + beforeEach(() => { + store = new Vuex.Store({ + modules: { + AccountProfile: initStore(account), + TimelineSpace: timelineSpace + } + }) + }) + it('should be matched', () => { + expect(store.getters['AccountProfile/isOwnProfile']).toBeTruthy() + }) + }) + + describe('target is another Mastodon account', () => { + const account: Account = { + id: '1', + username: 'h3poteto', + acct: 'h3poteto@another.example.com', + display_name: 'h3poteto', + locked: false, + created_at: '2019-10-28T23:11:54', + followers_count: 100, + following_count: 200, + statuses_count: 500, + note: '', + url: 'https://another.example.com/@h3poteto', + avatar: '', + avatar_static: '', + header: '', + header_static: '', + emojis: [], + moved: null, + fields: null, + bot: false + } + beforeEach(() => { + store = new Vuex.Store({ + modules: { + AccountProfile: initStore(account), + TimelineSpace: timelineSpace + } + }) + }) + it('should be matched', () => { + expect(store.getters['AccountProfile/isOwnProfile']).toBeFalsy() + }) + }) + + describe('target is a same Pleroma account', () => { + const account: Account = { + id: '1', + username: 'h3poteto', + acct: 'h3poteto@example.com', + display_name: 'h3poteto', + locked: false, + created_at: '2019-10-28T23:11:54', + followers_count: 100, + following_count: 200, + statuses_count: 500, + note: '', + url: 'https://example.com/users/h3poteto', + avatar: '', + avatar_static: '', + header: '', + header_static: '', + emojis: [], + moved: null, + fields: null, + bot: false + } + beforeEach(() => { + store = new Vuex.Store({ + modules: { + AccountProfile: initStore(account), + TimelineSpace: timelineSpace + } + }) + }) + it('should be matched', () => { + expect(store.getters['AccountProfile/isOwnProfile']).toBeTruthy() + }) + }) + + describe('target is another Pleroma account', () => { + const account: Account = { + id: '1', + username: 'h3poteto', + acct: 'h3poteto@another.example.com', + display_name: 'h3poteto', + locked: false, + created_at: '2019-10-28T23:11:54', + followers_count: 100, + following_count: 200, + statuses_count: 500, + note: '', + url: 'https://another.example.com/users/h3poteto', + avatar: '', + avatar_static: '', + header: '', + header_static: '', + emojis: [], + moved: null, + fields: null, + bot: false + } + beforeEach(() => { + store = new Vuex.Store({ + modules: { + AccountProfile: initStore(account), + TimelineSpace: timelineSpace + } + }) + }) + it('should be matched', () => { + expect(store.getters['AccountProfile/isOwnProfile']).toBeFalsy() + }) + }) + }) +})