Use ipcRenderer through window to mock ipc method in TimelineSpace
This commit is contained in:
parent
9a3ed1fe43
commit
a805ce6a49
|
@ -1,9 +1,11 @@
|
|||
import { IpcMainEvent } from 'electron'
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import { ipcMain } from '~/spec/mock/electron'
|
||||
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
||||
import Vuex from 'vuex'
|
||||
import { LocalTag } from '~/src/types/localTag'
|
||||
import List, { ListState } from '@/store/TimelineSpace/Contents/Hashtag/List'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
;(window as MyWindow).ipcRenderer = ipcRenderer
|
||||
|
||||
const tag1: LocalTag = {
|
||||
tagName: 'tag1',
|
||||
|
|
|
@ -2,9 +2,11 @@ import { Response, List } from 'megalodon'
|
|||
import mockedMegalodon from '~/spec/mock/megalodon'
|
||||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import { ipcMain } from '~/spec/mock/electron'
|
||||
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
||||
import SideMenu, { SideMenuState } from '~/src/renderer/store/TimelineSpace/SideMenu'
|
||||
import { LocalTag } from '~/src/types/localTag'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
;(window as MyWindow).ipcRenderer = ipcRenderer
|
||||
|
||||
jest.mock('megalodon')
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import List, { ListState } from './Hashtag/List'
|
||||
import Tag, { TagState } from './Hashtag/Tag'
|
||||
import { Module, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type HashtagState = {}
|
||||
|
||||
|
@ -17,10 +19,10 @@ const state = (): HashtagState => ({})
|
|||
|
||||
const actions: ActionTree<HashtagState, RootState> = {
|
||||
saveTag: ({ dispatch }, tag: string) => {
|
||||
ipcRenderer.once('response-save-hashtag', () => {
|
||||
win.ipcRenderer.once('response-save-hashtag', () => {
|
||||
dispatch('TimelineSpace/SideMenu/listTags', {}, { root: true })
|
||||
})
|
||||
ipcRenderer.send('save-hashtag', tag)
|
||||
win.ipcRenderer.send('save-hashtag', tag)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import { LocalTag } from '~/src/types/localTag'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type ListState = {
|
||||
tags: Array<LocalTag>
|
||||
|
@ -24,31 +26,31 @@ const mutations: MutationTree<ListState> = {
|
|||
const actions: ActionTree<ListState, RootState> = {
|
||||
listTags: ({ commit }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once('response-list-hashtags', (_, tags: Array<LocalTag>) => {
|
||||
ipcRenderer.removeAllListeners('error-list-hashtags')
|
||||
win.ipcRenderer.once('response-list-hashtags', (_, tags: Array<LocalTag>) => {
|
||||
win.ipcRenderer.removeAllListeners('error-list-hashtags')
|
||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||
resolve(tags)
|
||||
})
|
||||
ipcRenderer.once('error-list-hashtags', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-list-hashtags')
|
||||
win.ipcRenderer.once('error-list-hashtags', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-list-hashtags')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.send('list-hashtags')
|
||||
win.ipcRenderer.send('list-hashtags')
|
||||
})
|
||||
},
|
||||
removeTag: ({ dispatch }, tag: LocalTag) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once('response-remove-hashtag', () => {
|
||||
ipcRenderer.removeAllListeners('error-remove-hashtag')
|
||||
win.ipcRenderer.once('response-remove-hashtag', () => {
|
||||
win.ipcRenderer.removeAllListeners('error-remove-hashtag')
|
||||
dispatch('listTags')
|
||||
dispatch('TimelineSpace/SideMenu/listTags', {}, { root: true })
|
||||
resolve('deleted')
|
||||
})
|
||||
ipcRenderer.once('error-remove-hashtag', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-remove-hashtag')
|
||||
win.ipcRenderer.once('error-remove-hashtag', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-remove-hashtag')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.send('remove-hashtag', tag)
|
||||
win.ipcRenderer.send('remove-hashtag', tag)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import Mastodon, { Status, Response } from 'megalodon'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { LoadPositionWithTag } from '@/types/loadPosition'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type TagState = {
|
||||
timeline: Array<Status>
|
||||
|
@ -111,33 +113,33 @@ const actions: ActionTree<TagState, RootState> = {
|
|||
return res.data
|
||||
},
|
||||
startStreaming: ({ state, commit, rootState }, tag: string) => {
|
||||
ipcRenderer.on('update-start-tag-streaming', (_, update: Status) => {
|
||||
win.ipcRenderer.on('update-start-tag-streaming', (_, update: Status) => {
|
||||
commit(MUTATION_TYPES.APPEND_TIMELINE, update)
|
||||
if (state.heading && Math.random() > 0.8) {
|
||||
commit(MUTATION_TYPES.ARCHIVE_TIMELINE)
|
||||
}
|
||||
})
|
||||
ipcRenderer.on('delete-start-tag-streaming', (_, id: string) => {
|
||||
win.ipcRenderer.on('delete-start-tag-streaming', (_, id: string) => {
|
||||
commit(MUTATION_TYPES.DELETE_TOOT, id)
|
||||
})
|
||||
// @ts-ignore
|
||||
return new Promise((resolve, reject) => {
|
||||
// eslint-disable-line no-unused-vars
|
||||
ipcRenderer.send('start-tag-streaming', {
|
||||
win.ipcRenderer.send('start-tag-streaming', {
|
||||
tag: encodeURIComponent(tag),
|
||||
account: rootState.TimelineSpace.account
|
||||
})
|
||||
ipcRenderer.once('error-start-tag-streaming', (_, err: Error) => {
|
||||
win.ipcRenderer.once('error-start-tag-streaming', (_, err: Error) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
stopStreaming: () => {
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.removeAllListeners('error-start-tag-streaming')
|
||||
ipcRenderer.removeAllListeners('update-start-tag-streaming')
|
||||
ipcRenderer.removeAllListeners('delete-start-tag-streaming')
|
||||
ipcRenderer.send('stop-tag-streaming')
|
||||
win.ipcRenderer.removeAllListeners('error-start-tag-streaming')
|
||||
win.ipcRenderer.removeAllListeners('update-start-tag-streaming')
|
||||
win.ipcRenderer.removeAllListeners('delete-start-tag-streaming')
|
||||
win.ipcRenderer.send('stop-tag-streaming')
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import Mastodon, { Status, Response } from 'megalodon'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { LoadPositionWithList } from '@/types/loadPosition'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type ShowState = {
|
||||
timeline: Array<Status>
|
||||
|
@ -111,33 +113,33 @@ const actions: ActionTree<ShowState, RootState> = {
|
|||
return res.data
|
||||
},
|
||||
startStreaming: ({ state, commit, rootState }, listID: string) => {
|
||||
ipcRenderer.on('update-start-list-streaming', (_, update: Status) => {
|
||||
win.ipcRenderer.on('update-start-list-streaming', (_, update: Status) => {
|
||||
commit(MUTATION_TYPES.APPEND_TIMELINE, update)
|
||||
if (state.heading && Math.random() > 0.8) {
|
||||
commit(MUTATION_TYPES.ARCHIVE_TIMELINE)
|
||||
}
|
||||
})
|
||||
ipcRenderer.on('delete-start-list-streaming', (_, id: string) => {
|
||||
win.ipcRenderer.on('delete-start-list-streaming', (_, id: string) => {
|
||||
commit(MUTATION_TYPES.DELETE_TOOT, id)
|
||||
})
|
||||
// @ts-ignore
|
||||
return new Promise((resolve, reject) => {
|
||||
// eslint-disable-line no-unused-vars
|
||||
ipcRenderer.send('start-list-streaming', {
|
||||
win.ipcRenderer.send('start-list-streaming', {
|
||||
listID: listID,
|
||||
account: rootState.TimelineSpace.account
|
||||
})
|
||||
ipcRenderer.once('error-start-list-streaming', (_, err: Error) => {
|
||||
win.ipcRenderer.once('error-start-list-streaming', (_, err: Error) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
stopStreaming: () => {
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.removeAllListeners('error-start-list-streaming')
|
||||
ipcRenderer.removeAllListeners('update-start-list-streaming')
|
||||
ipcRenderer.removeAllListeners('delete-start-list-streaming')
|
||||
ipcRenderer.send('stop-list-streaming')
|
||||
win.ipcRenderer.removeAllListeners('error-start-list-streaming')
|
||||
win.ipcRenderer.removeAllListeners('update-start-list-streaming')
|
||||
win.ipcRenderer.removeAllListeners('delete-start-list-streaming')
|
||||
win.ipcRenderer.send('stop-list-streaming')
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { ipcRenderer } from 'electron'
|
||||
import Mastodon, { Notification, Status, Response } from 'megalodon'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type NotificationsState = {
|
||||
lazyLoading: boolean
|
||||
|
@ -136,7 +138,7 @@ const actions: ActionTree<NotificationsState, RootState> = {
|
|||
})
|
||||
},
|
||||
resetBadge: () => {
|
||||
ipcRenderer.send('reset-badge')
|
||||
win.ipcRenderer.send('reset-badge')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import Mastodon, { List, Response, Account } from 'megalodon'
|
||||
import { ipcRenderer } from 'electron'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { LocalTag } from '~/src/types/localTag'
|
||||
import { LocalAccount } from '~/src/types/localAccount'
|
||||
import { RootState } from '@/store'
|
||||
import { MyWindow } from '~/src/types/global'
|
||||
|
||||
const win = window as MyWindow
|
||||
|
||||
export type SideMenuState = {
|
||||
unreadHomeTimeline: boolean
|
||||
|
@ -111,13 +113,13 @@ const actions: ActionTree<SideMenuState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_UNREAD_PUBLIC_TIMELINE, false)
|
||||
},
|
||||
changeCollapse: ({ commit }, value: boolean) => {
|
||||
ipcRenderer.send('change-collapse', value)
|
||||
win.ipcRenderer.send('change-collapse', value)
|
||||
commit(MUTATION_TYPES.CHANGE_COLLAPSE, value)
|
||||
},
|
||||
readCollapse: ({ commit }) => {
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.send('get-collapse')
|
||||
ipcRenderer.once('response-get-collapse', (_, value: boolean) => {
|
||||
win.ipcRenderer.send('get-collapse')
|
||||
win.ipcRenderer.once('response-get-collapse', (_, value: boolean) => {
|
||||
commit(MUTATION_TYPES.CHANGE_COLLAPSE, value)
|
||||
resolve(value)
|
||||
})
|
||||
|
@ -125,16 +127,16 @@ const actions: ActionTree<SideMenuState, RootState> = {
|
|||
},
|
||||
listTags: ({ commit }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once('response-list-hashtags', (_, tags: Array<LocalTag>) => {
|
||||
ipcRenderer.removeAllListeners('error-list-hashtags')
|
||||
win.ipcRenderer.once('response-list-hashtags', (_, tags: Array<LocalTag>) => {
|
||||
win.ipcRenderer.removeAllListeners('error-list-hashtags')
|
||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||
resolve(tags)
|
||||
})
|
||||
ipcRenderer.once('error-list-hashtags', (_, err: Error) => {
|
||||
ipcRenderer.removeAllListeners('response-list-hashtags')
|
||||
win.ipcRenderer.once('error-list-hashtags', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-list-hashtags')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.send('list-hashtags')
|
||||
win.ipcRenderer.send('list-hashtags')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue