mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix UserCard_CoinAnimation to properly use the store, have 100% coverage and other minor fixes & simplifications
This commit is contained in:
parent
5a417cd2a8
commit
ce826deb1d
@ -32,6 +32,9 @@ export const mutations = {
|
|||||||
community: (state, community) => {
|
community: (state, community) => {
|
||||||
state.community = community
|
state.community = community
|
||||||
},
|
},
|
||||||
|
coinanimation: (state, coinanimation) => {
|
||||||
|
state.coinanimation = coinanimation
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
@ -42,6 +45,7 @@ export const actions = {
|
|||||||
commit('firstName', data.firstName)
|
commit('firstName', data.firstName)
|
||||||
commit('lastName', data.lastName)
|
commit('lastName', data.lastName)
|
||||||
commit('description', data.description)
|
commit('description', data.description)
|
||||||
|
commit('coinanimation', data.coinanimation)
|
||||||
commit('newsletterState', data.klickTipp.newsletterState)
|
commit('newsletterState', data.klickTipp.newsletterState)
|
||||||
},
|
},
|
||||||
logout: ({ commit, state }) => {
|
logout: ({ commit, state }) => {
|
||||||
@ -51,6 +55,7 @@ export const actions = {
|
|||||||
commit('firstName', '')
|
commit('firstName', '')
|
||||||
commit('lastName', '')
|
commit('lastName', '')
|
||||||
commit('description', '')
|
commit('description', '')
|
||||||
|
commit('coinanimation', true)
|
||||||
commit('newsletterState', null)
|
commit('newsletterState', null)
|
||||||
localStorage.clear()
|
localStorage.clear()
|
||||||
},
|
},
|
||||||
|
|||||||
@ -8,6 +8,7 @@ const {
|
|||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
description,
|
description,
|
||||||
|
coinanimation,
|
||||||
newsletterState,
|
newsletterState,
|
||||||
} = mutations
|
} = mutations
|
||||||
const { login, logout } = actions
|
const { login, logout } = actions
|
||||||
@ -70,6 +71,14 @@ describe('Vuex store', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('coinanimation', () => {
|
||||||
|
it('sets the state of coinanimation', () => {
|
||||||
|
const state = { coinanimation: true }
|
||||||
|
coinanimation(state, false)
|
||||||
|
expect(state.coinanimation).toEqual(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('newsletterState', () => {
|
describe('newsletterState', () => {
|
||||||
it('sets the state of newsletterState', () => {
|
it('sets the state of newsletterState', () => {
|
||||||
const state = { newsletterState: null }
|
const state = { newsletterState: null }
|
||||||
@ -90,14 +99,15 @@ describe('Vuex store', () => {
|
|||||||
firstName: 'Peter',
|
firstName: 'Peter',
|
||||||
lastName: 'Lustig',
|
lastName: 'Lustig',
|
||||||
description: 'Nickelbrille',
|
description: 'Nickelbrille',
|
||||||
|
coinanimation: false,
|
||||||
klickTipp: {
|
klickTipp: {
|
||||||
newsletterState: true,
|
newsletterState: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
it('calls seven commits', () => {
|
it('calls eight commits', () => {
|
||||||
login({ commit, state }, commitedData)
|
login({ commit, state }, commitedData)
|
||||||
expect(commit).toHaveBeenCalledTimes(7)
|
expect(commit).toHaveBeenCalledTimes(8)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits email', () => {
|
it('commits email', () => {
|
||||||
@ -130,9 +140,14 @@ describe('Vuex store', () => {
|
|||||||
expect(commit).toHaveBeenNthCalledWith(6, 'description', 'Nickelbrille')
|
expect(commit).toHaveBeenNthCalledWith(6, 'description', 'Nickelbrille')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('commits coinanimation', () => {
|
||||||
|
login({ commit, state }, commitedData)
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(7, 'coinanimation', false)
|
||||||
|
})
|
||||||
|
|
||||||
it('commits newsletterState', () => {
|
it('commits newsletterState', () => {
|
||||||
login({ commit, state }, commitedData)
|
login({ commit, state }, commitedData)
|
||||||
expect(commit).toHaveBeenNthCalledWith(7, 'newsletterState', true)
|
expect(commit).toHaveBeenNthCalledWith(8, 'newsletterState', true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -142,7 +157,7 @@ describe('Vuex store', () => {
|
|||||||
|
|
||||||
it('calls six commits', () => {
|
it('calls six commits', () => {
|
||||||
logout({ commit, state })
|
logout({ commit, state })
|
||||||
expect(commit).toHaveBeenCalledTimes(7)
|
expect(commit).toHaveBeenCalledTimes(8)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits token', () => {
|
it('commits token', () => {
|
||||||
@ -175,9 +190,14 @@ describe('Vuex store', () => {
|
|||||||
expect(commit).toHaveBeenNthCalledWith(6, 'description', '')
|
expect(commit).toHaveBeenNthCalledWith(6, 'description', '')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('commits coinanimation', () => {
|
||||||
|
logout({ commit, state })
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(7, 'coinanimation', true)
|
||||||
|
})
|
||||||
|
|
||||||
it('commits newsletterState', () => {
|
it('commits newsletterState', () => {
|
||||||
logout({ commit, state })
|
logout({ commit, state })
|
||||||
expect(commit).toHaveBeenNthCalledWith(7, 'newsletterState', null)
|
expect(commit).toHaveBeenNthCalledWith(8, 'newsletterState', null)
|
||||||
})
|
})
|
||||||
|
|
||||||
// how to get this working?
|
// how to get this working?
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import UserCardCoinAnimation from './UserCard_CoinAnimation'
|
import UserCardCoinAnimation from './UserCard_CoinAnimation'
|
||||||
|
import { updateUserInfos } from '../../../graphql/mutations'
|
||||||
|
|
||||||
const localVue = global.localVue
|
const localVue = global.localVue
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ describe('UserCard_CoinAnimation', () => {
|
|||||||
$store: {
|
$store: {
|
||||||
state: {
|
state: {
|
||||||
language: 'de',
|
language: 'de',
|
||||||
|
coinanimation: true,
|
||||||
},
|
},
|
||||||
commit: storeCommitMock,
|
commit: storeCommitMock,
|
||||||
},
|
},
|
||||||
@ -25,7 +27,7 @@ describe('UserCard_CoinAnimation', () => {
|
|||||||
error: toastErrorMock,
|
error: toastErrorMock,
|
||||||
},
|
},
|
||||||
$apollo: {
|
$apollo: {
|
||||||
query: mockAPIcall,
|
mutate: mockAPIcall,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,5 +47,84 @@ describe('UserCard_CoinAnimation', () => {
|
|||||||
it('has an edit BFormCheckbox switch', () => {
|
it('has an edit BFormCheckbox switch', () => {
|
||||||
expect(wrapper.find('.Test-BFormCheckbox').exists()).toBeTruthy()
|
expect(wrapper.find('.Test-BFormCheckbox').exists()).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('enable with success', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await wrapper.setData({ CoinAnimationStatus: false })
|
||||||
|
mockAPIcall.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
updateUserInfos: {
|
||||||
|
validValues: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await wrapper.find('input').trigger('change')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls the updateUserInfos mutation', () => {
|
||||||
|
expect(mockAPIcall).toBeCalledWith({
|
||||||
|
mutation: updateUserInfos,
|
||||||
|
variables: {
|
||||||
|
coinanimation: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates the store', () => {
|
||||||
|
expect(storeCommitMock).toBeCalledWith('coinanimation', false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('toasts a success message', () => {
|
||||||
|
expect(toastSuccessMock).toBeCalledWith('settings.coinanimation.False')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('disable with success', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await wrapper.setData({ CoinAnimationStatus: true })
|
||||||
|
mockAPIcall.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
updateUserInfos: {
|
||||||
|
validValues: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
wrapper.find('input').trigger('change')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls the subscribe mutation', () => {
|
||||||
|
expect(mockAPIcall).toBeCalledWith({
|
||||||
|
mutation: updateUserInfos,
|
||||||
|
variables: {
|
||||||
|
coinanimation: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates the store', () => {
|
||||||
|
expect(storeCommitMock).toBeCalledWith('coinanimation', true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('toasts a success message', () => {
|
||||||
|
expect(toastSuccessMock).toBeCalledWith('settings.coinanimation.True')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('disable with server error', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockAPIcall.mockRejectedValue({
|
||||||
|
message: 'Ouch',
|
||||||
|
})
|
||||||
|
wrapper.find('input').trigger('change')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('resets the CoinAnimationStatus', () => {
|
||||||
|
expect(wrapper.vm.CoinAnimationStatus).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('toasts an error message', () => {
|
||||||
|
expect(toastErrorMock).toBeCalledWith('Ouch')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -36,12 +36,9 @@ export default {
|
|||||||
name: 'FormUserCoinAnimation',
|
name: 'FormUserCoinAnimation',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
CoinAnimationStatus: true,
|
CoinAnimationStatus: this.$store.state.coinanimation,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
this.CoinAnimationStatus = this.$store.state.coinanimation /* existiert noch nicht im store */
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
async onSubmit() {
|
async onSubmit() {
|
||||||
this.$apollo
|
this.$apollo
|
||||||
@ -52,7 +49,7 @@ export default {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$store.state.coinanimation = this.CoinAnimationStatus
|
this.$store.commit('coinanimation', this.CoinAnimationStatus)
|
||||||
this.$toasted.success(
|
this.$toasted.success(
|
||||||
this.CoinAnimationStatus
|
this.CoinAnimationStatus
|
||||||
? this.$t('settings.coinanimation.True')
|
? this.$t('settings.coinanimation.True')
|
||||||
@ -60,6 +57,7 @@ export default {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
this.CoinAnimationStatus = this.$store.state.coinanimation
|
||||||
this.$toasted.error(error.message)
|
this.$toasted.error(error.message)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user