fixed rollback on privacy update fail

coverage privacy.spec.js
This commit is contained in:
Ulf Gebhardt 2021-04-27 00:44:52 +02:00
parent e3340760f5
commit 52740d8fc3
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
2 changed files with 29 additions and 1 deletions

View File

@ -12,11 +12,21 @@ describe('privacy.vue', () => {
beforeEach(() => {
mocks = {
$t: jest.fn(),
$apollo: {
mutate: jest.fn()
},
$toast: {
success: jest.fn(),
error: jest.fn(),
},
}
store = new Vuex.Store({
getters: {
'auth/user': () => {
return { id: 'u343', name: 'Delete MyAccount', showShoutsPublicly: true }
return {
id: 'u343',
name: 'MyAccount',
showShoutsPublicly: true }
},
},
})
@ -38,5 +48,22 @@ describe('privacy.vue', () => {
it('renders', () => {
expect(wrapper.is('.base-card')).toBe(true)
})
it('clicking on submit changes shoutsAllowed to false', async () => {
wrapper.find('#allow-shouts').trigger('click')
await wrapper.vm.$nextTick()
wrapper.find('.base-button').trigger('click')
expect(wrapper.vm.shoutsAllowed).toBe(false)
})
it('clicking on submit with a server error shows a toast and shoutsAllowed is still true', async () => {
mocks.$apollo.mutate = jest.fn().mockRejectedValue({ message: 'Ouch!' })
wrapper.find('#allow-shouts').trigger('click')
await wrapper.vm.$nextTick()
await wrapper.find('.base-button').trigger('click')
await wrapper.vm.$nextTick()
expect(mocks.$toast.error).toHaveBeenCalledWith('Ouch!')
expect(wrapper.vm.shoutsAllowed).toBe(true)
})
})
})

View File

@ -52,6 +52,7 @@ export default {
},
})
} catch (error) {
this.shoutsAllowed = !this.shoutsAllowed
this.$toast.error(error.message)
}
},