2018-12-30 16:03:36 +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-04 15:59:05 +02:00
|
|
|
import GlobalHeader, { GlobalHeaderState } from '~/src/renderer/store/GlobalHeader'
|
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
|
2018-12-30 16:03:36 +01:00
|
|
|
|
2019-04-04 15:59:05 +02:00
|
|
|
const state = (): GlobalHeaderState => {
|
2019-02-16 11:41:58 +01:00
|
|
|
return {
|
|
|
|
accounts: [],
|
|
|
|
changing: false,
|
|
|
|
hide: false
|
|
|
|
}
|
2018-12-30 16:03:36 +01:00
|
|
|
}
|
|
|
|
|
2019-02-16 11:41:58 +01:00
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: GlobalHeader.actions,
|
|
|
|
mutations: GlobalHeader.mutations
|
|
|
|
}
|
2018-12-30 16:03:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const routerState = {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
params: {
|
|
|
|
id: 'account_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('GlobalHeader', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
2019-02-16 11:41:58 +01:00
|
|
|
GlobalHeader: initStore(),
|
2018-12-30 16:03:36 +01:00
|
|
|
route: routerState
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('listAccounts', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('list-accounts', () => {
|
|
|
|
return ['account']
|
2018-12-30 16:03:36 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('list-accounts')
|
|
|
|
})
|
2018-12-30 16:03:36 +01:00
|
|
|
it('should be updated', async () => {
|
|
|
|
await store.dispatch('GlobalHeader/listAccounts')
|
|
|
|
expect(store.state.GlobalHeader.accounts).toEqual(['account'])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('refreshAccounts', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('refresh-accounts', () => {
|
|
|
|
return ['accounts']
|
2018-12-30 16:03:36 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('refresh-accounts')
|
|
|
|
})
|
2018-12-30 16:03:36 +01:00
|
|
|
it('should be refreshed', async () => {
|
|
|
|
await store.dispatch('GlobalHeader/refreshAccounts')
|
|
|
|
expect(store.state.GlobalHeader.accounts).toEqual(['accounts'])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('removeShortcutEvents', () => {
|
|
|
|
it('should be removed', async () => {
|
|
|
|
const removed = await store.dispatch('GlobalHeader/removeShortcutEvents')
|
|
|
|
expect(removed).toEqual(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('loadHide', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-global-header', () => {
|
|
|
|
return true
|
2018-12-30 16:03:36 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('get-global-header')
|
|
|
|
})
|
2018-12-30 16:03:36 +01:00
|
|
|
it('should be changed', async () => {
|
|
|
|
await store.dispatch('GlobalHeader/loadHide')
|
|
|
|
expect(store.state.GlobalHeader.hide).toEqual(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('switchHide', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('change-global-header', (_, value) => {
|
|
|
|
return value
|
2018-12-30 16:03:36 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('change-global-header')
|
|
|
|
})
|
2018-12-30 16:03:36 +01:00
|
|
|
it('should be switched', async () => {
|
2019-02-16 11:41:58 +01:00
|
|
|
const hide = await store.dispatch('GlobalHeader/switchHide', true)
|
|
|
|
expect(hide).toEqual(true)
|
2018-12-30 16:03:36 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|