Fix megalodon class for 3.0.0 in spec

This commit is contained in:
AkiraFukushima 2020-03-15 17:48:02 +09:00
parent 0200f69e1d
commit 4dceedb3ef
33 changed files with 876 additions and 998 deletions

View File

@ -1,10 +0,0 @@
import Mastodon, { MegalodonInstance } from 'megalodon'
interface MockedMegalodon extends MegalodonInstance {
mockResolvedValue: Function
mockImplementation: Function
mockClear: Function
}
const mockedMegalodon: jest.Mocked<MockedMegalodon> = Mastodon as any
export default mockedMegalodon

View File

@ -1,12 +1,15 @@
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import { ipcMain, ipcRenderer } from '~/spec/mock/electron' import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
import Mastodon, { Instance, Response } from 'megalodon'
import Login, { LoginState } from '@/store/Login' import Login, { LoginState } from '@/store/Login'
import { MyWindow } from '~/src/types/global' import { MyWindow } from '~/src/types/global'
;(window as MyWindow).ipcRenderer = ipcRenderer ;(window as MyWindow).ipcRenderer = ipcRenderer
jest.mock('megalodon') jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
detector: jest.fn(() => 'pleroma'),
__esModule: true
}))
const state = (): LoginState => { const state = (): LoginState => {
return { return {
@ -77,56 +80,6 @@ describe('Login', () => {
describe('confirmInstance', () => { describe('confirmInstance', () => {
it('should change instance', async () => { it('should change instance', async () => {
// Provide Promise.resolve for finally keywrod.
// https://github.com/facebook/jest/issues/6552
// https://github.com/kulshekhar/ts-jest/issues/828
const mockedClient = Mastodon as any
const instance: Promise<Response<Instance>> = new Promise<Response<Instance>>(resolve => {
const res: Response<Instance> = {
data: {
uri: 'http://example.com',
title: 'test-mastodon',
description: 'description',
email: 'hoge@example.com',
version: '1.0.0',
thumbnail: null,
urls: {
streaming_api: 'http://example.com'
},
stats: {
user_count: 1,
status_count: 10,
domain_count: 10
},
languages: ['en'],
contact_account: null
} as Instance,
status: 200,
statusText: '200',
headers: null
}
resolve(res)
})
mockedClient.get.mockImplementation(() => instance)
const result = await store.dispatch('Login/confirmInstance', 'pleroma.io')
expect(result).toEqual(true)
expect(store.state.Login.selectedInstance).toEqual('pleroma.io')
})
it('should failover host-meta', async () => {
const mockedClient = Mastodon as any
// @ts-ignore
const instance: Promise<any> = new Promise<any>((resolve, reject) => {
const err = new Error('err')
reject(err)
})
const hostMeta: Promise<{}> = new Promise<{}>(resolve => {
resolve({
data:
'<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="https://pleroma.io/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>'
})
})
mockedClient.get.mockImplementationOnce(() => instance).mockImplementationOnce(() => hostMeta)
const result = await store.dispatch('Login/confirmInstance', 'pleroma.io') const result = await store.dispatch('Login/confirmInstance', 'pleroma.io')
expect(result).toEqual(true) expect(result).toEqual(true)
expect(store.state.Login.selectedInstance).toEqual('pleroma.io') expect(store.state.Login.selectedInstance).toEqual('pleroma.io')

View File

@ -1,4 +1,4 @@
import Mastodon, { Emoji, Instance, Response } from 'megalodon' import { Entity, Response } from 'megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import { ipcMain, ipcRenderer } from '~/spec/mock/electron' import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
@ -7,9 +7,20 @@ import unreadSettings from '~/src/constants/unreadNotification'
import { MyWindow } from '~/src/types/global' import { MyWindow } from '~/src/types/global'
;(window as MyWindow).ipcRenderer = ipcRenderer ;(window as MyWindow).ipcRenderer = ipcRenderer
jest.mock('megalodon') const emacsEmoji: Entity.Emoji = {
shortcode: 'emacs',
url: 'http://example.com/emacs',
static_url: 'http://example.com/emacs',
visible_in_picker: true
}
const rubyEmoji: Entity.Emoji = {
shortcode: 'ruby',
url: 'http://example.com/ruby',
static_url: 'http://example.com/ruby',
visible_in_picker: true
}
const mockedInstance: Instance = { const mockedInstance: Entity.Instance = {
uri: 'http://pleroma.io', uri: 'http://pleroma.io',
title: 'pleroma', title: 'pleroma',
description: '', description: '',
@ -29,6 +40,38 @@ const mockedInstance: Instance = {
max_toot_chars: 5000 max_toot_chars: 5000
} }
const mockClient = {
getInstance: () => {
return new Promise<Response<Entity.Instance>>(resolve => {
const res: Response<Entity.Instance> = {
data: mockedInstance,
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
getInstanceCustomEmojis: () => {
return new Promise<Response<Array<Entity.Emoji>>>(resolve => {
const res: Response<Array<Entity.Emoji>> = {
data: [emacsEmoji, rubyEmoji],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
detector: jest.fn(() => 'pleroma'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const state = (): TimelineSpaceState => { const state = (): TimelineSpaceState => {
return { return {
account: blankAccount, account: blankAccount,
@ -41,7 +84,7 @@ const state = (): TimelineSpaceState => {
local: true, local: true,
public: true public: true
}, },
pleroma: false sns: 'mastodon'
} }
} }
@ -169,117 +212,26 @@ describe('TimelineSpace', () => {
}) })
}) })
describe('detectPleroma', () => { describe('detectSNS', () => {
describe('API is pleroma', () => { describe('API is pleroma', () => {
let mockedResponse: Response<Instance>
beforeEach(() => {
mockedResponse = {
data: mockedInstance,
status: 200,
statusText: 'OK',
headers: {}
}
})
it('should be detected', async () => { it('should be detected', async () => {
;(Mastodon.get as any).mockResolvedValue(mockedResponse) await store.dispatch('TimelineSpace/detectSNS')
await store.dispatch('TimelineSpace/detectPleroma') expect(store.state.TimelineSpace.sns).toEqual('pleroma')
expect(store.state.TimelineSpace.pleroma).toEqual(true)
})
})
describe('API is not pleroma', () => {
let mockedResponse: Response<Instance>
beforeEach(() => {
const instance: Instance = {
uri: 'http://mstdn.io',
title: 'mstnd.io',
description: '',
email: 'test@example.com',
version: '2.7.0',
thumbnail: null,
urls: {
streaming_api: 'wss://mstdn.io'
},
stats: {
user_count: 10,
status_count: 1000,
domain_count: 100
},
languages: ['en'],
contact_account: null
}
mockedResponse = {
data: instance,
status: 200,
statusText: 'OK',
headers: {}
}
})
it('should be detected', async () => {
;(Mastodon.get as any).mockResolvedValue(mockedResponse)
await store.dispatch('TimelineSpace/detectPleroma')
expect(store.state.TimelineSpace.pleroma).toEqual(false)
}) })
}) })
}) })
describe('fetchEmojis', () => { describe('fetchEmojis', () => {
let emacsEmoji: Emoji
let rubyEmoji: Emoji
let mockedResponse: Response<Array<Emoji>>
beforeEach(() => {
emacsEmoji = {
shortcode: 'emacs',
url: 'http://example.com/emacs',
static_url: 'http://example.com/emacs',
visible_in_picker: true
}
rubyEmoji = {
shortcode: 'ruby',
url: 'http://example.com/ruby',
static_url: 'http://example.com/ruby',
visible_in_picker: true
}
mockedResponse = {
data: [emacsEmoji, rubyEmoji],
status: 200,
statusText: 'OK',
headers: {}
}
})
it('should be updated', async () => { it('should be updated', async () => {
;(Mastodon.get as any).mockResolvedValue(mockedResponse)
await store.dispatch('TimelineSpace/fetchEmojis', {}) await store.dispatch('TimelineSpace/fetchEmojis', {})
expect(store.state.TimelineSpace.emojis).toEqual([ expect(store.state.TimelineSpace.emojis).toEqual([emacsEmoji, rubyEmoji])
{
shortcode: 'emacs',
url: 'http://example.com/emacs',
static_url: 'http://example.com/emacs',
visible_in_picker: true
},
{
shortcode: 'ruby',
url: 'http://example.com/ruby',
static_url: 'http://example.com/ruby',
visible_in_picker: true
}
])
}) })
}) })
describe('fetchInstance', () => { describe('fetchInstance', () => {
let mockedResponse: Response<Instance>
beforeEach(() => {
mockedResponse = {
data: mockedInstance,
status: 200,
statusText: 'OK',
headers: {}
}
})
it('should be updated', async () => { it('should be updated', async () => {
;(Mastodon.get as any).mockResolvedValue(mockedResponse)
await store.dispatch('TimelineSpace/fetchInstance', {}) await store.dispatch('TimelineSpace/fetchInstance', {})
expect(store.state.TimelineSpace.tootMax).toEqual(5000) expect(store.state.TimelineSpace.tootMax).toEqual(mockedInstance.max_toot_chars)
}) })
}) })

View File

@ -1,12 +1,29 @@
import { Response, Status, Account, Application, Conversation } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import DirectMessages, { DirectMessagesState } from '@/store/TimelineSpace/Contents/DirectMessages' import DirectMessages, { DirectMessagesState } from '@/store/TimelineSpace/Contents/DirectMessages'
jest.mock('megalodon') const mockClient = {
getConversationTimeline: () => {
return new Promise<Response<Array<Entity.Conversation>>>(resolve => {
const res: Response<Array<Entity.Conversation>> = {
data: [conversation1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -28,7 +45,7 @@ const account: Account = {
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -55,12 +72,12 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -87,19 +104,19 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const conversation1: Conversation = { const conversation1: Entity.Conversation = {
id: '1', id: '1',
accounts: [account], accounts: [account],
last_status: status1, last_status: status1,
unread: false unread: false
} }
const conversation2: Conversation = { const conversation2: Entity.Conversation = {
id: '2', id: '2',
accounts: [account], accounts: [account],
last_status: status2, last_status: status2,
@ -131,7 +148,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
@ -156,26 +174,10 @@ describe('Home', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchTimeline', () => { describe('fetchTimeline', () => {
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Conversation>>>(resolve => {
const res: Response<Array<Conversation>> = {
data: [conversation1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const statuses = await store.dispatch('DirectMessages/fetchTimeline') const statuses = await store.dispatch('DirectMessages/fetchTimeline')
expect(statuses).toEqual([status1]) expect(statuses).toEqual([status1])
expect(store.state.DirectMessages.timeline).toEqual([status1]) expect(store.state.DirectMessages.timeline).toEqual([status1])
@ -198,20 +200,17 @@ describe('Home', () => {
} }
}) })
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { mockClient.getConversationTimeline = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Conversation>>>(resolve => {
return new Promise<Response<Array<Conversation>>>(resolve => { const res: Response<Array<Entity.Conversation>> = {
const res: Response<Array<Conversation>> = { data: [conversation2],
data: [conversation2], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
resolve(res) })
})
}
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('DirectMessages/lazyFetchTimeline', status1) await store.dispatch('DirectMessages/lazyFetchTimeline', status1)
expect(store.state.DirectMessages.lazyLoading).toEqual(false) expect(store.state.DirectMessages.lazyLoading).toEqual(false)
expect(store.state.DirectMessages.timeline).toEqual([status1, status2]) expect(store.state.DirectMessages.timeline).toEqual([status1, status2])

View File

@ -1,11 +1,28 @@
import { Response, Status, Account, Application } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Favourites, { FavouritesState } from '@/store/TimelineSpace/Contents/Favourites' import Favourites, { FavouritesState } from '@/store/TimelineSpace/Contents/Favourites'
import { LocalAccount } from '~/src/types/localAccount' import { LocalAccount } from '~/src/types/localAccount'
jest.mock('megalodon') const mockClient = {
getFavourites: () => {
return new Promise<Response<Array<Entity.Status>>>(resolve => {
const res: Response<Array<Entity.Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const localAccount: LocalAccount = { const localAccount: LocalAccount = {
_id: '1', _id: '1',
@ -21,7 +38,7 @@ const localAccount: LocalAccount = {
order: 1 order: 1
} }
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -42,7 +59,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -69,11 +86,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -100,7 +117,7 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
@ -129,7 +146,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
@ -154,72 +172,49 @@ describe('Favourites', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchFavourites', () => { describe('fetchFavourites', () => {
it('does not exist header', async () => { 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) await store.dispatch('Favourites/fetchFavourites', localAccount)
expect(store.state.Favourites.favourites).toEqual([status1]) expect(store.state.Favourites.favourites).toEqual([status1])
expect(store.state.Favourites.maxId).toEqual(null) expect(store.state.Favourites.maxId).toEqual(null)
}) })
it('link is null', async () => { it('link is null', async () => {
const mockClient = { mockClient.getFavourites = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status1],
data: [status1], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {
headers: { link: null
link: null
}
} }
resolve(res) }
}) resolve(res)
} })
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/fetchFavourites', localAccount) await store.dispatch('Favourites/fetchFavourites', localAccount)
expect(store.state.Favourites.favourites).toEqual([status1]) expect(store.state.Favourites.favourites).toEqual([status1])
expect(store.state.Favourites.maxId).toEqual(null) expect(store.state.Favourites.maxId).toEqual(null)
}) })
it('link exists in header', async () => { it('link exists in header', async () => {
const mockClient = { mockClient.getFavourites = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status1],
data: [status1], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {
headers: { link: '<http://localhost?max_id=2>; rel="next"'
link: '<http://localhost?max_id=2>; rel="next"'
}
} }
resolve(res) }
}) resolve(res)
} })
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/fetchFavourites', localAccount) await store.dispatch('Favourites/fetchFavourites', localAccount)
expect(store.state.Favourites.favourites).toEqual([status1]) expect(store.state.Favourites.favourites).toEqual([status1])
expect(store.state.Favourites.maxId).toEqual('2') expect(store.state.Favourites.maxId).toEqual('2')
@ -273,46 +268,40 @@ describe('Favourites', () => {
} }
}) })
it('link is null', async () => { it('link is null', async () => {
const mockClient = { mockClient.getFavourites = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status2],
data: [status2], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {
headers: { link: null
link: null
}
} }
resolve(res) }
}) resolve(res)
} })
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/lazyFetchFavourites') await store.dispatch('Favourites/lazyFetchFavourites')
expect(store.state.Favourites.favourites).toEqual([status1, status2]) expect(store.state.Favourites.favourites).toEqual([status1, status2])
expect(store.state.Favourites.maxId).toEqual(null) expect(store.state.Favourites.maxId).toEqual(null)
}) })
it('link exists in header', async () => { it('link exists in header', async () => {
const mockClient = { mockClient.getFavourites = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status2],
data: [status2], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {
headers: { link: '<http://localhost?max_id=3>; rel="next"'
link: '<http://localhost?max_id=3>; rel="next"'
}
} }
resolve(res) }
}) resolve(res)
} })
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Favourites/lazyFetchFavourites') await store.dispatch('Favourites/lazyFetchFavourites')
expect(store.state.Favourites.favourites).toEqual([status1, status2]) expect(store.state.Favourites.favourites).toEqual([status1, status2])
expect(store.state.Favourites.maxId).toEqual('3') expect(store.state.Favourites.maxId).toEqual('3')

View File

@ -1,13 +1,52 @@
import { Account, Response } from 'megalodon' import { Entity, Response } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import FollowRequests, { FollowRequestsState } from '@/store/TimelineSpace/Contents/FollowRequests' import FollowRequests, { FollowRequestsState } from '@/store/TimelineSpace/Contents/FollowRequests'
import { SideMenuState } from '@/store/TimelineSpace/SideMenu' import { SideMenuState } from '@/store/TimelineSpace/SideMenu'
jest.mock('megalodon') const mockClient = {
getFollowRequests: () => {
return new Promise<Response<Array<Entity.Account>>>(resolve => {
const res: Response<Array<Entity.Account>> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
acceptFollowRequest: () => {
return new Promise<Response<{}>>(resolve => {
const res: Response<{}> = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
rejectFollowRequest: () => {
return new Promise<Response<{}>>(resolve => {
const res: Response<{}> = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -77,7 +116,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
@ -102,26 +142,10 @@ describe('Home', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchRequests', () => { describe('fetchRequests', () => {
it('should be updated', async () => { 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') await store.dispatch('FollowRequests/fetchRequests')
expect(store.state.FollowRequests.requests).toEqual([account]) expect(store.state.FollowRequests.requests).toEqual([account])
}) })
@ -136,32 +160,18 @@ describe('Home', () => {
} }
}) })
it('should be succeed', async () => { it('should be succeed', async () => {
const mockClient = { mockClient.getFollowRequests = () => {
post: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Account>>>(resolve => {
return new Promise<Response<{}>>(resolve => { const res: Response<Array<Entity.Account>> = {
const res: Response<{}> = { data: [],
data: {}, status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
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) await store.dispatch('FollowRequests/acceptRequest', account)
expect(store.state.FollowRequests.requests).toEqual([]) expect(store.state.FollowRequests.requests).toEqual([])
}) })
@ -176,32 +186,18 @@ describe('Home', () => {
} }
}) })
it('should be succeed', async () => { it('should be succeed', async () => {
const mockClient = { mockClient.getFollowRequests = () => {
post: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Account>>>(resolve => {
return new Promise<Response<{}>>(resolve => { const res: Response<Array<Entity.Account>> = {
const res: Response<{}> = { data: [],
data: {}, status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
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) await store.dispatch('FollowRequests/rejectRequest', account)
expect(store.state.FollowRequests.requests).toEqual([]) expect(store.state.FollowRequests.requests).toEqual([])
}) })

View File

@ -1,13 +1,30 @@
import { Response, Status, Account, Application } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Tag, { TagState } from '@/store/TimelineSpace/Contents/Hashtag/Tag' import Tag, { TagState } from '@/store/TimelineSpace/Contents/Hashtag/Tag'
import { LoadPositionWithTag } from '@/types/loadPosition' import { LoadPositionWithTag } from '@/types/loadPosition'
jest.mock('megalodon') const mockClient = {
getTagTimeline: () => {
return new Promise<Response<Array<Entity.Status>>>(resolve => {
const res: Response<Array<Entity.Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -28,7 +45,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -55,11 +72,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -86,7 +103,7 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
@ -141,26 +158,10 @@ describe('Home', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetch', () => { describe('fetch', () => {
it('should be updated', async () => { 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') const statuses = await store.dispatch('Tag/fetch', 'tag')
expect(statuses).toEqual([status1]) expect(statuses).toEqual([status1])
expect(store.state.Tag.timeline).toEqual([status1]) expect(store.state.Tag.timeline).toEqual([status1])
@ -181,20 +182,17 @@ describe('Home', () => {
} }
}) })
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { mockClient.getTagTimeline = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status2],
data: [status2], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
resolve(res) })
})
}
} }
mockedMegalodon.mockImplementation(() => mockClient)
const loadPositionWithTag: LoadPositionWithTag = { const loadPositionWithTag: LoadPositionWithTag = {
status: status1, status: status1,
tag: 'tag' tag: 'tag'

View File

@ -1,12 +1,29 @@
import { Response, Status, Account, Application } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Home, { HomeState } from '@/store/TimelineSpace/Contents/Home' import Home, { HomeState } from '@/store/TimelineSpace/Contents/Home'
jest.mock('megalodon') const mockClient = {
getHomeTimeline: () => {
return new Promise<Response<Array<Entity.Status>>>(resolve => {
const res: Response<Array<Entity.Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -27,7 +44,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -54,11 +71,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -85,7 +102,7 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
@ -142,26 +159,10 @@ describe('Home', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchTimeline', () => { describe('fetchTimeline', () => {
it('should be updated', async () => { 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('Home/fetchTimeline') const statuses = await store.dispatch('Home/fetchTimeline')
expect(statuses).toEqual([status1]) expect(statuses).toEqual([status1])
expect(store.state.Home.timeline).toEqual([status1]) expect(store.state.Home.timeline).toEqual([status1])
@ -184,20 +185,18 @@ describe('Home', () => {
} }
}) })
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { mockClient.getHomeTimeline = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status2],
data: [status2], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
resolve(res) })
})
}
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Home/lazyFetchTimeline', status1) 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

@ -1,13 +1,41 @@
import { Response, Account } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Edit, { EditState } from '@/store/TimelineSpace/Contents/Lists/Edit' import Edit, { EditState } from '@/store/TimelineSpace/Contents/Lists/Edit'
import { RemoveAccountFromList } from '@/types/removeAccountFromList' import { RemoveAccountFromList } from '@/types/removeAccountFromList'
jest.mock('megalodon') const mockClient = {
getAccountsInList: () => {
return new Promise<Response<Entity.Account[]>>(resolve => {
const res: Response<Entity.Account[]> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
deleteAccountsFromList: () => {
return new Promise<Response<{}>>(resolve => {
const res: Response<{}> = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -50,7 +78,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
@ -75,26 +104,10 @@ describe('Lists/Edit', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchMembers', () => { describe('fetchMembers', () => {
it('should be updated', async () => { it('should get', 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') await store.dispatch('Edit/fetchMembers', 'id')
expect(store.state.Edit.members).toEqual([account]) expect(store.state.Edit.members).toEqual([account])
}) })
@ -102,21 +115,6 @@ describe('Lists/Edit', () => {
describe('removeAccount', () => { describe('removeAccount', () => {
it('should be removed', async () => { 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 = { const removeFromList: RemoveAccountFromList = {
account: account, account: account,
listId: 'id' listId: 'id'

View File

@ -1,12 +1,40 @@
import { Response, List } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Index, { IndexState } from '@/store/TimelineSpace/Contents/Lists/Index' import Index, { IndexState } from '@/store/TimelineSpace/Contents/Lists/Index'
jest.mock('megalodon') const mockClient = {
getLists: () => {
return new Promise<Response<Array<Entity.List>>>(resolve => {
const res: Response<Array<Entity.List>> = {
data: [list],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
createList: () => {
return new Promise<Response<Entity.List>>(resolve => {
const res: Response<Entity.List> = {
data: list,
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const list: List = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const list: Entity.List = {
id: '1', id: '1',
title: 'list1' title: 'list1'
} }
@ -32,7 +60,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
@ -57,26 +86,10 @@ describe('Lists/Index', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchLists', () => { describe('fetchLists', () => {
it('should be updated', async () => { 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') await store.dispatch('Index/fetchLists')
expect(store.state.Index.lists).toEqual([list]) expect(store.state.Index.lists).toEqual([list])
}) })
@ -84,22 +97,7 @@ describe('Lists/Index', () => {
describe('createList', () => { describe('createList', () => {
it('should be created', async () => { it('should be created', async () => {
const mockClient = { const res: Entity.List = await store.dispatch('Index/createList', 'list1')
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') expect(res.title).toEqual('list1')
}) })
}) })

View File

@ -1,13 +1,30 @@
import { Response, Status, Account, Application } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Show, { ShowState } from '@/store/TimelineSpace/Contents/Lists/Show' import Show, { ShowState } from '@/store/TimelineSpace/Contents/Lists/Show'
import { LoadPositionWithList } from '@/types/loadPosition' import { LoadPositionWithList } from '@/types/loadPosition'
jest.mock('megalodon') const mockClient = {
getListTimeline: () => {
return new Promise<Response<Array<Entity.Status>>>(resolve => {
const res: Response<Array<Entity.Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -29,7 +46,7 @@ const account: Account = {
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -56,12 +73,12 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -88,7 +105,7 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
@ -143,26 +160,10 @@ describe('Lists/Show', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchTimeline', () => { describe('fetchTimeline', () => {
it('should be updated', async () => { 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') await store.dispatch('Show/fetchTimeline', '1')
expect(store.state.Show.timeline).toEqual([status1]) expect(store.state.Show.timeline).toEqual([status1])
}) })
@ -181,21 +182,18 @@ describe('Lists/Show', () => {
} }
}) })
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { mockClient.getListTimeline = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status2],
data: [status2], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
resolve(res) })
})
}
} }
mockedMegalodon.mockImplementation(() => mockClient)
const loadPosition: LoadPositionWithList = { const loadPosition: LoadPositionWithList = {
status: status1, status: status1,
list_id: '1' list_id: '1'

View File

@ -1,12 +1,29 @@
import { Response, Status, Account, Application } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Local, { LocalState } from '@/store/TimelineSpace/Contents/Local' import Local, { LocalState } from '@/store/TimelineSpace/Contents/Local'
jest.mock('megalodon') const mockClient = {
getLocalTimeline: () => {
return new Promise<Response<Array<Entity.Status>>>(resolve => {
const res: Response<Array<Entity.Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -27,7 +44,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -54,11 +71,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -85,7 +102,7 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
@ -140,26 +157,10 @@ describe('Home', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchLocalTimeline', () => { describe('fetchLocalTimeline', () => {
it('should be updated', async () => { 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') const statuses = await store.dispatch('Local/fetchLocalTimeline')
expect(statuses).toEqual([status1]) expect(statuses).toEqual([status1])
expect(store.state.Local.timeline).toEqual([status1]) expect(store.state.Local.timeline).toEqual([status1])
@ -182,20 +183,18 @@ describe('Home', () => {
} }
}) })
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { mockClient.getLocalTimeline = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status2],
data: [status2], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
resolve(res) })
})
}
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Local/lazyFetchTimeline', status1) await store.dispatch('Local/lazyFetchTimeline', status1)
expect(store.state.Local.lazyLoading).toEqual(false) expect(store.state.Local.lazyLoading).toEqual(false)
expect(store.state.Local.timeline).toEqual([status1, status2]) expect(store.state.Local.timeline).toEqual([status1, status2])

View File

@ -1,12 +1,29 @@
import { Response, Account, Notification, Status, Application } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Mentions from '~/src/renderer/store/TimelineSpace/Contents/Mentions' import Mentions from '~/src/renderer/store/TimelineSpace/Contents/Mentions'
jest.mock('megalodon') const mockClient = {
getNotifications: () => {
return new Promise<Response<Entity.Notification[]>>(resolve => {
const res: Response<Entity.Notification[]> = {
data: [mention, reblog, favourite, follow],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -28,7 +45,7 @@ const account: Account = {
bot: false bot: false
} }
const status: Status = { const status: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -55,12 +72,12 @@ const status: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const mention: Notification = { const mention: Entity.Notification = {
account: account, account: account,
created_at: '2019-03-26T21:40:32', created_at: '2019-03-26T21:40:32',
id: '1', id: '1',
@ -68,7 +85,7 @@ const mention: Notification = {
type: 'mention' type: 'mention'
} }
const reblog: Notification = { const reblog: Entity.Notification = {
account: account, account: account,
created_at: '2019-03-26T21:40:32', created_at: '2019-03-26T21:40:32',
id: '2', id: '2',
@ -76,7 +93,7 @@ const reblog: Notification = {
type: 'reblog' type: 'reblog'
} }
const favourite: Notification = { const favourite: Entity.Notification = {
account: account, account: account,
created_at: '2019-03-26T21:40:32', created_at: '2019-03-26T21:40:32',
id: '3', id: '3',
@ -84,11 +101,10 @@ const favourite: Notification = {
type: 'favourite' type: 'favourite'
} }
const follow: Notification = { const follow: Entity.Notification = {
account: account, account: account,
created_at: '2019-03-26T21:40:32', created_at: '2019-03-26T21:40:32',
id: '4', id: '4',
status: null,
type: 'follow' type: 'follow'
} }
@ -142,26 +158,10 @@ describe('Mentions', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchMentions', () => { describe('fetchMentions', () => {
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Notification[]>>(resolve => {
const res: Response<Notification[]> = {
data: [mention, reblog, favourite, follow],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Mentions/fetchMentions') await store.dispatch('Mentions/fetchMentions')
expect(store.state.Mentions.mentions).toEqual([mention, reblog, favourite, follow]) expect(store.state.Mentions.mentions).toEqual([mention, reblog, favourite, follow])
}) })
@ -199,21 +199,18 @@ describe('Mentions', () => {
} }
}) })
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { mockClient.getNotifications = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Entity.Notification[]>>(resolve => {
return new Promise<Response<Notification[]>>(resolve => { const res: Response<Entity.Notification[]> = {
const res: Response<Notification[]> = { data: [favourite, follow],
data: [favourite, follow], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
resolve(res) })
})
}
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Mentions/lazyFetchMentions', { id: 1 }) await store.dispatch('Mentions/lazyFetchMentions', { id: 1 })
expect(store.state.Mentions.mentions).toEqual([mention, reblog, favourite, follow]) expect(store.state.Mentions.mentions).toEqual([mention, reblog, favourite, follow])
expect(store.state.Mentions.lazyLoading).toEqual(false) expect(store.state.Mentions.lazyLoading).toEqual(false)

View File

@ -1,12 +1,29 @@
import { Response, Status, Account, Application, Notification } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon.ts'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Notifications, { NotificationsState } from '@/store/TimelineSpace/Contents/Notifications' import Notifications, { NotificationsState } from '@/store/TimelineSpace/Contents/Notifications'
jest.mock('megalodon') const mockClient = {
getNotifications: () => {
return new Promise<Response<Array<Entity.Notification>>>(resolve => {
const res: Response<Array<Entity.Notification>> = {
data: [notification1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account1: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account1: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -28,7 +45,7 @@ const account1: Account = {
bot: false bot: false
} }
const account2: Account = { const account2: Entity.Account = {
id: '2', id: '2',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@mstdn.io', acct: 'h3poteto@mstdn.io',
@ -50,7 +67,7 @@ const account2: Account = {
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -77,12 +94,12 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -109,12 +126,12 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -141,12 +158,12 @@ const rebloggedStatus: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const notification1: Notification = { const notification1: Entity.Notification = {
id: '1', id: '1',
account: account2, account: account2,
status: status1, status: status1,
@ -154,7 +171,7 @@ const notification1: Notification = {
created_at: '2019-04-01T17:01:32' created_at: '2019-04-01T17:01:32'
} }
const notification2: Notification = { const notification2: Entity.Notification = {
id: '2', id: '2',
account: account2, account: account2,
status: rebloggedStatus, status: rebloggedStatus,
@ -212,26 +229,10 @@ describe('Notifications', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchNotifications', () => { describe('fetchNotifications', () => {
it('should be updated', async () => { 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') const response = await store.dispatch('Notifications/fetchNotifications')
expect(response).toEqual([notification1]) expect(response).toEqual([notification1])
expect(store.state.Notifications.notifications).toEqual([notification1]) expect(store.state.Notifications.notifications).toEqual([notification1])
@ -251,20 +252,17 @@ describe('Notifications', () => {
} }
}) })
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { mockClient.getNotifications = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Notification>>>(resolve => {
return new Promise<Response<Array<Notification>>>(resolve => { const res: Response<Array<Entity.Notification>> = {
const res: Response<Array<Notification>> = { data: [notification2],
data: [notification2], status: 200,
status: 200, statusText: 'OK',
statusText: '200', headers: {}
headers: {} }
} resolve(res)
resolve(res) })
})
}
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Notifications/lazyFetchNotifications', notification1) await store.dispatch('Notifications/lazyFetchNotifications', notification1)
expect(store.state.Notifications.lazyLoading).toEqual(false) expect(store.state.Notifications.lazyLoading).toEqual(false)
expect(store.state.Notifications.notifications).toEqual([notification1, notification2]) expect(store.state.Notifications.notifications).toEqual([notification1, notification2])

View File

@ -1,12 +1,29 @@
import { Response, Status, Account, Application } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Public, { PublicState } from '@/store/TimelineSpace/Contents/Public' import Public, { PublicState } from '@/store/TimelineSpace/Contents/Public'
jest.mock('megalodon') const mockClient = {
getPublicTimeline: () => {
return new Promise<Response<Array<Entity.Status>>>(resolve => {
const res: Response<Array<Entity.Status>> = {
data: [status1],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -27,7 +44,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -54,11 +71,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -85,7 +102,7 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
@ -140,26 +157,10 @@ describe('Home', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchPublicTimeline', () => { describe('fetchPublicTimeline', () => {
it('should be updated', async () => { 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') const statuses = await store.dispatch('Public/fetchPublicTimeline')
expect(statuses).toEqual([status1]) expect(statuses).toEqual([status1])
expect(store.state.Public.timeline).toEqual([status1]) expect(store.state.Public.timeline).toEqual([status1])
@ -182,20 +183,17 @@ describe('Home', () => {
} }
}) })
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { mockClient.getPublicTimeline = () => {
get: (_path: string, _params: object) => { return new Promise<Response<Array<Entity.Status>>>(resolve => {
return new Promise<Response<Array<Status>>>(resolve => { const res: Response<Array<Entity.Status>> = {
const res: Response<Array<Status>> = { data: [status2],
data: [status2], status: 200,
status: 200, statusText: 'OK',
statusText: 'OK', headers: {}
headers: {} }
} resolve(res)
resolve(res) })
})
}
} }
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('Public/lazyFetchTimeline', status1) await store.dispatch('Public/lazyFetchTimeline', status1)
expect(store.state.Public.lazyLoading).toEqual(false) expect(store.state.Public.lazyLoading).toEqual(false)
expect(store.state.Public.timeline).toEqual([status1, status2]) expect(store.state.Public.timeline).toEqual([status1, status2])

View File

@ -1,12 +1,9 @@
import { Response, Account } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import AccountStore, { AccountState } from '@/store/TimelineSpace/Contents/Search/Account' import AccountStore, { AccountState } from '@/store/TimelineSpace/Contents/Search/Account'
jest.mock('megalodon') const account: Entity.Account = {
const account: Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -28,6 +25,26 @@ const account: Account = {
bot: false bot: false
} }
const mockClient = {
searchAccount: () => {
return new Promise<Response<Array<Entity.Account>>>(resolve => {
const res: Response<Array<Entity.Account>> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
let state = (): AccountState => { let state = (): AccountState => {
return { return {
results: [] results: []
@ -61,7 +78,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
@ -86,26 +104,10 @@ describe('Search/Account', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('search', () => { describe('search', () => {
it('should be updated', async () => { 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') await store.dispatch('Account/search', 'query')
expect(store.state.Account.results).toEqual([account]) expect(store.state.Account.results).toEqual([account])
}) })

View File

@ -1,17 +1,38 @@
import { Response, Results, Tag } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import TagStore, { TagState } from '@/store/TimelineSpace/Contents/Search/Tag' import TagStore, { TagState } from '@/store/TimelineSpace/Contents/Search/Tag'
jest.mock('megalodon') const tag1: Entity.Tag = {
const tag1: Tag = {
name: 'tag1', name: 'tag1',
url: 'http://example.com/tag1', url: 'http://example.com/tag1',
history: null history: null
} }
const mockClient = {
search: () => {
return new Promise<Response<Entity.Results>>(resolve => {
const res: Response<Entity.Results> = {
data: {
accounts: [],
statuses: [],
hashtags: [tag1]
},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
let state = (): TagState => { let state = (): TagState => {
return { return {
results: [] results: []
@ -45,7 +66,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
const appState = { const appState = {
@ -55,7 +77,7 @@ const appState = {
} }
} }
describe('Search/Account', () => { describe('Search/Tag', () => {
let store let store
let localVue let localVue
@ -69,30 +91,10 @@ describe('Search/Account', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('search', () => { describe('search', () => {
it('should be updated', async () => { 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') await store.dispatch('Tag/search', 'query')
expect(store.state.Tag.results).toEqual([tag1]) expect(store.state.Tag.results).toEqual([tag1])
}) })

View File

@ -1,12 +1,33 @@
import { Response, Results, Status, Account, Application } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import Toots, { TootsState } from '@/store/TimelineSpace/Contents/Search/Toots' import Toots, { TootsState } from '@/store/TimelineSpace/Contents/Search/Toots'
jest.mock('megalodon') const mockClient = {
search: () => {
return new Promise<Response<Entity.Results>>(resolve => {
const res: Response<Entity.Results> = {
data: {
accounts: [],
statuses: [status],
hashtags: []
},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -28,7 +49,7 @@ const account: Account = {
bot: false bot: false
} }
const status: Status = { const status: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -55,7 +76,7 @@ const status: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
@ -93,7 +114,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
@ -118,30 +140,10 @@ describe('Search/Account', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('search', () => { describe('search', () => {
it('should be updated', async () => { 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') await store.dispatch('Toots/search', 'query')
expect(store.state.Toots.results).toEqual([status]) expect(store.state.Toots.results).toEqual([status])
}) })

View File

@ -1,9 +1,9 @@
import { Account } from 'megalodon' import { Entity } from 'megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import AccountProfile, { AccountProfileState } from '~/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile' import AccountProfile, { AccountProfileState } from '~/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile'
const state = (account: Account | null): AccountProfileState => { const state = (account: Entity.Account | null): AccountProfileState => {
return { return {
loading: false, loading: false,
relationship: null, relationship: null,
@ -29,7 +29,7 @@ const timelineSpace = {
} }
} }
const initStore = (account: Account | null) => { const initStore = (account: Entity.Account | null) => {
return { return {
namespaced: true, namespaced: true,
state: state(account), state: state(account),
@ -56,7 +56,7 @@ describe('AccountProfile', () => {
describe('isOwnProfile', () => { describe('isOwnProfile', () => {
describe('target is a same Mastodon account', () => { describe('target is a same Mastodon account', () => {
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@example.com', acct: 'h3poteto@example.com',
@ -91,7 +91,7 @@ describe('AccountProfile', () => {
}) })
describe('target is another Mastodon account', () => { describe('target is another Mastodon account', () => {
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@another.example.com', acct: 'h3poteto@another.example.com',
@ -126,7 +126,7 @@ describe('AccountProfile', () => {
}) })
describe('target is a same Pleroma account', () => { describe('target is a same Pleroma account', () => {
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@example.com', acct: 'h3poteto@example.com',
@ -161,7 +161,7 @@ describe('AccountProfile', () => {
}) })
describe('target is another Pleroma account', () => { describe('target is another Pleroma account', () => {
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@another.example.com', acct: 'h3poteto@another.example.com',

View File

@ -1,16 +1,33 @@
import { Response, List } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import HeaderMenu, { HeaderMenuState } from '~/src/renderer/store/TimelineSpace/HeaderMenu' import HeaderMenu, { HeaderMenuState } from '~/src/renderer/store/TimelineSpace/HeaderMenu'
jest.mock('megalodon') const list: Entity.List = {
const list: List = {
id: '1', id: '1',
title: 'example' title: 'example'
} }
const mockClient = {
getList: (_listID: string) => {
return new Promise<Response<Entity.List>>(resolve => {
const res: Response<Entity.List> = {
data: list,
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const state = (): HeaderMenuState => { const state = (): HeaderMenuState => {
return { return {
title: 'Home', title: 'Home',
@ -34,7 +51,8 @@ const timelineState = {
account: { account: {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'
} },
sns: 'mastodon'
} }
} }
@ -59,26 +77,10 @@ describe('HeaderMenu', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('fetchLists', () => { describe('fetchLists', () => {
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = {
get: (_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 l = await store.dispatch('HeaderMenu/fetchList', list.id) const l = await store.dispatch('HeaderMenu/fetchList', list.id)
expect(l).toEqual(list) expect(l).toEqual(list)
expect(store.state.HeaderMenu.title).toEqual(`#${list.title}`) expect(store.state.HeaderMenu.title).toEqual(`#${list.title}`)

View File

@ -1,12 +1,40 @@
import { Response, Account } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import AddListMember, { AddListMemberState } from '@/store/TimelineSpace/Modals/AddListMember' import AddListMember, { AddListMemberState } from '@/store/TimelineSpace/Modals/AddListMember'
jest.mock('megalodon') const mockClient = {
searchAccount: () => {
return new Promise<Response<Entity.Account[]>>(resolve => {
const res: Response<Entity.Account[]> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
addAccountsToList: () => {
return new Promise<Response>(resolve => {
const res: Response = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -50,7 +78,8 @@ const timelineState = {
state: { state: {
account: { account: {
_id: '0' _id: '0'
} },
sns: 'mastodon'
} }
} }
@ -75,7 +104,6 @@ describe('AddListMember', () => {
App: appState App: appState
} }
}) })
mockedMegalodon.mockClear()
}) })
describe('changeModal', () => { describe('changeModal', () => {
@ -87,21 +115,6 @@ describe('AddListMember', () => {
describe('search', () => { describe('search', () => {
it('should be searched', async () => { it('should be searched', async () => {
const mockClient = {
get: () => {
return new Promise<Response<Account[]>>(resolve => {
const res: Response<Account[]> = {
data: [account],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('AddListMember/search', 'akira') await store.dispatch('AddListMember/search', 'akira')
expect(store.state.AddListMember.accounts).toEqual([account]) expect(store.state.AddListMember.accounts).toEqual([account])
}) })
@ -109,21 +122,6 @@ describe('AddListMember', () => {
describe('add', () => { describe('add', () => {
it('should be added a member to the list', async () => { it('should be added a member to the list', async () => {
const mockClient = {
post: () => {
return new Promise<Response>(resolve => {
const res: Response = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const result = await store.dispatch('AddListMember/add', 'akira') const result = await store.dispatch('AddListMember/add', 'akira')
expect(result).toEqual({}) expect(result).toEqual({})
}) })

View File

@ -1,12 +1,62 @@
import { Response, List, Account } from 'megalodon' import { Response, Entity } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import ListMembership, { ListMembershipState } from '@/store/TimelineSpace/Modals/ListMembership' import ListMembership, { ListMembershipState } from '@/store/TimelineSpace/Modals/ListMembership'
jest.mock('megalodon') const mockClient = {
getAccountLists: () => {
return new Promise<Response<Entity.List[]>>(resolve => {
const res: Response<Entity.List[]> = {
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
getLists: () => {
return new Promise<Response<Entity.List[]>>(resolve => {
const res: Response<Entity.List[]> = {
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
deleteAccountsFromList: () => {
return new Promise<Response>(resolve => {
const res: Response = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
addAccountsToList: () => {
return new Promise<Response>(resolve => {
const res: Response = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const account: Account = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -28,12 +78,12 @@ const account: Account = {
bot: false bot: false
} }
const list1: List = { const list1: Entity.List = {
id: '1', id: '1',
title: 'list1' title: 'list1'
} }
const list2: List = { const list2: Entity.List = {
id: '2', id: '2',
title: 'list2' title: 'list2'
} }
@ -89,21 +139,7 @@ describe('ListMembership', () => {
}) })
describe('fetchListMembership', () => { describe('fetchListMembership', () => {
it('should be changed', async () => { it('should get', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<List[]>>(resolve => {
const res: Response<List[]> = {
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('ListMembership/fetchListMembership', { await store.dispatch('ListMembership/fetchListMembership', {
id: '5' id: '5'
}) })
@ -113,20 +149,6 @@ describe('ListMembership', () => {
describe('fetchLists', () => { describe('fetchLists', () => {
it('should be changed', async () => { it('should be changed', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<List[]>>(resolve => {
const res: Response<List[]> = {
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('ListMembership/fetchLists') await store.dispatch('ListMembership/fetchLists')
expect(store.state.ListMembership.lists).toEqual([list1, list2]) expect(store.state.ListMembership.lists).toEqual([list1, list2])
}) })
@ -144,31 +166,6 @@ describe('ListMembership', () => {
} }
}) })
it('should be changed', async () => { it('should be changed', async () => {
const mockClient = {
del: (_path: string, _params: object) => {
return new Promise<Response>(resolve => {
const res: Response = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
},
post: (_path: string, _params: object) => {
return new Promise<Response>(resolve => {
const res: Response = {
data: {},
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
await store.dispatch('ListMembership/changeBelongToLists', [list1]) await store.dispatch('ListMembership/changeBelongToLists', [list1])
expect(store.state.ListMembership.belongToLists).toEqual([list1]) expect(store.state.ListMembership.belongToLists).toEqual([list1])
}) })

View File

@ -1,5 +1,4 @@
import { Response, List } from 'megalodon' import { Entity, Response } from 'megalodon'
import mockedMegalodon from '~/spec/mock/megalodon'
import { createLocalVue } from '@vue/test-utils' import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex' import Vuex from 'vuex'
import { ipcMain, ipcRenderer } from '~/spec/mock/electron' import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
@ -8,14 +7,34 @@ import { LocalTag } from '~/src/types/localTag'
import { MyWindow } from '~/src/types/global' import { MyWindow } from '~/src/types/global'
;(window as MyWindow).ipcRenderer = ipcRenderer ;(window as MyWindow).ipcRenderer = ipcRenderer
jest.mock('megalodon') const mockClient = {
getLists: () => {
return new Promise<Response<Entity.List[]>>(resolve => {
const res: Response<Entity.List[]> = {
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
const list1: List = { jest.mock('megalodon', () => ({
...jest.requireActual('megalodon'),
default: jest.fn(() => mockClient),
__esModule: true
}))
// import mockedMegalodon from '~/spec/mock/megalodon'
const list1: Entity.List = {
id: '1', id: '1',
title: 'example1' title: 'example1'
} }
const list2: List = { const list2: Entity.List = {
id: '2', id: '2',
title: 'example2' title: 'example2'
} }
@ -44,13 +63,20 @@ const initStore = () => {
} }
} }
const appState = { const appStore = {
namespaced: true, namespaced: true,
state: { state: {
proxyConfiguration: false proxyConfiguration: false
} }
} }
const timelineStore = {
namespaced: true,
state: {
sns: 'mastodon'
}
}
describe('SideMenu', () => { describe('SideMenu', () => {
let store let store
let localVue let localVue
@ -61,29 +87,16 @@ describe('SideMenu', () => {
store = new Vuex.Store({ store = new Vuex.Store({
modules: { modules: {
SideMenu: initStore(), SideMenu: initStore(),
App: appState App: appStore,
TimelineSpace: timelineStore
} }
}) })
mockedMegalodon.mockClear() // mockedMegalodon.mockClear()
}) })
describe('fetchLists', () => { describe('fetchLists', () => {
it('should be updated', async () => { it('should be updated', async () => {
const mockClient = { // mockedMegalodon.mockImplementation(() => mockClient)
get: (_path: string, _params: object) => {
return new Promise<Response<List[]>>(resolve => {
const res: Response<List[]> = {
data: [list1, list2],
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
mockedMegalodon.mockImplementation(() => mockClient)
const account = { const account = {
accessToken: 'token', accessToken: 'token',
baseURL: 'http://localhost' baseURL: 'http://localhost'

View File

@ -16,7 +16,7 @@ describe('TimelineSpace', () => {
local: unreadSettings.Local.default, local: unreadSettings.Local.default,
public: unreadSettings.Public.default public: unreadSettings.Public.default
}, },
pleroma: false sns: 'mastodon'
} }
}) })

View File

@ -1,7 +1,7 @@
import { Account, Status, Application } from 'megalodon' import { Entity } from 'megalodon'
import DirectMessages, { DirectMessagesState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/DirectMessages' import DirectMessages, { DirectMessagesState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/DirectMessages'
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -22,7 +22,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -49,11 +49,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -80,12 +80,12 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -112,7 +112,7 @@ const rebloggedStatus: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }

View File

@ -1,7 +1,7 @@
import { Account, Status, Application } from 'megalodon' import { Entity } from 'megalodon'
import Tag, { TagState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Hashtag/Tag' import Tag, { TagState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Hashtag/Tag'
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -22,7 +22,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -49,11 +49,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -80,12 +80,12 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -112,7 +112,7 @@ const rebloggedStatus: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }

View File

@ -1,7 +1,7 @@
import { Account, Status, Application } from 'megalodon' import { Entity } from 'megalodon'
import Home, { HomeState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Home' import Home, { HomeState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Home'
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -22,7 +22,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -49,11 +49,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -80,7 +80,7 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
@ -245,7 +245,7 @@ describe('TimelineSpace/Contents/Home', () => {
showReplies: true showReplies: true
} }
}) })
const favouritedStatus: Status = Object.assign(status1, { const favouritedStatus: Entity.Status = Object.assign(status1, {
favourited: true favourited: true
}) })
it('should be updated', () => { it('should be updated', () => {
@ -254,7 +254,7 @@ describe('TimelineSpace/Contents/Home', () => {
}) })
}) })
describe('message is reblogged', () => { describe('message is reblogged', () => {
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -281,11 +281,11 @@ describe('TimelineSpace/Contents/Home', () => {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const favouritedStatus: Status = Object.assign(status1, { const favouritedStatus: Entity.Status = Object.assign(status1, {
favourited: true favourited: true
}) })
beforeEach(() => { beforeEach(() => {
@ -328,7 +328,7 @@ describe('TimelineSpace/Contents/Home', () => {
describe('message is reblogged', () => { describe('message is reblogged', () => {
beforeEach(() => { beforeEach(() => {
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -355,7 +355,7 @@ describe('TimelineSpace/Contents/Home', () => {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }

View File

@ -1,7 +1,7 @@
import { Account, Status, Application } from 'megalodon' import { Entity } from 'megalodon'
import Show, { ShowState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Show' import Show, { ShowState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Lists/Show'
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -22,7 +22,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -49,11 +49,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -80,12 +80,12 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -112,7 +112,7 @@ const rebloggedStatus: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }

View File

@ -1,7 +1,7 @@
import { Account, Status, Application } from 'megalodon' import { Entity } from 'megalodon'
import Local, { LocalState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Local' import Local, { LocalState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Local'
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -22,7 +22,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -49,11 +49,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -80,12 +80,12 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -112,7 +112,7 @@ const rebloggedStatus: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }

View File

@ -1,7 +1,7 @@
import { Account, Notification, Status, Application } from 'megalodon' import { Entity } from 'megalodon'
import Mentions, { MentionsState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Mentions' import Mentions, { MentionsState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Mentions'
const account1: Account = { const account1: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -23,7 +23,7 @@ const account1: Account = {
bot: false bot: false
} }
const account2: Account = { const account2: Entity.Account = {
id: '2', id: '2',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@mstdn.io', acct: 'h3poteto@mstdn.io',
@ -45,7 +45,7 @@ const account2: Account = {
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -72,12 +72,12 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -104,12 +104,12 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -136,12 +136,12 @@ const rebloggedStatus: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const notification1: Notification = { const notification1: Entity.Notification = {
id: '1', id: '1',
account: account2, account: account2,
status: status1, status: status1,
@ -149,7 +149,7 @@ const notification1: Notification = {
created_at: '2019-04-01T17:01:32' created_at: '2019-04-01T17:01:32'
} }
const notification2: Notification = { const notification2: Entity.Notification = {
id: '2', id: '2',
account: account2, account: account2,
status: rebloggedStatus, status: rebloggedStatus,
@ -288,7 +288,7 @@ describe('TimelineSpace/Contents/Mentions', () => {
} }
}) })
it('should be updated', () => { it('should be updated', () => {
const favourited: Status = Object.assign(status1, { const favourited: Entity.Status = Object.assign(status1, {
favourited: true favourited: true
}) })
Mentions.mutations![MUTATION_TYPES.UPDATE_TOOT](state, favourited) Mentions.mutations![MUTATION_TYPES.UPDATE_TOOT](state, favourited)

View File

@ -1,7 +1,7 @@
import { Account, Notification, Status, Application } from 'megalodon' import { Entity } from 'megalodon'
import Notifications, { NotificationsState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Notifications' import Notifications, { NotificationsState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Notifications'
const account1: Account = { const account1: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -23,7 +23,7 @@ const account1: Account = {
bot: false bot: false
} }
const account2: Account = { const account2: Entity.Account = {
id: '2', id: '2',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@mstdn.io', acct: 'h3poteto@mstdn.io',
@ -45,7 +45,7 @@ const account2: Account = {
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -72,12 +72,12 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -104,12 +104,12 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -136,12 +136,12 @@ const rebloggedStatus: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const notification1: Notification = { const notification1: Entity.Notification = {
id: '1', id: '1',
account: account2, account: account2,
status: status1, status: status1,
@ -149,7 +149,7 @@ const notification1: Notification = {
created_at: '2019-04-01T17:01:32' created_at: '2019-04-01T17:01:32'
} }
const notification2: Notification = { const notification2: Entity.Notification = {
id: '2', id: '2',
account: account2, account: account2,
status: rebloggedStatus, status: rebloggedStatus,

View File

@ -1,7 +1,7 @@
import { Account, Status, Application } from 'megalodon' import { Entity } from 'megalodon'
import Public, { PublicState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Public' import Public, { PublicState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Public'
const account: Account = { const account: Entity.Account = {
id: '1', id: '1',
username: 'h3poteto', username: 'h3poteto',
acct: 'h3poteto@pleroma.io', acct: 'h3poteto@pleroma.io',
@ -22,7 +22,7 @@ const account: Account = {
fields: null, fields: null,
bot: false bot: false
} }
const status1: Status = { const status1: Entity.Status = {
id: '1', id: '1',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -49,11 +49,11 @@ const status1: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const status2: Status = { const status2: Entity.Status = {
id: '2', id: '2',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -80,12 +80,12 @@ const status2: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }
const rebloggedStatus: Status = { const rebloggedStatus: Entity.Status = {
id: '3', id: '3',
uri: 'http://example.com', uri: 'http://example.com',
url: 'http://example.com', url: 'http://example.com',
@ -112,7 +112,7 @@ const rebloggedStatus: Status = {
poll: null, poll: null,
application: { application: {
name: 'Web' name: 'Web'
} as Application, } as Entity.Application,
language: null, language: null,
pinned: null pinned: null
} }

View File

@ -1,7 +1,7 @@
import i18n from '~/src/config/i18n' import i18n from '~/src/config/i18n'
import Jump, { JumpState, MUTATION_TYPES, Channel } from '@/store/TimelineSpace/Modals/Jump' import Jump, { JumpState, MUTATION_TYPES, Channel } from '@/store/TimelineSpace/Modals/Jump'
import { LocalTag } from '~/src/types/localTag' import { LocalTag } from '~/src/types/localTag'
import { List } from 'megalodon' import { Entity } from 'megalodon'
describe('TimelineSpace/Modals/Jump', () => { describe('TimelineSpace/Modals/Jump', () => {
describe('mutations', () => { describe('mutations', () => {
@ -55,15 +55,15 @@ describe('TimelineSpace/Modals/Jump', () => {
describe('updateListChannel', () => { describe('updateListChannel', () => {
it('should be updated', () => { it('should be updated', () => {
const admin: List = { const admin: Entity.List = {
id: '0', id: '0',
title: 'admin' title: 'admin'
} }
const engineer: List = { const engineer: Entity.List = {
id: '1', id: '1',
title: 'engineer' title: 'engineer'
} }
const designer: List = { const designer: Entity.List = {
id: '2', id: '2',
title: 'designer' title: 'designer'
} }