mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Tests on GdtAmount
This commit is contained in:
parent
74c575882a
commit
01f054c181
@ -1,19 +1,30 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import GdtAmount from './GdtAmount'
|
||||
import { updateUserInfos } from '@/graphql/mutations'
|
||||
import flushPromises from 'flush-promises'
|
||||
|
||||
import { toastErrorSpy, toastSuccessSpy } from '@test/testSetup'
|
||||
|
||||
const localVue = global.localVue
|
||||
|
||||
const mockAPICall = jest.fn()
|
||||
const storeCommitMock = jest.fn()
|
||||
|
||||
const state = {
|
||||
language: 'en',
|
||||
hideAmountGDT: false,
|
||||
}
|
||||
|
||||
const mocks = {
|
||||
$store: {
|
||||
state,
|
||||
commit: storeCommitMock,
|
||||
},
|
||||
$i18n: {
|
||||
locale: 'en',
|
||||
},
|
||||
$apollo: {
|
||||
mutate: mockAPICall,
|
||||
},
|
||||
$t: jest.fn((t) => t),
|
||||
$n: jest.fn((n) => n),
|
||||
}
|
||||
@ -39,5 +50,88 @@ describe('GdtAmount', () => {
|
||||
it('renders the component gdt-amount', () => {
|
||||
expect(wrapper.find('div.gdt-amount').exists()).toBe(true)
|
||||
})
|
||||
|
||||
describe('API throws exception', () => {
|
||||
beforeEach(async () => {
|
||||
mockAPICall.mockRejectedValue({
|
||||
message: 'Ouch',
|
||||
})
|
||||
jest.clearAllMocks()
|
||||
await wrapper.find('div.border-left svg').trigger('click')
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('toasts an error message', () => {
|
||||
expect(toastErrorSpy).toBeCalledWith('Ouch')
|
||||
})
|
||||
})
|
||||
|
||||
describe('API call successful', () => {
|
||||
beforeEach(async () => {
|
||||
mockAPICall.mockResolvedValue({
|
||||
data: {
|
||||
updateUserInfos: {
|
||||
validValues: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
jest.clearAllMocks()
|
||||
await wrapper.find('div.border-left svg').trigger('click')
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('calls the API', () => {
|
||||
expect(mockAPICall).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
mutation: updateUserInfos,
|
||||
variables: {
|
||||
hideAmountGDT: true,
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('commits hideAmountGDT to store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('hideAmountGDT', true)
|
||||
})
|
||||
|
||||
it('toasts a success message', () => {
|
||||
expect(toastSuccessSpy).toBeCalledWith('settings.showAmountGDT')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe.skip('second call to API', () => {
|
||||
beforeEach(async () => {
|
||||
mockAPICall.mockResolvedValue({
|
||||
data: {
|
||||
updateUserInfos: {
|
||||
validValues: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
jest.clearAllMocks()
|
||||
await wrapper.find('div.border-left svg').trigger('click')
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('calls the API', () => {
|
||||
expect(mockAPICall).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
mutation: updateUserInfos,
|
||||
variables: {
|
||||
hideAmountGDT: true,
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('commits hideAmountGDT to store', () => {
|
||||
expect(storeCommitMock).toBeCalledWith('hideAmountGDT', false)
|
||||
})
|
||||
|
||||
it('toasts a success message', () => {
|
||||
expect(toastSuccessSpy).toBeCalledWith('settings.hideAmountGDT')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user