Merge pull request #939 from h3poteto/iss-209

refs #209 Add integration tests for Contents
This commit is contained in:
AkiraFukushima 2019-06-18 22:14:26 +09:00 committed by GitHub
commit a4c5f3e914
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 2403 additions and 21 deletions

View File

@ -1,3 +1,4 @@
import { Event } from 'electron'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Theme from '~/src/constants/theme' import Theme from '~/src/constants/theme'
@ -52,14 +53,14 @@ describe('Preferences/Appearance', () => {
App: App App: App
} }
}) })
ipcMain.once('update-preferences', (event: any, config: any) => { ipcMain.once('update-preferences', (event: Event, config: any) => {
event.sender.send('response-update-preferences', config) event.sender.send('response-update-preferences', config)
}) })
}) })
describe('load', () => { describe('load', () => {
it('loadAppearance', async () => { it('loadAppearance', async () => {
ipcMain.once('get-preferences', (event: any, _) => { ipcMain.once('get-preferences', (event: Event, _) => {
event.sender.send('response-get-preferences', { event.sender.send('response-get-preferences', {
appearance: { appearance: {
theme: Theme.Dark.key, theme: Theme.Dark.key,
@ -72,7 +73,7 @@ describe('Preferences/Appearance', () => {
expect(store.state.Preferences.appearance.fontSize).toEqual(15) expect(store.state.Preferences.appearance.fontSize).toEqual(15)
}) })
it('loadFonts', async () => { it('loadFonts', async () => {
ipcMain.once('list-fonts', (event, _) => { ipcMain.once('list-fonts', (event: Event, _) => {
event.sender.send('response-list-fonts', ['my-font']) event.sender.send('response-list-fonts', ['my-font'])
}) })
await store.dispatch('Preferences/loadFonts') await store.dispatch('Preferences/loadFonts')

View File

@ -0,0 +1,195 @@
import { Response, Status, Account, Application } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import DirectMessages, { DirectMessagesState } from '@/store/TimelineSpace/Contents/DirectMessages'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'fuga',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
let state = (): DirectMessagesState => {
return {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: [],
filter: ''
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: DirectMessages.actions,
mutations: DirectMessages.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Home', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
DirectMessages: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchTimeline', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const statuses = await store.dispatch('DirectMessages/fetchTimeline')
expect(statuses).toEqual([status1])
expect(store.state.DirectMessages.timeline).toEqual([status1])
})
})
describe('lazyFetchTimeline', () => {
describe('success', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [status1],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
}
})
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('DirectMessages/lazyFetchTimeline', status1)
expect(store.state.DirectMessages.lazyLoading).toEqual(false)
expect(store.state.DirectMessages.timeline).toEqual([status1, status2])
})
})
})
})

View File

@ -0,0 +1,312 @@
import { Response, Status, Account, Application } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Favourites, { FavouritesState } from '@/store/TimelineSpace/Contents/Favourites'
import { LocalAccount } from '~/src/types/localAccount'
jest.mock('megalodon')
const localAccount: LocalAccount = {
_id: '1',
baseURL: 'http://localhost',
domain: 'localhost',
clientId: 'id',
clientSecret: 'secret',
accessToken: 'token',
refreshToken: null,
username: 'hoge',
accountId: '1',
avatar: null,
order: 1
}
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'fuga',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
let state = (): FavouritesState => {
return {
favourites: [],
lazyLoading: false,
filter: '',
maxId: null
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Favourites.actions,
mutations: Favourites.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Favourites', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Favourites: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchFavourites', () => {
it('does not exist header', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/fetchFavourites', localAccount)
expect(store.state.Favourites.favourites).toEqual([status1])
expect(store.state.Favourites.maxId).toEqual(null)
})
it('link is null', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {
link: null
}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/fetchFavourites', localAccount)
expect(store.state.Favourites.favourites).toEqual([status1])
expect(store.state.Favourites.maxId).toEqual(null)
})
it('link exists in header', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {
link: '<http://localhost?max_id=2>; rel="next"'
}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/fetchFavourites', localAccount)
expect(store.state.Favourites.favourites).toEqual([status1])
expect(store.state.Favourites.maxId).toEqual('2')
})
})
describe('lazyFetchFavourites', () => {
describe('lazyLoading', () => {
beforeAll(() => {
state = () => {
return {
favourites: [],
lazyLoading: true,
filter: '',
maxId: null
}
}
})
it('should not be updated', async () => {
const res = await store.dispatch('Favourites/lazyFetchFavourites')
expect(res).toEqual(null)
})
})
describe('does not exist maxId', () => {
beforeAll(() => {
state = () => {
return {
favourites: [],
lazyLoading: false,
filter: '',
maxId: null
}
}
})
it('should not be updated', async () => {
const res = await store.dispatch('Favourites/lazyFetchFavourites')
expect(res).toEqual(null)
})
})
describe('fetch', () => {
beforeAll(() => {
state = () => {
return {
favourites: [status1],
lazyLoading: false,
filter: '',
maxId: '2'
}
}
})
it('link is null', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status2],
status: 200,
statusText: 'OK',
headers: {
link: null
}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/lazyFetchFavourites')
expect(store.state.Favourites.favourites).toEqual([status1, status2])
expect(store.state.Favourites.maxId).toEqual(null)
})
it('link exists in header', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status2],
status: 200,
statusText: 'OK',
headers: {
link: '<http://localhost?max_id=3>; rel="next"'
}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/lazyFetchFavourites')
expect(store.state.Favourites.favourites).toEqual([status1, status2])
expect(store.state.Favourites.maxId).toEqual('3')
})
})
})
})

View File

@ -0,0 +1,201 @@
import { Account, Response } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import FollowRequests, { FollowRequestsState } from '@/store/TimelineSpace/Contents/FollowRequests'
import { SideMenuState } from '@/store/TimelineSpace/SideMenu'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
let state = (): FollowRequestsState => {
return {
requests: []
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: FollowRequests.actions,
mutations: FollowRequests.mutations
}
}
const sideMenuState = (): SideMenuState => {
return {
unreadHomeTimeline: false,
unreadNotifications: false,
unreadMentions: false,
unreadLocalTimeline: false,
unreadDirectMessagesTimeline: false,
unreadPublicTimeline: false,
unreadFollowRequests: false,
lists: [],
tags: [],
collapse: false
}
}
const sideMenuStore = {
namespaced: true,
state: sideMenuState(),
actions: {
fetchFollowRequests: jest.fn()
},
mutations: {}
}
const timelineState = {
namespaced: true,
modules: {
SideMenu: sideMenuStore
},
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Home', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
FollowRequests: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchRequests', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Account>>>(resolve => {
const res: Response<Array<Account>> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('FollowRequests/fetchRequests')
expect(store.state.FollowRequests.requests).toEqual([account])
})
})
describe('acceptRequest', () => {
beforeAll(() => {
state = () => {
return {
requests: [account]
}
}
})
it('should be succeed', async () => {
const mockClient = {
post: (_path: string, _params: object) => {
return new Promise<Response<{}>>(resolve => {
const res: Response<{}> = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Account>>>(resolve => {
const res: Response<Array<Account>> = {
data: [],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('FollowRequests/acceptRequest', account)
expect(store.state.FollowRequests.requests).toEqual([])
})
})
describe('rejectRequest', () => {
beforeAll(() => {
state = () => {
return {
requests: [account]
}
}
})
it('should be succeed', async () => {
const mockClient = {
post: (_path: string, _params: object) => {
return new Promise<Response<{}>>(resolve => {
const res: Response<{}> = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Account>>>(resolve => {
const res: Response<Array<Account>> = {
data: [],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('FollowRequests/rejectRequest', account)
expect(store.state.FollowRequests.requests).toEqual([])
})
})
})

View File

@ -0,0 +1,68 @@
import { Event } from 'electron'
import { createLocalVue } from '@vue/test-utils'
import { ipcMain } from '~/spec/mock/electron'
import Vuex from 'vuex'
import { LocalTag } from '~/src/types/localTag'
import List, { ListState } from '@/store/TimelineSpace/Contents/Hashtag/List'
const tag1: LocalTag = {
tagName: 'tag1',
_id: '1'
}
const tag2: LocalTag = {
tagName: 'tag2',
_id: '2'
}
const state = (): ListState => {
return {
tags: []
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: List.actions,
mutations: List.mutations
}
}
describe('Hashtag/List', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
List: initStore()
}
})
})
describe('listTags', () => {
it('should be updated', async () => {
ipcMain.once('list-hashtags', (event: Event) => {
event.sender.send('response-list-hashtags', [tag1, tag2])
})
await store.dispatch('List/listTags')
expect(store.state.List.tags).toEqual([tag1, tag2])
})
})
describe('removeTag', () => {
it('should be updated', async () => {
ipcMain.once('remove-hashtag', async () => {
ipcMain.once('remove-hashtag', (event: Event, tag: LocalTag) => {
expect(tag).toEqual(tag1)
event.sender.send('response-remove-hashtag')
})
await store.dispatch('List/removeTag', tag1)
})
})
})
})

View File

@ -0,0 +1,198 @@
import { Response, Status, Account, Application } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Tag, { TagState } from '@/store/TimelineSpace/Contents/Hashtag/Tag'
import { LoadPositionWithTag } from '@/types/loadPosition'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'fuga',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
let state = (): TagState => {
return {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: [],
filter: ''
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Tag.actions,
mutations: Tag.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Home', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Tag: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetch', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const statuses = await store.dispatch('Tag/fetch', 'tag')
expect(statuses).toEqual([status1])
expect(store.state.Tag.timeline).toEqual([status1])
})
})
describe('lazyFetchTimeline', () => {
describe('success', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [status1],
unreadTimeline: [],
filter: ''
}
}
})
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const loadPositionWithTag: LoadPositionWithTag = {
status: status1,
tag: 'tag'
}
await store.dispatch('Tag/lazyFetchTimeline', loadPositionWithTag)
expect(store.state.Tag.lazyLoading).toEqual(false)
expect(store.state.Tag.timeline).toEqual([status1, status2])
})
})
})
})

View File

@ -139,8 +139,8 @@ describe('Home', () => {
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { const mockClient = {
get: (_path: string, _params: object) => { get: (_path: string, _params: object) => {
return new Promise<Response<Status[]>>(resolve => { return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Status[]> = { const res: Response<Array<Status>> = {
data: [status1], data: [status1],
status: 200, status: 200,
statusText: 'OK', statusText: 'OK',
@ -176,8 +176,8 @@ describe('Home', () => {
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { const mockClient = {
get: (_path: string, _params: object) => { get: (_path: string, _params: object) => {
return new Promise<Response<[Status]>>(resolve => { return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<[Status]> = { const res: Response<Array<Status>> = {
data: [status2], data: [status2],
status: 200, status: 200,
statusText: 'OK', statusText: 'OK',
@ -188,7 +188,7 @@ describe('Home', () => {
} }
} }
mockedMegalodon.mockImplementation(() => mockClient) mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Home/lazyFetchTimeline', { id: 20 }) await store.dispatch('Home/lazyFetchTimeline', status1)
expect(store.state.Home.lazyLoading).toEqual(false) expect(store.state.Home.lazyLoading).toEqual(false)
expect(store.state.Home.timeline).toEqual([status1, status2]) expect(store.state.Home.timeline).toEqual([status1, status2])
}) })

View File

@ -0,0 +1,120 @@
import { Response, Account } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Edit, { EditState } from '@/store/TimelineSpace/Contents/Lists/Edit'
import { RemoveAccountFromList } from '@/types/removeAccountFromList'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
let state = (): EditState => {
return {
members: []
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Edit.actions,
mutations: Edit.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Lists/Edit', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Edit: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchMembers', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Account>>>(resolve => {
const res: Response<Array<Account>> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Edit/fetchMembers', 'id')
expect(store.state.Edit.members).toEqual([account])
})
})
describe('removeAccount', () => {
it('should be removed', async () => {
const mockClient = {
del: (_path: string, _params: object) => {
return new Promise<Response<{}>>(resolve => {
const res: Response<{}> = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const removeFromList: RemoveAccountFromList = {
account: account,
listId: 'id'
}
const res = await store.dispatch('Edit/removeAccount', removeFromList)
expect(res.data).toEqual({})
})
})
})

View File

@ -0,0 +1,98 @@
import { Response, List } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Index, { IndexState } from '@/store/TimelineSpace/Contents/Lists/Index'
jest.mock('megalodon')
const list: List = {
id: '1',
title: 'list1'
}
let state = (): IndexState => {
return {
lists: []
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Index.actions,
mutations: Index.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Lists/Index', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Index: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchLists', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<List>>>(resolve => {
const res: Response<Array<List>> = {
data: [list],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Index/fetchLists')
expect(store.state.Index.lists).toEqual([list])
})
})
describe('createList', () => {
it('should be created', async () => {
const mockClient = {
post: (_path: string, _params: object) => {
return new Promise<Response<List>>(resolve => {
const res: Response<List> = {
data: list,
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const res: List = await store.dispatch('Index/createList', 'list1')
expect(res.title).toEqual('list1')
})
})
})

View File

@ -0,0 +1,198 @@
import { Response, Status, Account, Application } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Show, { ShowState } from '@/store/TimelineSpace/Contents/Lists/Show'
import { LoadPositionWithList } from '@/types/loadPosition'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'fuga',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
let state = (): ShowState => {
return {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: [],
filter: ''
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Show.actions,
mutations: Show.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Lists/Show', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Show: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchTimeline', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Show/fetchTimeline', '1')
expect(store.state.Show.timeline).toEqual([status1])
})
})
describe('lazyFetchTimeline', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [status1],
unreadTimeline: [],
filter: ''
}
}
})
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const loadPosition: LoadPositionWithList = {
status: status1,
list_id: '1'
}
await store.dispatch('Show/lazyFetchTimeline', loadPosition)
expect(store.state.Show.timeline).toEqual([status1, status2])
expect(store.state.Show.lazyLoading).toEqual(false)
})
})
})

View File

@ -0,0 +1,195 @@
import { Response, Status, Account, Application } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Local, { LocalState } from '@/store/TimelineSpace/Contents/Local'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'fuga',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
let state = (): LocalState => {
return {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: [],
filter: ''
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Local.actions,
mutations: Local.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Home', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Local: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchLocalTimeline', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const statuses = await store.dispatch('Local/fetchLocalTimeline')
expect(statuses).toEqual([status1])
expect(store.state.Local.timeline).toEqual([status1])
})
})
describe('lazyFetchTimeline', () => {
describe('success', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [status1],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
}
})
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Local/lazyFetchTimeline', status1)
expect(store.state.Local.lazyLoading).toEqual(false)
expect(store.state.Local.timeline).toEqual([status1, status2])
})
})
})
})

View File

@ -0,0 +1,262 @@
import { Response, Status, Account, Application, Notification } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon.ts'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Notifications, { NotificationsState } from '@/store/TimelineSpace/Contents/Notifications'
jest.mock('megalodon')
const account1: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const account2: Account = {
id: '2',
username: 'h3poteto',
acct: 'h3poteto@mstdn.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://mstdn.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account1,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account1,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const rebloggedStatus: Status = {
id: '3',
uri: 'http://example.com',
url: 'http://example.com',
account: account1,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: status2,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const notification1: Notification = {
id: '1',
account: account2,
status: status1,
type: 'favourite',
created_at: '2019-04-01T17:01:32'
}
const notification2: Notification = {
id: '2',
account: account2,
status: rebloggedStatus,
type: 'mention',
created_at: '2019-04-01T17:01:32'
}
let state = (): NotificationsState => {
return {
lazyLoading: false,
heading: true,
notifications: [],
unreadNotifications: [],
filter: ''
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Notifications.actions,
mutations: Notifications.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Notifications', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Notifications: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchNotifications', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Notification>>>(resolve => {
const res: Response<Array<Notification>> = {
data: [notification1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const response = await store.dispatch('Notifications/fetchNotifications')
expect(response).toEqual([notification1])
expect(store.state.Notifications.notifications).toEqual([notification1])
})
})
describe('lazyFetchNotifications', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: false,
heading: true,
notifications: [notification1],
unreadNotifications: [],
filter: ''
}
}
})
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Notification>>>(resolve => {
const res: Response<Array<Notification>> = {
data: [notification2],
status: 200,
statusText: '200',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Notifications/lazyFetchNotifications', notification1)
expect(store.state.Notifications.lazyLoading).toEqual(false)
expect(store.state.Notifications.notifications).toEqual([notification1, notification2])
})
})
})

View File

@ -0,0 +1,195 @@
import { Response, Status, Account, Application } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Public, { PublicState } from '@/store/TimelineSpace/Contents/Public'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'fuga',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
let state = (): PublicState => {
return {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: [],
filter: ''
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Public.actions,
mutations: Public.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Home', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Public: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('fetchPublicTimeline', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const statuses = await store.dispatch('Public/fetchPublicTimeline')
expect(statuses).toEqual([status1])
expect(store.state.Public.timeline).toEqual([status1])
})
})
describe('lazyFetchTimeline', () => {
describe('success', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [status1],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
}
})
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Public/lazyFetchTimeline', status1)
expect(store.state.Public.lazyLoading).toEqual(false)
expect(store.state.Public.timeline).toEqual([status1, status2])
})
})
})
})

View File

@ -0,0 +1,105 @@
import { Response, Account } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import AccountStore, { AccountState } from '@/store/TimelineSpace/Contents/Search/Account'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
let state = (): AccountState => {
return {
results: []
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: AccountStore.actions,
mutations: AccountStore.mutations
}
}
const contentsStore = {
namespaced: true,
state: {},
mutations: {
changeLoading: jest.fn()
},
actions: {}
}
const timelineState = {
namespaced: true,
modules: {
Contents: contentsStore
},
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Search/Account', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Account: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('search', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Account>>>(resolve => {
const res: Response<Array<Account>> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Account/search', 'query')
expect(store.state.Account.results).toEqual([account])
})
})
})

View File

@ -0,0 +1,93 @@
import { Response, Results, Tag } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import TagStore, { TagState } from '@/store/TimelineSpace/Contents/Search/Tag'
jest.mock('megalodon')
const tag1: Tag = {
name: 'tag1',
url: 'http://example.com/tag1',
history: null
}
let state = (): TagState => {
return {
results: []
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: TagStore.actions,
mutations: TagStore.mutations
}
}
const contentsStore = {
namespaced: true,
state: {},
mutations: {
changeLoading: jest.fn()
},
actions: {}
}
const timelineState = {
namespaced: true,
modules: {
Contents: contentsStore
},
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Search/Account', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Tag: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('search', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Results>>(resolve => {
const res: Response<Results> = {
data: {
accounts: [],
statuses: [],
hashtags: [tag1]
},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Tag/search', 'query')
expect(store.state.Tag.results).toEqual([tag1])
})
})
})

View File

@ -0,0 +1,140 @@
import { Response, Results, Status, Account, Application } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Toots, { TootsState } from '@/store/TimelineSpace/Contents/Search/Toots'
jest.mock('megalodon')
const account: Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: null,
bot: false
}
const status: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
application: {
name: 'Web'
} as Application,
language: null,
pinned: null
}
let state = (): TootsState => {
return {
results: []
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Toots.actions,
mutations: Toots.mutations
}
}
const contentsStore = {
namespaced: true,
state: {},
mutations: {
changeLoading: jest.fn()
},
actions: {}
}
const timelineState = {
namespaced: true,
modules: {
Contents: contentsStore
},
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Search/Account', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Toots: initStore(),
TimelineSpace: timelineState
}
})
mockedMegalodon.mockClear()
})
describe('search', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Results>>(resolve => {
const res: Response<Results> = {
data: {
accounts: [],
statuses: [status],
hashtags: []
},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Toots/search', 'query')
expect(store.state.Toots.results).toEqual([status])
})
})
})

View File

@ -44,7 +44,6 @@ const mutations: MutationTree<AppearanceState> = {
const actions: ActionTree<AppearanceState, RootState> = { const actions: ActionTree<AppearanceState, RootState> = {
loadAppearance: ({ commit }) => { loadAppearance: ({ commit }) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('get-preferences')
ipcRenderer.once('error-get-preferences', (_, err: Error) => { ipcRenderer.once('error-get-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-get-preferences') ipcRenderer.removeAllListeners('response-get-preferences')
reject(err) reject(err)
@ -54,11 +53,11 @@ const actions: ActionTree<AppearanceState, RootState> = {
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance) commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
resolve(conf) resolve(conf)
}) })
ipcRenderer.send('get-preferences')
}) })
}, },
loadFonts: ({ commit }) => { loadFonts: ({ commit }) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('list-fonts')
ipcRenderer.once('error-list-fonts', (_, err: Error) => { ipcRenderer.once('error-list-fonts', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-list-fonts') ipcRenderer.removeAllListeners('response-list-fonts')
reject(err) reject(err)
@ -68,6 +67,7 @@ const actions: ActionTree<AppearanceState, RootState> = {
commit(MUTATION_TYPES.UPDATE_FONTS, [DefaultFonts[0]].concat(fonts)) commit(MUTATION_TYPES.UPDATE_FONTS, [DefaultFonts[0]].concat(fonts))
resolve(fonts) resolve(fonts)
}) })
ipcRenderer.send('list-fonts')
}) })
}, },
updateTheme: ({ dispatch, commit, state }, themeKey: string) => { updateTheme: ({ dispatch, commit, state }, themeKey: string) => {
@ -78,7 +78,6 @@ const actions: ActionTree<AppearanceState, RootState> = {
appearance: newAppearance appearance: newAppearance
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (_, err: Error) => { ipcRenderer.once('error-update-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-update-preferences') ipcRenderer.removeAllListeners('response-update-preferences')
reject(err) reject(err)
@ -89,6 +88,7 @@ const actions: ActionTree<AppearanceState, RootState> = {
dispatch('App/loadPreferences', null, { root: true }) dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance) resolve(conf.appearance)
}) })
ipcRenderer.send('update-preferences', config)
}) })
}, },
updateFontSize: ({ dispatch, commit, state }, fontSize: number) => { updateFontSize: ({ dispatch, commit, state }, fontSize: number) => {
@ -99,7 +99,6 @@ const actions: ActionTree<AppearanceState, RootState> = {
appearance: newAppearance appearance: newAppearance
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (_, err: Error) => { ipcRenderer.once('error-update-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-update-preferences') ipcRenderer.removeAllListeners('response-update-preferences')
reject(err) reject(err)
@ -110,6 +109,7 @@ const actions: ActionTree<AppearanceState, RootState> = {
dispatch('App/loadPreferences', null, { root: true }) dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance) resolve(conf.appearance)
}) })
ipcRenderer.send('update-preferences', config)
}) })
}, },
updateDisplayNameStyle: ({ dispatch, commit, state }, value: number) => { updateDisplayNameStyle: ({ dispatch, commit, state }, value: number) => {
@ -120,7 +120,6 @@ const actions: ActionTree<AppearanceState, RootState> = {
appearance: newAppearance appearance: newAppearance
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (_, err: Error) => { ipcRenderer.once('error-update-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-update-preferences') ipcRenderer.removeAllListeners('response-update-preferences')
reject(err) reject(err)
@ -131,6 +130,7 @@ const actions: ActionTree<AppearanceState, RootState> = {
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance) commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
resolve(conf.appearance) resolve(conf.appearance)
}) })
ipcRenderer.send('update-preferences', config)
}) })
}, },
updateTimeFormat: ({ dispatch, commit, state }, value: number) => { updateTimeFormat: ({ dispatch, commit, state }, value: number) => {
@ -141,7 +141,6 @@ const actions: ActionTree<AppearanceState, RootState> = {
appearance: newAppearance appearance: newAppearance
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (_, err: Error) => { ipcRenderer.once('error-update-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-update-preferences') ipcRenderer.removeAllListeners('response-update-preferences')
reject(err) reject(err)
@ -152,6 +151,7 @@ const actions: ActionTree<AppearanceState, RootState> = {
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance) commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
resolve(conf.appearance) resolve(conf.appearance)
}) })
ipcRenderer.send('update-preferences', config)
}) })
}, },
updateCustomThemeColor: ({ dispatch, state, commit }, value: object) => { updateCustomThemeColor: ({ dispatch, state, commit }, value: object) => {
@ -163,7 +163,6 @@ const actions: ActionTree<AppearanceState, RootState> = {
appearance: newAppearance appearance: newAppearance
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (_, err: Error) => { ipcRenderer.once('error-update-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-update-preferences') ipcRenderer.removeAllListeners('response-update-preferences')
reject(err) reject(err)
@ -174,6 +173,7 @@ const actions: ActionTree<AppearanceState, RootState> = {
dispatch('App/loadPreferences', null, { root: true }) dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance) resolve(conf.appearance)
}) })
ipcRenderer.send('update-preferences', config)
}) })
}, },
updateFont: ({ dispatch, state, commit }, value: string) => { updateFont: ({ dispatch, state, commit }, value: string) => {
@ -184,7 +184,6 @@ const actions: ActionTree<AppearanceState, RootState> = {
appearance: newAppearance appearance: newAppearance
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (_, err: Error) => { ipcRenderer.once('error-update-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-update-preferences') ipcRenderer.removeAllListeners('response-update-preferences')
reject(err) reject(err)
@ -195,6 +194,7 @@ const actions: ActionTree<AppearanceState, RootState> = {
dispatch('App/loadPreferences', null, { root: true }) dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance) resolve(conf.appearance)
}) })
ipcRenderer.send('update-preferences', config)
}) })
}, },
updateTootPadding: ({ dispatch, state, commit }, value: number) => { updateTootPadding: ({ dispatch, state, commit }, value: number) => {
@ -205,7 +205,6 @@ const actions: ActionTree<AppearanceState, RootState> = {
appearance: newAppearance appearance: newAppearance
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('error-update-preferences', (_, err: Error) => { ipcRenderer.once('error-update-preferences', (_, err: Error) => {
ipcRenderer.removeAllListeners('response-update-preferences') ipcRenderer.removeAllListeners('response-update-preferences')
reject(err) reject(err)
@ -216,6 +215,7 @@ const actions: ActionTree<AppearanceState, RootState> = {
dispatch('App/loadPreferences', null, { root: true }) dispatch('App/loadPreferences', null, { root: true })
resolve(conf.appearance) resolve(conf.appearance)
}) })
ipcRenderer.send('update-preferences', config)
}) })
} }
} }

View File

@ -30,14 +30,14 @@ const actions: ActionTree<FollowRequestsState, RootState> = {
acceptRequest: async ({ dispatch, rootState }, user: Account) => { acceptRequest: async ({ dispatch, rootState }, user: Account) => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1') const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<{}> = await client.post<{}>(`/follow_requests/${user.id}/authorize`) const res: Response<{}> = await client.post<{}>(`/follow_requests/${user.id}/authorize`)
dispatch('fetchRequests') await dispatch('fetchRequests')
dispatch('TimelineSpace/SideMenu/fetchFollowRequests', rootState.TimelineSpace.account, { root: true }) dispatch('TimelineSpace/SideMenu/fetchFollowRequests', rootState.TimelineSpace.account, { root: true })
return res.data return res.data
}, },
rejectRequest: async ({ dispatch, rootState }, user: Account) => { rejectRequest: async ({ dispatch, rootState }, user: Account) => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1') const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<{}> = await client.post<{}>(`/follow_requests/${user.id}/reject`) const res: Response<{}> = await client.post<{}>(`/follow_requests/${user.id}/reject`)
dispatch('fetchRequests') await dispatch('fetchRequests')
dispatch('TimelineSpace/SideMenu/fetchFollowRequests', rootState.TimelineSpace.account, { root: true }) dispatch('TimelineSpace/SideMenu/fetchFollowRequests', rootState.TimelineSpace.account, { root: true })
return res.data return res.data
} }

View File

@ -94,7 +94,7 @@ const mutations: MutationTree<LocalState> = {
} }
const actions: ActionTree<LocalState, RootState> = { const actions: ActionTree<LocalState, RootState> = {
fetchLocalTimeline: async ({ commit, rootState }) => { fetchLocalTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1') const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/public', { limit: 40, local: true }) const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/public', { limit: 40, local: true })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data) commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)

View File

@ -94,10 +94,11 @@ const mutations: MutationTree<PublicState> = {
} }
const actions: ActionTree<PublicState, RootState> = { const actions: ActionTree<PublicState, RootState> = {
fetchPublicTimeline: async ({ commit, rootState }) => { fetchPublicTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1') const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/public', { limit: 40 }) const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/public', { limit: 40 })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data) commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
return res.data
}, },
lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Status): Promise<Array<Status> | null> => { lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Status): Promise<Array<Status> | null> => {
if (state.lazyLoading) { if (state.lazyLoading) {