2020-03-15 09:48:02 +01:00
|
|
|
import { Entity, Response } from 'megalodon'
|
2019-01-22 15:47:16 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex from 'vuex'
|
2019-12-04 15:03:34 +01:00
|
|
|
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
2019-04-07 15:48:37 +02:00
|
|
|
import TimelineSpace, { TimelineSpaceState, blankAccount } from '~/src/renderer/store/TimelineSpace'
|
2019-12-04 15:03:34 +01:00
|
|
|
import { MyWindow } from '~/src/types/global'
|
2020-04-11 11:22:49 +02:00
|
|
|
;((window as any) as MyWindow).ipcRenderer = ipcRenderer
|
2019-01-22 15:47:16 +01:00
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
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
|
|
|
|
}
|
2019-01-22 15:47:16 +01:00
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
const mockedInstance: Entity.Instance = {
|
2019-04-07 15:48:37 +02:00
|
|
|
uri: 'http://pleroma.io',
|
|
|
|
title: 'pleroma',
|
|
|
|
description: '',
|
|
|
|
email: 'test@example.com',
|
|
|
|
version: '2.5.0 (compatible; Pleroma 0.9.0-3363-g7c5d2dc7)',
|
|
|
|
thumbnail: null,
|
|
|
|
urls: {
|
|
|
|
streaming_api: 'wss://pleroma.io'
|
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
user_count: 10,
|
|
|
|
status_count: 1000,
|
|
|
|
domain_count: 100
|
|
|
|
},
|
|
|
|
languages: ['en'],
|
|
|
|
contact_account: null,
|
|
|
|
max_toot_chars: 5000
|
|
|
|
}
|
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
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', () => ({
|
2020-09-13 10:24:36 +02:00
|
|
|
...jest.requireActual<object>('megalodon'),
|
2020-03-15 09:48:02 +01:00
|
|
|
detector: jest.fn(() => 'pleroma'),
|
|
|
|
default: jest.fn(() => mockClient),
|
|
|
|
__esModule: true
|
|
|
|
}))
|
|
|
|
|
2019-04-07 15:48:37 +02:00
|
|
|
const state = (): TimelineSpaceState => {
|
2019-01-22 15:47:16 +01:00
|
|
|
return {
|
2019-04-07 15:48:37 +02:00
|
|
|
account: blankAccount,
|
2019-07-01 15:47:01 +02:00
|
|
|
bindingAccount: null,
|
2019-01-22 15:47:16 +01:00
|
|
|
loading: false,
|
|
|
|
emojis: [],
|
|
|
|
tootMax: 500,
|
2022-01-01 10:39:33 +01:00
|
|
|
timelineSetting: {
|
|
|
|
unreadNotification: {
|
|
|
|
direct: true,
|
|
|
|
local: true,
|
|
|
|
public: true
|
2022-01-01 14:41:28 +01:00
|
|
|
},
|
|
|
|
useMarker: {
|
|
|
|
home: false,
|
2022-03-18 16:46:22 +01:00
|
|
|
notifications: true,
|
|
|
|
mentions: false
|
2022-01-01 10:39:33 +01:00
|
|
|
}
|
2019-01-22 15:47:16 +01:00
|
|
|
},
|
2021-05-21 18:43:27 +02:00
|
|
|
sns: 'mastodon',
|
|
|
|
filters: []
|
2019-01-22 15:47:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const homeStore = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
fetchTimeline: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const notificationStore = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
fetchNotifications: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const DMStore = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
fetchTimeline: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const LocalStore = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
fetchLocalTimeline: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const PublicStore = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
fetchPublicTimeline: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-19 01:07:13 +01:00
|
|
|
const MentionStore = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
fetchMentions: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 15:47:16 +01:00
|
|
|
const contentsStore = {
|
|
|
|
namespaced: true,
|
|
|
|
modules: {
|
|
|
|
Home: homeStore,
|
|
|
|
Notifications: notificationStore,
|
|
|
|
DirectMessages: DMStore,
|
|
|
|
Local: LocalStore,
|
2019-03-19 01:07:13 +01:00
|
|
|
Public: PublicStore,
|
|
|
|
Mentions: MentionStore
|
2019-05-27 16:04:53 +02:00
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
changeLoading: jest.fn()
|
2019-01-22 15:47:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
modules: {
|
|
|
|
Contents: contentsStore
|
|
|
|
},
|
|
|
|
state: state(),
|
|
|
|
actions: TimelineSpace.actions,
|
|
|
|
mutations: TimelineSpace.mutations
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 10:37:43 +01:00
|
|
|
const appState = {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
proxyConfiguration: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 15:47:16 +01:00
|
|
|
describe('TimelineSpace', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
2019-10-27 10:37:43 +01:00
|
|
|
TimelineSpace: initStore(),
|
|
|
|
App: appState
|
2019-01-22 15:47:16 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('localAccount', () => {
|
|
|
|
describe('account already exists', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-local-account', () => {
|
|
|
|
return {
|
2019-01-22 15:47:16 +01:00
|
|
|
username: 'test'
|
2020-11-30 14:30:06 +01:00
|
|
|
}
|
2019-01-22 15:47:16 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('get-local-account')
|
|
|
|
})
|
2019-01-22 15:47:16 +01:00
|
|
|
it('should be updated', async () => {
|
|
|
|
await store.dispatch('TimelineSpace/localAccount', 1)
|
|
|
|
expect(store.state.TimelineSpace.account.username).toEqual('test')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('account does not exist', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-local-account', () => {
|
|
|
|
return {}
|
2019-01-22 15:47:16 +01:00
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('update-account', () => {
|
|
|
|
return {
|
2019-01-22 15:47:16 +01:00
|
|
|
username: 'fetched'
|
2020-11-30 14:30:06 +01:00
|
|
|
}
|
2019-01-22 15:47:16 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('get-local-account')
|
|
|
|
ipcMain.removeHandler('update-account')
|
|
|
|
})
|
2019-01-22 15:47:16 +01:00
|
|
|
it('should be fetched', async () => {
|
|
|
|
await store.dispatch('TimelineSpace/localAccount', 1)
|
|
|
|
expect(store.state.TimelineSpace.account.username).toEqual('fetched')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
describe('detectSNS', () => {
|
2019-01-22 15:47:16 +01:00
|
|
|
describe('API is pleroma', () => {
|
|
|
|
it('should be detected', async () => {
|
2020-03-15 09:48:02 +01:00
|
|
|
await store.dispatch('TimelineSpace/detectSNS')
|
|
|
|
expect(store.state.TimelineSpace.sns).toEqual('pleroma')
|
2019-01-22 15:47:16 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('fetchEmojis', () => {
|
|
|
|
it('should be updated', async () => {
|
|
|
|
await store.dispatch('TimelineSpace/fetchEmojis', {})
|
2020-03-15 09:48:02 +01:00
|
|
|
expect(store.state.TimelineSpace.emojis).toEqual([emacsEmoji, rubyEmoji])
|
2019-01-22 15:47:16 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('fetchInstance', () => {
|
|
|
|
it('should be updated', async () => {
|
|
|
|
await store.dispatch('TimelineSpace/fetchInstance', {})
|
2020-03-15 09:48:02 +01:00
|
|
|
expect(store.state.TimelineSpace.tootMax).toEqual(mockedInstance.max_toot_chars)
|
2019-01-22 15:47:16 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('loadUnreadNotification', () => {
|
|
|
|
describe('success', () => {
|
|
|
|
it('should be updated', async () => {
|
2022-01-01 10:39:33 +01:00
|
|
|
ipcMain.handle('get-account-setting', () => {
|
2020-11-30 14:30:06 +01:00
|
|
|
return {
|
2022-01-01 10:39:33 +01:00
|
|
|
accountID: 'sample',
|
|
|
|
timeline: {
|
|
|
|
unreadNotification: {
|
|
|
|
direct: false,
|
|
|
|
local: false,
|
|
|
|
public: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await store.dispatch('TimelineSpace/loadTimelineSetting')
|
|
|
|
expect(store.state.TimelineSpace.timelineSetting).toEqual({
|
|
|
|
unreadNotification: {
|
2019-01-22 15:47:16 +01:00
|
|
|
direct: false,
|
|
|
|
local: false,
|
|
|
|
public: false
|
2020-11-30 14:30:06 +01:00
|
|
|
}
|
2019-01-22 15:47:16 +01:00
|
|
|
})
|
2022-01-01 10:39:33 +01:00
|
|
|
ipcMain.removeHandler('get-account-setting')
|
2019-01-22 15:47:16 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('fetchContentsTimelines', () => {
|
|
|
|
it('should be called', async () => {
|
|
|
|
await store.dispatch('TimelineSpace/fetchContentsTimelines', {})
|
|
|
|
expect(homeStore.actions.fetchTimeline).toHaveBeenCalled()
|
|
|
|
expect(notificationStore.actions.fetchNotifications).toHaveBeenCalled()
|
|
|
|
expect(DMStore.actions.fetchTimeline).toHaveBeenCalled()
|
|
|
|
expect(LocalStore.actions.fetchLocalTimeline).toHaveBeenCalled()
|
|
|
|
expect(PublicStore.actions.fetchPublicTimeline).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|