2019-01-23 15:18:28 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex from 'vuex'
|
2019-12-04 15:09:11 +01:00
|
|
|
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
2019-01-23 15:18:28 +01:00
|
|
|
import App from '@/store/App'
|
|
|
|
import DisplayStyle from '~/src/constants/displayStyle'
|
2019-04-17 13:46:47 +02:00
|
|
|
import { LightTheme, DarkTheme } from '~/src/constants/themeColor'
|
2019-01-23 15:18:28 +01:00
|
|
|
import Theme from '~/src/constants/theme'
|
|
|
|
import TimeFormat from '~/src/constants/timeFormat'
|
|
|
|
import Language from '~/src/constants/language'
|
|
|
|
import DefaultFonts from '@/utils/fonts'
|
2019-12-04 15:09:11 +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-23 15:18:28 +01:00
|
|
|
|
|
|
|
const state = () => {
|
|
|
|
return {
|
|
|
|
theme: LightTheme,
|
|
|
|
fontSize: 14,
|
|
|
|
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
|
|
|
|
notify: {
|
|
|
|
reply: true,
|
|
|
|
reblog: true,
|
|
|
|
favourite: true,
|
|
|
|
follow: true
|
|
|
|
},
|
|
|
|
timeFormat: TimeFormat.Absolute.value,
|
|
|
|
language: Language.en.key,
|
|
|
|
defaultFonts: DefaultFonts,
|
|
|
|
ignoreCW: false,
|
2020-12-25 07:27:13 +01:00
|
|
|
ignoreNSFW: false,
|
2019-02-18 14:16:19 +01:00
|
|
|
hideAllAttachments: false
|
2019-01-23 15:18:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: App.actions,
|
|
|
|
mutations: App.mutations
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('App', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
App: initStore()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('loadPreferences', () => {
|
|
|
|
describe('error', () => {
|
|
|
|
it('should not change', async () => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-preferences', async () => {
|
|
|
|
throw new Error()
|
2019-01-23 15:18:28 +01:00
|
|
|
})
|
2019-05-09 17:05:40 +02:00
|
|
|
await store.dispatch('App/loadPreferences').catch(err => {
|
|
|
|
expect(err instanceof Error).toEqual(true)
|
|
|
|
expect(store.state.App.theme).toEqual(LightTheme)
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.removeHandler('get-preferences')
|
2019-01-23 15:18:28 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
describe('success', () => {
|
|
|
|
it('should be changed', async () => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-preferences', () => {
|
|
|
|
return {
|
2019-01-23 15:18:28 +01:00
|
|
|
general: {
|
|
|
|
timeline: {
|
|
|
|
cw: true,
|
2020-12-25 07:27:13 +01:00
|
|
|
nsfw: true
|
2019-01-23 15:18:28 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
language: {
|
|
|
|
language: Language.en.key
|
|
|
|
},
|
|
|
|
notification: {
|
|
|
|
notify: {
|
|
|
|
reply: true,
|
|
|
|
reblog: true,
|
|
|
|
favourite: true,
|
|
|
|
follow: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
appearance: {
|
|
|
|
theme: Theme.Dark.key,
|
|
|
|
fontSize: 13,
|
|
|
|
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
|
|
|
|
timeFormat: TimeFormat.Absolute.value,
|
|
|
|
customThemeColor: LightTheme,
|
|
|
|
font: DefaultFonts[0]
|
|
|
|
}
|
2020-11-30 14:30:06 +01:00
|
|
|
}
|
2019-01-23 15:18:28 +01:00
|
|
|
})
|
|
|
|
await store.dispatch('App/loadPreferences')
|
|
|
|
expect(store.state.App.fontSize).toEqual(13)
|
|
|
|
expect(store.state.App.theme).toEqual(DarkTheme)
|
|
|
|
expect(store.state.App.ignoreCW).toEqual(true)
|
2020-12-25 07:27:13 +01:00
|
|
|
expect(store.state.App.ignoreNSFW).toEqual(true)
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.removeHandler('get-preferences')
|
2019-01-23 15:18:28 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|