refs #850 Fix test for typescript in Preferences

This commit is contained in:
AkiraFukushima 2019-04-06 22:08:29 +09:00
parent ca6fc13975
commit 9456374516
11 changed files with 93 additions and 56 deletions

View File

@ -29,6 +29,8 @@ module.exports = {
{
'argsIgnorePattern': '^_'
}
]
],
'camelcase': 'off',
'@typescript-eslint/camelcase': 'off'
}
}

View File

@ -1,9 +1,24 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import Account from '@/store/Preferences/Account'
import Account, { AccountState } from '@/store/Preferences/Account'
import AccountType from '~/src/types/account'
const state = () => {
const account: AccountType = {
_id: 'sample',
baseURL: 'http://example.com',
domain: 'example.com',
clientId: 'hoge',
clientSecret: 'hogehoge',
accessToken: null,
refreshToken: null,
username: null,
accountId: null,
avatar: null,
order: 1
}
const state = (): AccountState => {
return {
accounts: [],
accountLoading: false
@ -35,7 +50,7 @@ describe('Account', () => {
describe('loadAccounts', () => {
it('error', async () => {
ipcMain.once('list-accounts', (event, _) => {
ipcMain.once('list-accounts', (event: any, _) => {
event.sender.send('error-list-accounts', new Error())
})
@ -45,86 +60,86 @@ describe('Account', () => {
})
})
it('success', async () => {
ipcMain.once('list-accounts', (event, _) => {
event.sender.send('response-list-accounts', ['accounts'])
ipcMain.once('list-accounts', (event: any, _) => {
event.sender.send('response-list-accounts', [account])
})
await store.dispatch('Account/loadAccounts')
expect(store.state.Account.accounts).toEqual(['accounts'])
expect(store.state.Account.accounts).toEqual([account])
})
})
describe('removeAccount', () => {
it('error', async () => {
ipcMain.once('remove-account', (event, _) => {
ipcMain.once('remove-account', (event: any, _) => {
event.sender.send('error-remove-account', new Error())
})
await store.dispatch('Account/removeAccount', 'account')
await store.dispatch('Account/removeAccount', account)
.catch((err: Error) => {
expect(err instanceof Error).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('remove-account', (event, _) => {
event.sender.send('response-remove-account', 1)
ipcMain.once('remove-account', (event: any, _) => {
event.sender.send('response-remove-account')
})
const res = await store.dispatch('Account/removeAccount', 'account')
const res = await store.dispatch('Account/removeAccount', account)
expect(res).toEqual(undefined)
})
})
describe('forwardAccount', () => {
it('error', async () => {
ipcMain.once('forward-account', (event, _) => {
ipcMain.once('forward-account', (event: any, _) => {
event.sender.send('error-forward-account', new Error())
})
await store.dispatch('Account/forwardAccount', 'account')
await store.dispatch('Account/forwardAccount', account)
.catch((err: Error) => {
expect(err instanceof Error).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('forward-account', (event, _) => {
event.sender.send('response-forward-account', 1)
ipcMain.once('forward-account', (event: any, _) => {
event.sender.send('response-forward-account')
})
const res = await store.dispatch('Account/forwardAccount', 'account')
const res = await store.dispatch('Account/forwardAccount', account)
expect(res).toEqual(undefined)
})
})
describe('backwardAccount', () => {
it('error', async () => {
ipcMain.once('backward-account', (event, _) => {
ipcMain.once('backward-account', (event: any, _) => {
event.sender.send('error-backward-account', new Error())
})
await store.dispatch('Account/backwardAccount', 'account')
await store.dispatch('Account/backwardAccount', account)
.catch((err: Error) => {
expect(err instanceof Error).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('backward-account', (event, _) => {
event.sender.send('response-backward-account', 1)
ipcMain.once('backward-account', (event: any, _) => {
event.sender.send('response-backward-account')
})
const res = await store.dispatch('Account/backwardAccount', 'account')
const res = await store.dispatch('Account/backwardAccount', account)
expect(res).toEqual(undefined)
})
})
describe('removeAllAccounts', () => {
it('error', async () => {
ipcMain.once('remove-all-accounts', (event, _) => {
ipcMain.once('remove-all-accounts', (event: any, _) => {
event.sender.send('error-remove-all-accounts', new Error())
})
await store.dispatch('Account/removeAllAccounts', 'account')
await store.dispatch('Account/removeAllAccounts', account)
.catch((err: Error) => {
expect(err instanceof Error).toEqual(true)
})
})
it('success', async () => {
ipcMain.once('remove-all-accounts', (event, _) => {
event.sender.send('response-remove-all-accounts', 1)
ipcMain.once('remove-all-accounts', (event: any, _) => {
event.sender.send('response-remove-all-accounts')
})
const res = await store.dispatch('Account/removeAllAccounts', 'account')
const res = await store.dispatch('Account/removeAllAccounts', account)
expect(res).toEqual(undefined)
})
})

View File

@ -5,10 +5,10 @@ import DisplayStyle from '~/src/constants/displayStyle'
import TimeFormat from '~/src/constants/timeFormat'
import { LightTheme, DarkTheme } from '~/src/renderer/utils/theme'
import DefaultFonts from '@/utils/fonts'
import Appearance from '@/store/Preferences/Appearance'
import Appearance, { AppearanceState } from '@/store/Preferences/Appearance'
import { ipcMain } from '~/spec/mock/electron'
const state = () => {
const state = (): AppearanceState => {
return {
appearance: {
theme: Theme.Light.key,
@ -51,14 +51,14 @@ describe('Preferences/Appearance', () => {
App: App
}
})
ipcMain.once('update-preferences', (event, config) => {
ipcMain.once('update-preferences', (event: any, config: any) => {
event.sender.send('response-update-preferences', config)
})
})
describe('load', () => {
it('loadAppearance', async () => {
ipcMain.once('get-preferences', (event, _) => {
ipcMain.once('get-preferences', (event: any, _) => {
event.sender.send('response-get-preferences', {
appearance: {
theme: Theme.Dark.key,

View File

@ -1,9 +1,9 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import General from '@/store/Preferences/General'
import General, { GeneralState } from '@/store/Preferences/General'
const state = () => {
const state = (): GeneralState => {
return {
general: {
sound: {

View File

@ -1,10 +1,10 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import Language from '@/store/Preferences/Language'
import Language, { LanguageState } from '@/store/Preferences/Language'
import DefaultLanguage from '~/src/constants/language'
const state = () => {
const state = (): LanguageState => {
return {
language: {
language: DefaultLanguage.en.key

View File

@ -1,9 +1,9 @@
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import Notification from '@/store/Preferences/Notification'
import Notification, { NotificationState } from '@/store/Preferences/Notification'
const state = () => {
const state = (): NotificationState => {
return {
notification: {
notify: {

View File

@ -1,8 +1,23 @@
import Account from '@/store/Preferences/Account'
import Account, { AccountState, MUTATION_TYPES } from '@/store/Preferences/Account'
import AccountType from '~/src/types/account'
const account: AccountType = {
_id: 'sample',
baseURL: 'http://example.com',
domain: 'example.com',
clientId: 'hoge',
clientSecret: 'hogehoge',
accessToken: null,
refreshToken: null,
username: null,
accountId: null,
avatar: null,
order: 1
}
describe('Preferences/Account', () => {
describe('mutations', () => {
let state
let state: AccountState
beforeEach(() => {
state = {
accounts: [],
@ -11,13 +26,13 @@ describe('Preferences/Account', () => {
})
describe('updateAccounts', () => {
it('should be updated', () => {
Account.mutations.updateAccounts(state, ['account'])
expect(state.accounts).toEqual(['account'])
Account.mutations![MUTATION_TYPES.UPDATE_ACCOUNTS](state, [account])
expect(state.accounts).toEqual([account])
})
})
describe('updateAccountLoading', () => {
it('should be update', () => {
Account.mutations.updateAccountLoading(state, true)
Account.mutations![MUTATION_TYPES.UPDATE_ACCOUNT_LOADING](state, true)
expect(state.accountLoading).toEqual(true)
})
})

View File

@ -3,10 +3,10 @@ import DisplayStyle from '~/src/constants/displayStyle'
import TimeFormat from '~/src/constants/timeFormat'
import { LightTheme } from '~/src/renderer/utils/theme'
import DefaultFonts from '@/utils/fonts'
import Appearance from '@/store/Preferences/Appearance'
import Appearance, { AppearanceState, MUTATION_TYPES } from '@/store/Preferences/Appearance'
describe('Preferences/Appearance', () => {
let state
let state: AppearanceState
beforeEach(() => {
state = {
appearance: {
@ -23,7 +23,7 @@ describe('Preferences/Appearance', () => {
describe('mutations', () => {
describe('updateAppearance', () => {
it('should be changed', () => {
Appearance.mutations.updateAppearance(state, {
Appearance.mutations![MUTATION_TYPES.UPDATE_APPEARANCE](state, {
theme: Theme.Dark.key
})
expect(state.appearance.theme).toEqual(Theme.Dark.key)
@ -31,7 +31,7 @@ describe('Preferences/Appearance', () => {
})
describe('updateFonts', () => {
it('should be changed', () => {
Appearance.mutations.updateFonts(state, ['font'])
Appearance.mutations![MUTATION_TYPES.UPDATE_FONTS](state, ['font'])
expect(state.fonts).toEqual(['font'])
})
})

View File

@ -1,13 +1,18 @@
import General from '@/store/Preferences/General'
import General, { GeneralState, MUTATION_TYPES } from '@/store/Preferences/General'
describe('Preferences/General', () => {
let state
let state: GeneralState
beforeEach(() => {
state = {
general: {
sound: {
fav_rb: true,
toot: true
},
timeline: {
cw: false,
nfsw: false,
hideAllAttachments: false
}
},
loading: false
@ -16,7 +21,7 @@ describe('Preferences/General', () => {
describe('mutations', () => {
it('updateGeneral', () => {
General.mutations.updateGeneral(state, {
General.mutations![MUTATION_TYPES.UPDATE_GENERAL](state, {
sound: {
fav_rb: false,
toot: false

View File

@ -1,8 +1,8 @@
import Language from '@/store/Preferences/Language'
import Language, { LanguageState, MUTATION_TYPES } from '@/store/Preferences/Language'
import DefaultLanguage from '~/src/constants/language'
describe('Preferences/Language', () => {
let state
let state: LanguageState
beforeEach(() => {
state = {
language: {
@ -13,7 +13,7 @@ describe('Preferences/Language', () => {
describe('mutations', () => {
describe('updateLanguage', () => {
it('should be updated', () => {
Language.mutations.updateLanguage(state, {
Language.mutations![MUTATION_TYPES.UPDATE_LANGUAGE](state, {
language: DefaultLanguage.ja.key
})
expect(state.language.language).toEqual(DefaultLanguage.ja.key)
@ -21,7 +21,7 @@ describe('Preferences/Language', () => {
})
describe('changeLanguage', () => {
it('should be changed', () => {
Language.mutations.changeLanguage(state, DefaultLanguage.ja.key)
Language.mutations![MUTATION_TYPES.CHANGE_LANGUAGE](state, DefaultLanguage.ja.key)
expect(state.language.language).toEqual(DefaultLanguage.ja.key)
})
})

View File

@ -1,7 +1,7 @@
import Notification from '@/store/Preferences/Notification'
import Notification, { NotificationState, MUTATION_TYPES } from '@/store/Preferences/Notification'
describe('Preferences/Notification', () => {
let state
let state: NotificationState
beforeEach(() => {
state = {
notification: {
@ -16,7 +16,7 @@ describe('Preferences/Notification', () => {
})
describe('mutations', () => {
it('updateNotification', () => {
Notification.mutations.updateNotification(state, {
Notification.mutations![MUTATION_TYPES.UPDATE_NOTIFICATION](state, {
notify: {
reply: false,
reblog: false,