2019-03-25 15:50:11 +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:24:24 +02:00
|
|
|
import Login, { LoginState } from '@/store/Login'
|
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-03-25 15:50:11 +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
|
|
|
detector: jest.fn(() => 'pleroma'),
|
|
|
|
__esModule: true
|
|
|
|
}))
|
2019-03-25 15:50:11 +01:00
|
|
|
|
2019-04-04 15:24:24 +02:00
|
|
|
const state = (): LoginState => {
|
2019-03-25 15:50:11 +01:00
|
|
|
return {
|
|
|
|
selectedInstance: null,
|
2020-03-17 16:21:57 +01:00
|
|
|
searching: false,
|
|
|
|
sns: 'mastodon'
|
2019-03-25 15:50:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: Login.actions,
|
|
|
|
mutations: Login.mutations
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 10:37:43 +01:00
|
|
|
const appState = {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
proxyConfiguration: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 15:50:11 +01:00
|
|
|
describe('Login', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
2019-10-27 10:37:43 +01:00
|
|
|
Login: initStore(),
|
|
|
|
App: appState
|
2019-03-25 15:50:11 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('fetchLogin', () => {
|
|
|
|
describe('error', () => {
|
|
|
|
it('should return error', async () => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-auth-url', () => {
|
|
|
|
throw new Error()
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
2019-09-14 15:34:45 +02:00
|
|
|
await store.dispatch('Login/fetchLogin', 'pleroma.io').catch((err: Error) => {
|
|
|
|
expect(err instanceof Error).toEqual(true)
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.removeHandler('get-auth-url')
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
describe('success', () => {
|
|
|
|
it('should return url', async () => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-auth-url', () => {
|
|
|
|
return 'http://example.com/auth'
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
|
|
|
const url = await store.dispatch('Login/fetchLogin', 'pleroma.io')
|
|
|
|
expect(url).toEqual('http://example.com/auth')
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.removeHandler('get-auth-url')
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('pageBack', () => {
|
|
|
|
it('should reset instance', () => {
|
|
|
|
store.dispatch('Login/pageBack')
|
|
|
|
expect(store.state.Login.selectedInstance).toEqual(null)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-03-26 16:44:40 +01:00
|
|
|
describe('confirmInstance', () => {
|
2019-03-25 15:50:11 +01:00
|
|
|
it('should change instance', async () => {
|
2019-04-04 15:24:24 +02:00
|
|
|
const result = await store.dispatch('Login/confirmInstance', 'pleroma.io')
|
|
|
|
expect(result).toEqual(true)
|
2019-03-25 15:50:11 +01:00
|
|
|
expect(store.state.Login.selectedInstance).toEqual('pleroma.io')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|