2019-10-23 16:07:20 +02:00
|
|
|
import { IpcMainEvent } from 'electron'
|
2019-03-25 15:50:11 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
import Theme from '~/src/constants/theme'
|
|
|
|
import DisplayStyle from '~/src/constants/displayStyle'
|
|
|
|
import TimeFormat from '~/src/constants/timeFormat'
|
2019-04-16 15:35:46 +02:00
|
|
|
import { LightTheme, DarkTheme } from '~/src/constants/themeColor'
|
2019-03-25 15:50:11 +01:00
|
|
|
import DefaultFonts from '@/utils/fonts'
|
2019-04-06 15:08:29 +02:00
|
|
|
import Appearance, { AppearanceState } from '@/store/Preferences/Appearance'
|
2019-12-04 14:35:53 +01:00
|
|
|
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
|
|
|
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
|
|
|
|
2019-04-06 15:08:29 +02:00
|
|
|
const state = (): AppearanceState => {
|
2019-03-25 15:50:11 +01:00
|
|
|
return {
|
|
|
|
appearance: {
|
|
|
|
theme: Theme.Light.key,
|
|
|
|
fontSize: 14,
|
|
|
|
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
|
|
|
|
timeFormat: TimeFormat.Absolute.value,
|
|
|
|
customThemeColor: LightTheme,
|
2019-06-05 14:51:02 +02:00
|
|
|
font: DefaultFonts[0],
|
|
|
|
tootPadding: 8
|
2019-03-25 15:50:11 +01:00
|
|
|
},
|
|
|
|
fonts: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: Appearance.actions,
|
|
|
|
mutations: Appearance.mutations
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const App = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
loadPreferences: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Preferences/Appearance', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
Preferences: initStore(),
|
|
|
|
App: App
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('load', () => {
|
2019-12-11 15:18:06 +01:00
|
|
|
describe('loadAppearance', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
ipcMain.once('get-preferences', (event: IpcMainEvent, _) => {
|
|
|
|
event.sender.send('response-get-preferences', {
|
|
|
|
appearance: {
|
|
|
|
theme: Theme.Dark.key,
|
|
|
|
fontSize: 15
|
|
|
|
}
|
|
|
|
})
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
|
|
|
})
|
2019-12-11 15:18:06 +01:00
|
|
|
it('should be loaded', async () => {
|
|
|
|
await store.dispatch('Preferences/loadAppearance')
|
|
|
|
expect(store.state.Preferences.appearance.theme).toEqual(Theme.Dark.key)
|
|
|
|
expect(store.state.Preferences.appearance.fontSize).toEqual(15)
|
|
|
|
})
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
2019-12-11 15:18:06 +01:00
|
|
|
describe('loadFonts', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
ipcMain.once('list-fonts', (event: IpcMainEvent, _) => {
|
|
|
|
event.sender.send('response-list-fonts', ['my-font'])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('should be loaded', async () => {
|
|
|
|
await store.dispatch('Preferences/loadFonts')
|
|
|
|
expect(store.state.Preferences.fonts).toEqual([DefaultFonts[0], 'my-font'])
|
2019-03-25 15:50:11 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('update', () => {
|
2019-12-11 15:18:06 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
ipcMain.once('update-preferences', (event: IpcMainEvent, config: any) => {
|
|
|
|
event.sender.send('response-update-preferences', config)
|
|
|
|
})
|
|
|
|
})
|
2019-03-25 15:50:11 +01:00
|
|
|
it('updateTheme', async () => {
|
|
|
|
await store.dispatch('Preferences/updateTheme', Theme.Dark.key)
|
|
|
|
expect(store.state.Preferences.appearance.theme).toEqual(Theme.Dark.key)
|
|
|
|
expect(App.actions.loadPreferences).toBeCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('updateFontSize', async () => {
|
|
|
|
await store.dispatch('Preferences/updateFontSize', 15)
|
|
|
|
expect(store.state.Preferences.appearance.fontSize).toEqual(15)
|
|
|
|
expect(App.actions.loadPreferences).toBeCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('updateDisplayNameStyle', async () => {
|
|
|
|
await store.dispatch('Preferences/updateDisplayNameStyle', DisplayStyle.DisplayName.value)
|
|
|
|
expect(store.state.Preferences.appearance.displayNameStyle).toEqual(DisplayStyle.DisplayName.value)
|
|
|
|
expect(App.actions.loadPreferences).toBeCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('updateTimeFormat', async () => {
|
|
|
|
await store.dispatch('Preferences/updateTimeFormat', TimeFormat.Relative.value)
|
|
|
|
expect(store.state.Preferences.appearance.timeFormat).toEqual(TimeFormat.Relative.value)
|
|
|
|
expect(App.actions.loadPreferences).toBeCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('updateCustomThemeColor', async () => {
|
|
|
|
await store.dispatch('Preferences/updateCustomThemeColor', DarkTheme)
|
|
|
|
expect(store.state.Preferences.appearance.customThemeColor).toEqual(DarkTheme)
|
|
|
|
expect(App.actions.loadPreferences).toBeCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('updateFont', async () => {
|
|
|
|
await store.dispatch('Preferences/updateFont', DefaultFonts[1])
|
|
|
|
expect(store.state.Preferences.appearance.font).toEqual(DefaultFonts[1])
|
|
|
|
expect(App.actions.loadPreferences).toBeCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|