2018-12-30 07:27:46 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex 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'
|
2020-04-11 11:22:49 +02:00
|
|
|
;((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,
|
2021-06-10 18:07:41 +02:00
|
|
|
hideAllAttachments: false,
|
2021-12-26 17:11:20 +01:00
|
|
|
useMarkerTimeline: []
|
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
|
|
|
}
|
|
|
|
|
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', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
2019-03-10 14:14:47 +01:00
|
|
|
Preferences: initStore(),
|
|
|
|
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 () => {
|
|
|
|
await store.dispatch('Preferences/loadGeneral')
|
|
|
|
expect(store.state.Preferences.general.sound.fav_rb).toEqual(false)
|
|
|
|
expect(store.state.Preferences.general.sound.toot).toEqual(false)
|
|
|
|
expect(store.state.Preferences.loading).toEqual(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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 () => {
|
|
|
|
await store.dispatch('Preferences/updateSound', {
|
|
|
|
fav_rb: false,
|
|
|
|
toot: false
|
|
|
|
})
|
|
|
|
expect(store.state.Preferences.general.sound.fav_rb).toEqual(false)
|
|
|
|
expect(store.state.Preferences.general.sound.toot).toEqual(false)
|
|
|
|
expect(store.state.Preferences.loading).toEqual(false)
|
|
|
|
})
|
|
|
|
})
|
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 () => {
|
|
|
|
await store.dispatch('Preferences/updateTimeline', {
|
|
|
|
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
|
|
|
})
|
|
|
|
expect(store.state.Preferences.general.timeline.cw).toEqual(true)
|
2020-12-25 07:27:13 +01:00
|
|
|
expect(store.state.Preferences.general.timeline.nsfw).toEqual(true)
|
2019-02-18 14:16:19 +01:00
|
|
|
expect(store.state.Preferences.general.timeline.hideAllAttachments).toEqual(true)
|
2019-01-23 14:25:18 +01:00
|
|
|
expect(store.state.Preferences.loading).toEqual(false)
|
|
|
|
})
|
|
|
|
})
|
2018-12-30 07:27:46 +01:00
|
|
|
})
|