refs #825 Set default value to ignoreCW and ignoreNFSW

This commit is contained in:
AkiraFukushima 2019-01-23 23:18:28 +09:00
parent d5f2db098a
commit 3a06489e74
3 changed files with 125 additions and 9 deletions

View File

@ -0,0 +1,106 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import App from '@/store/App'
import DisplayStyle from '~/src/constants/displayStyle'
import { LightTheme, DarkTheme } from '@/utils/theme'
import Theme from '~/src/constants/theme'
import TimeFormat from '~/src/constants/timeFormat'
import Language from '~/src/constants/language'
import DefaultFonts from '@/utils/fonts'
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,
ignoreNFSW: false
}
}
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 () => {
ipcMain.once('get-preferences', (event, _) => {
event.sender.send('error-get-preferences', new Error())
})
await store.dispatch('App/loadPreferences')
.catch((err) => {
expect(err instanceof Error).toEqual(true)
expect(store.state.App.theme).toEqual(LightTheme)
})
})
})
describe('success', () => {
it('should be changed', async () => {
ipcMain.once('get-preferences', (event, _) => {
event.sender.send('response-get-preferences', {
general: {
timeline: {
cw: true,
nfsw: true
}
},
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]
}
})
})
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)
expect(store.state.App.ignoreNFSW).toEqual(true)
})
})
})
})

View File

@ -156,8 +156,8 @@ export default {
},
data () {
return {
showContent: false,
showAttachments: false,
showContent: this.$store.state.App.ignoreCW,
showAttachments: this.$store.state.App.ignoreNFSW,
now: Date.now()
}
},
@ -184,10 +184,10 @@ export default {
}
},
computed: {
...mapState({
displayNameStyle: state => state.App.displayNameStyle,
timeFormat: state => state.App.timeFormat,
language: state => state.App.language
...mapState('App', {
displayNameStyle: state => state.displayNameStyle,
timeFormat: state => state.timeFormat,
language: state => state.language
}),
shortcutEnabled: function () {
return this.focused && !this.overlaid

View File

@ -1,11 +1,11 @@
import { ipcRenderer } from 'electron'
import router from '@/router'
import { LightTheme, DarkTheme, SolarizedLightTheme, SolarizedDarkTheme, KimbieDarkTheme } from '../utils/theme'
import { LightTheme, DarkTheme, SolarizedLightTheme, SolarizedDarkTheme, KimbieDarkTheme } from '@/utils/theme'
import DisplayStyle from '~/src/constants/displayStyle'
import Theme from '~/src/constants/theme'
import TimeFormat from '~/src/constants/timeFormat'
import Language from '~/src/constants/language'
import DefaultFonts from '../utils/fonts'
import DefaultFonts from '@/utils/fonts'
const App = {
namespaced: true,
@ -21,7 +21,9 @@ const App = {
},
timeFormat: TimeFormat.Absolute.value,
language: Language.en.key,
defaultFonts: DefaultFonts
defaultFonts: DefaultFonts,
ignoreCW: false,
ignoreNFSW: false
},
mutations: {
updateTheme (state, themeColorList) {
@ -45,6 +47,12 @@ const App = {
addFont (state, font) {
const list = [font].concat(DefaultFonts)
state.defaultFonts = Array.from(new Set(list))
},
updateIgnoreCW (state, cw) {
state.ignoreCW = cw
},
updateIgnoreNFSW (state, nfsw) {
state.ignoreNFSW = nfsw
}
},
actions: {
@ -72,6 +80,8 @@ const App = {
commit('updateTimeFormat', conf.appearance.timeFormat)
commit('updateLanguage', conf.language.language)
commit('addFont', conf.appearance.font)
commit('updateIgnoreCW', conf.general.timeline.cw)
commit('updateIgnoreNFSW', conf.general.timeline.nfsw)
resolve(conf)
})
})