2020-03-15 09:48:02 +01:00
|
|
|
import { Entity, Response } from 'megalodon'
|
2022-04-25 15:33:49 +02:00
|
|
|
import { createStore, Store } from 'vuex'
|
2019-12-04 15:03:21 +01:00
|
|
|
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
2019-04-08 15:45:02 +02:00
|
|
|
import SideMenu, { SideMenuState } from '~/src/renderer/store/TimelineSpace/SideMenu'
|
2019-06-06 16:44:50 +02:00
|
|
|
import { LocalTag } from '~/src/types/localTag'
|
2019-12-04 15:03:21 +01:00
|
|
|
import { MyWindow } from '~/src/types/global'
|
2022-04-25 15:33:49 +02:00
|
|
|
import { RootState } from '@/store'
|
|
|
|
;(window as any as MyWindow).ipcRenderer = ipcRenderer
|
2018-12-31 15:36:46 +01:00
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2018-12-31 15:36:46 +01:00
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
jest.mock('megalodon', () => ({
|
2020-09-13 10:24:36 +02:00
|
|
|
...jest.requireActual<object>('megalodon'),
|
2020-03-15 09:48:02 +01:00
|
|
|
default: jest.fn(() => mockClient),
|
|
|
|
__esModule: true
|
|
|
|
}))
|
|
|
|
|
|
|
|
// import mockedMegalodon from '~/spec/mock/megalodon'
|
|
|
|
|
|
|
|
const list1: Entity.List = {
|
2019-05-27 16:04:53 +02:00
|
|
|
id: '1',
|
2019-04-03 15:15:46 +02:00
|
|
|
title: 'example1'
|
2019-04-02 16:24:06 +02:00
|
|
|
}
|
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
const list2: Entity.List = {
|
2019-05-27 16:04:53 +02:00
|
|
|
id: '2',
|
2019-04-03 15:15:46 +02:00
|
|
|
title: 'example2'
|
2019-04-02 16:24:06 +02:00
|
|
|
}
|
|
|
|
|
2019-04-08 15:45:02 +02:00
|
|
|
const state = (): SideMenuState => {
|
2019-02-16 11:41:58 +01:00
|
|
|
return {
|
|
|
|
unreadHomeTimeline: false,
|
|
|
|
unreadNotifications: false,
|
2019-04-08 15:45:02 +02:00
|
|
|
unreadMentions: false,
|
2019-02-16 11:41:58 +01:00
|
|
|
unreadLocalTimeline: false,
|
|
|
|
unreadDirectMessagesTimeline: false,
|
|
|
|
unreadPublicTimeline: false,
|
2019-05-11 16:01:59 +02:00
|
|
|
unreadFollowRequests: false,
|
2019-02-16 11:41:58 +01:00
|
|
|
lists: [],
|
|
|
|
tags: [],
|
2020-03-31 14:14:24 +02:00
|
|
|
collapse: false,
|
|
|
|
enabledTimelines: {
|
|
|
|
home: true,
|
|
|
|
notification: true,
|
|
|
|
mention: true,
|
|
|
|
direct: true,
|
|
|
|
favourite: true,
|
2020-08-24 10:23:37 +02:00
|
|
|
bookmark: true,
|
2020-03-31 14:14:24 +02:00
|
|
|
local: true,
|
|
|
|
public: true,
|
|
|
|
tag: true,
|
|
|
|
list: true
|
|
|
|
}
|
2019-02-16 11:41:58 +01:00
|
|
|
}
|
2018-12-31 15:36:46 +01:00
|
|
|
}
|
|
|
|
|
2019-02-16 11:41:58 +01:00
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: SideMenu.actions,
|
|
|
|
mutations: SideMenu.mutations
|
|
|
|
}
|
2018-12-31 15:36:46 +01:00
|
|
|
}
|
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
const appStore = {
|
2019-10-27 10:37:43 +01:00
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
proxyConfiguration: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-25 15:33:49 +02:00
|
|
|
const timelineStore = () => ({
|
2020-03-15 09:48:02 +01:00
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
sns: 'mastodon'
|
2022-04-25 15:33:49 +02:00
|
|
|
},
|
|
|
|
modules: {
|
|
|
|
SideMenu: initStore()
|
2020-03-15 09:48:02 +01:00
|
|
|
}
|
2022-04-25 15:33:49 +02:00
|
|
|
})
|
2020-03-15 09:48:02 +01:00
|
|
|
|
2018-12-31 15:36:46 +01:00
|
|
|
describe('SideMenu', () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
let store: Store<RootState>
|
2018-12-31 15:36:46 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-04-25 15:33:49 +02:00
|
|
|
store = createStore({
|
2018-12-31 15:36:46 +01:00
|
|
|
modules: {
|
2020-03-15 09:48:02 +01:00
|
|
|
App: appStore,
|
2022-04-25 15:33:49 +02:00
|
|
|
TimelineSpace: timelineStore()
|
2018-12-31 15:36:46 +01:00
|
|
|
}
|
|
|
|
})
|
2020-03-15 09:48:02 +01:00
|
|
|
// mockedMegalodon.mockClear()
|
2018-12-31 15:36:46 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('fetchLists', () => {
|
|
|
|
it('should be updated', async () => {
|
2020-03-15 09:48:02 +01:00
|
|
|
// mockedMegalodon.mockImplementation(() => mockClient)
|
2018-12-31 15:36:46 +01:00
|
|
|
const account = {
|
|
|
|
accessToken: 'token',
|
|
|
|
baseURL: 'http://localhost'
|
|
|
|
}
|
2022-04-25 15:33:49 +02:00
|
|
|
const lists = await store.dispatch('TimelineSpace/SideMenu/fetchLists', account)
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.lists).toEqual([list1, list2])
|
2019-04-02 16:24:06 +02:00
|
|
|
expect(lists).toEqual([list1, list2])
|
2018-12-31 15:36:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('clearUnread', () => {
|
|
|
|
it('should be resetted', () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
store.dispatch('TimelineSpace/SideMenu/clearUnread')
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.unreadHomeTimeline).toEqual(false)
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.unreadNotifications).toEqual(false)
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.unreadLocalTimeline).toEqual(false)
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.unreadDirectMessagesTimeline).toEqual(false)
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.unreadPublicTimeline).toEqual(false)
|
2018-12-31 15:36:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('changeCollapse', () => {
|
|
|
|
it('should be changed', () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
store.dispatch('TimelineSpace/SideMenu/changeCollapse', true)
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.collapse).toEqual(true)
|
2018-12-31 15:36:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('readCollapse', () => {
|
|
|
|
it('should be read', async () => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-collapse', () => {
|
|
|
|
return true
|
2018-12-31 15:36:46 +01:00
|
|
|
})
|
2022-04-25 15:33:49 +02:00
|
|
|
await store.dispatch('TimelineSpace/SideMenu/readCollapse')
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.collapse).toEqual(true)
|
2018-12-31 15:36:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('listTags', () => {
|
|
|
|
it('should be listed', async () => {
|
2019-04-16 14:44:46 +02:00
|
|
|
const tag1: LocalTag = {
|
2019-04-08 15:45:02 +02:00
|
|
|
tagName: 'tag1'
|
|
|
|
}
|
2019-04-16 14:44:46 +02:00
|
|
|
const tag2: LocalTag = {
|
2019-04-08 15:45:02 +02:00
|
|
|
tagName: 'tag2'
|
|
|
|
}
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('list-hashtags', () => {
|
|
|
|
return [tag1, tag2]
|
2018-12-31 15:36:46 +01:00
|
|
|
})
|
2022-04-25 15:33:49 +02:00
|
|
|
await store.dispatch('TimelineSpace/SideMenu/listTags')
|
|
|
|
expect(store.state.TimelineSpace.SideMenu.tags).toEqual([tag1, tag2])
|
2018-12-31 15:36:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|