2022-04-25 15:33:49 +02:00
|
|
|
import { createStore, Store } from 'vuex'
|
2019-12-04 14:35:53 +01:00
|
|
|
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
2019-04-06 15:08:29 +02:00
|
|
|
import General, { GeneralState } from '@/store/Preferences/General'
|
2019-12-04 14:35:53 +01:00
|
|
|
import { MyWindow } from '~/src/types/global'
|
2020-11-30 14:30:06 +01:00
|
|
|
import { IpcMainInvokeEvent } from 'electron'
|
2022-04-25 15:33:49 +02:00
|
|
|
import { RootState } from '@/store'
|
|
|
|
;(window as any as MyWindow).ipcRenderer = ipcRenderer
|
2018-12-30 07:27:46 +01:00
|
|
|
|
2019-04-06 15:08:29 +02:00
|
|
|
const state = (): GeneralState => {
|
2019-01-23 14:25:18 +01:00
|
|
|
return {
|
|
|
|
general: {
|
|
|
|
sound: {
|
|
|
|
fav_rb: true,
|
|
|
|
toot: true
|
|
|
|
},
|
|
|
|
timeline: {
|
|
|
|
cw: false,
|
2020-12-25 07:27:13 +01:00
|
|
|
nsfw: false,
|
2022-01-01 14:41:28 +01:00
|
|
|
hideAllAttachments: false
|
2019-09-23 15:54:37 +02:00
|
|
|
},
|
|
|
|
other: {
|
2021-03-25 11:04:31 +01:00
|
|
|
launch: false
|
2019-01-23 14:25:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
loading: false
|
|
|
|
}
|
2018-12-30 07:27:46 +01:00
|
|
|
}
|
2019-01-23 14:25:18 +01:00
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: General.actions,
|
|
|
|
mutations: General.mutations
|
|
|
|
}
|
2018-12-30 07:27:46 +01:00
|
|
|
}
|
|
|
|
|
2022-04-25 15:33:49 +02:00
|
|
|
const preferencesStore = () => ({
|
|
|
|
namespaced: true,
|
|
|
|
modules: {
|
|
|
|
General: initStore()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-03-10 14:14:47 +01:00
|
|
|
const app = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
2019-09-23 15:54:37 +02:00
|
|
|
loadPreferences(_) {
|
2019-03-10 14:14:47 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 07:27:46 +01:00
|
|
|
describe('Preferences/General', () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
let store: Store<RootState>
|
2018-12-30 07:27:46 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-04-25 15:33:49 +02:00
|
|
|
store = createStore({
|
2018-12-30 07:27:46 +01:00
|
|
|
modules: {
|
2022-04-25 15:33:49 +02:00
|
|
|
Preferences: preferencesStore(),
|
2019-03-10 14:14:47 +01:00
|
|
|
App: app
|
2018-12-30 07:27:46 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('loadGeneral', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-preferences', () => {
|
|
|
|
return {
|
2018-12-30 07:27:46 +01:00
|
|
|
general: {
|
|
|
|
sound: {
|
|
|
|
fav_rb: false,
|
2018-12-30 08:56:38 +01:00
|
|
|
toot: false
|
2018-12-30 07:27:46 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-30 14:30:06 +01:00
|
|
|
}
|
2018-12-30 07:27:46 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('get-preferences')
|
|
|
|
})
|
2018-12-30 07:27:46 +01:00
|
|
|
it('should be updated', async () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
await store.dispatch('Preferences/General/loadGeneral')
|
|
|
|
expect(store.state.Preferences.General.general.sound.fav_rb).toEqual(false)
|
|
|
|
expect(store.state.Preferences.General.general.sound.toot).toEqual(false)
|
|
|
|
expect(store.state.Preferences.General.loading).toEqual(false)
|
2018-12-30 07:27:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('updateSound', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('update-preferences', (_: IpcMainInvokeEvent, config: any) => {
|
|
|
|
return config
|
2018-12-30 07:27:46 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('update-preferences')
|
|
|
|
})
|
2018-12-30 07:27:46 +01:00
|
|
|
it('should be updated', async () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
await store.dispatch('Preferences/General/updateSound', {
|
2018-12-30 07:27:46 +01:00
|
|
|
fav_rb: false,
|
|
|
|
toot: false
|
|
|
|
})
|
2022-04-25 15:33:49 +02:00
|
|
|
expect(store.state.Preferences.General.general.sound.fav_rb).toEqual(false)
|
|
|
|
expect(store.state.Preferences.General.general.sound.toot).toEqual(false)
|
|
|
|
expect(store.state.Preferences.General.loading).toEqual(false)
|
2018-12-30 07:27:46 +01:00
|
|
|
})
|
|
|
|
})
|
2019-01-23 14:25:18 +01:00
|
|
|
|
|
|
|
describe('updateTimeline', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('update-preferences', (_: IpcMainInvokeEvent, config: any) => {
|
|
|
|
return config
|
2019-01-23 14:25:18 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('update-preferences')
|
|
|
|
})
|
2019-01-23 14:25:18 +01:00
|
|
|
it('should be updated', async () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
await store.dispatch('Preferences/General/updateTimeline', {
|
2019-01-23 14:25:18 +01:00
|
|
|
cw: true,
|
2020-12-25 07:27:13 +01:00
|
|
|
nsfw: true,
|
2019-02-18 14:16:19 +01:00
|
|
|
hideAllAttachments: true
|
2019-01-23 14:25:18 +01:00
|
|
|
})
|
2022-04-25 15:33:49 +02:00
|
|
|
expect(store.state.Preferences.General.general.timeline.cw).toEqual(true)
|
|
|
|
expect(store.state.Preferences.General.general.timeline.nsfw).toEqual(true)
|
|
|
|
expect(store.state.Preferences.General.general.timeline.hideAllAttachments).toEqual(true)
|
|
|
|
expect(store.state.Preferences.General.loading).toEqual(false)
|
2019-01-23 14:25:18 +01:00
|
|
|
})
|
|
|
|
})
|
2018-12-30 07:27:46 +01:00
|
|
|
})
|