test bvModal, fix duplicate Id warning

This commit is contained in:
Moriz Wahl 2022-03-17 13:52:49 +01:00
parent 97590373cb
commit 36ea3bf170
3 changed files with 108 additions and 31 deletions

View File

@ -78,39 +78,70 @@ describe('TransactionLink', () => {
})
})
describe('deleteLink', () => {
beforeEach(async () => {
describe('delete link', () => {
let spy
beforeEach(() => {
jest.clearAllMocks()
mockAPIcall.mockResolvedValue()
await wrapper.findAll('button').at(1).trigger('click')
})
it('test Modal if confirm true', () => {
const spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve('some value'))
wrapper.vm.deleteLink()
expect(spy).toHaveBeenCalled()
describe('with success', () => {
beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve('some value'))
mockAPIcall.mockResolvedValue()
await wrapper.findAll('button').at(1).trigger('click')
})
it('test Modal if confirm true', () => {
expect(spy).toBeCalled()
})
it('calls the API', () => {
expect(mockAPIcall).toBeCalledWith(
expect.objectContaining({
mutation: deleteTransactionLink,
variables: {
id: 12,
},
}),
)
})
it('toasts a success message', () => {
expect(toastSuccessSpy).toBeCalledWith('gdd_per_link.deleted')
})
it('emits reset transaction link list', () => {
expect(wrapper.emitted('reset-transaction-link-list')).toBeTruthy()
})
})
it('calls the API', () => {
expect.objectContaining({
mutation: deleteTransactionLink,
variables: {
id: 12,
},
describe('with error', () => {
beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve('some value'))
mockAPIcall.mockRejectedValue({ message: 'Something went wrong :(' })
await wrapper.findAll('button').at(1).trigger('click')
})
it('toasts an error message', () => {
expect(toastErrorSpy).toBeCalledWith('Something went wrong :(')
})
})
describe('cancel delete', () => {
beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve(false))
mockAPIcall.mockResolvedValue()
await wrapper.findAll('button').at(1).trigger('click')
})
it('does not call the API', () => {
expect(mockAPIcall).not.toBeCalled()
})
})
})
// describe('delete with error', () => {
// beforeEach(async () => {
// mockAPIcall.mockRejectedValue({ message: 'Oh no!' })
// await wrapper.findAll('button').at(1).trigger('click')
// })
// it('toasts an error message', () => {
// expect(toastErrorSpy).toBeCalledWith('Oh no!')
// })
// })
})
})

View File

@ -82,7 +82,7 @@ export default {
id: this.id,
},
})
.then((result) => {
.then(() => {
this.toastSuccess(this.$t('gdd_per_link.deleted'))
this.$emit('reset-transaction-link-list')
})

View File

@ -13,7 +13,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
code: 'ce28664b5308c17f931c0367',
createdAt: '2022-03-16T14:22:40.000Z',
holdAvailableAmount: '5.13109484759482747111',
id: 12,
id: 86,
memo: 'asdasdaadsdd asd asdadss',
redeemedAt: null,
validUntil: '2022-03-30T14:22:40.000Z',
@ -23,7 +23,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
code: 'ce28664b5308c17f931c0367',
createdAt: '2022-03-16T14:22:40.000Z',
holdAvailableAmount: '5.13109484759482747111',
id: 34,
id: 107,
memo: 'asdasdaadsdd asd asdadss',
redeemedAt: null,
validUntil: '2022-03-30T14:22:40.000Z',
@ -33,7 +33,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
code: 'ce28664b5308c17f931c0367',
createdAt: '2022-03-16T14:22:40.000Z',
holdAvailableAmount: '5.13109484759482747111',
id: 56,
id: 92,
memo: 'asdasdaadsdd asd asdadss',
redeemedAt: null,
validUntil: '2022-03-30T14:22:40.000Z',
@ -43,7 +43,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
code: 'ce28664b5308c17f931c0367',
createdAt: '2022-03-16T14:22:40.000Z',
holdAvailableAmount: '5.13109484759482747111',
id: 78,
id: 16,
memo: 'asdasdaadsdd asd asdadss',
redeemedAt: null,
validUntil: '2022-03-30T14:22:40.000Z',
@ -137,6 +137,52 @@ describe('TransactionLinksSummary', () => {
describe('load more transaction links', () => {
beforeEach(async () => {
jest.clearAllMocks()
apolloQueryMock.mockResolvedValue({
data: {
listTransactionLinks: [
{
amount: '76',
code: 'ce28664b5308c17f931c0367',
createdAt: '2022-03-16T14:22:40.000Z',
holdAvailableAmount: '5.13109484759482747111',
id: 87,
memo: 'asdasdaadsdd asd asdadss',
redeemedAt: null,
validUntil: '2022-03-30T14:22:40.000Z',
},
{
amount: '86',
code: 'ce28664b5308c17f931c0367',
createdAt: '2022-03-16T14:22:40.000Z',
holdAvailableAmount: '5.13109484759482747111',
id: 108,
memo: 'asdasdaadsdd asd asdadss',
redeemedAt: null,
validUntil: '2022-03-30T14:22:40.000Z',
},
{
amount: '96',
code: 'ce28664b5308c17f931c0367',
createdAt: '2022-03-16T14:22:40.000Z',
holdAvailableAmount: '5.13109484759482747111',
id: 93,
memo: 'asdasdaadsdd asd asdadss',
redeemedAt: null,
validUntil: '2022-03-30T14:22:40.000Z',
},
{
amount: '150',
code: 'ce28664b5308c17f931c0367',
createdAt: '2022-03-16T14:22:40.000Z',
holdAvailableAmount: '5.13109484759482747111',
id: 17,
memo: 'asdasdaadsdd asd asdadss',
redeemedAt: null,
validUntil: '2022-03-30T14:22:40.000Z',
},
],
},
})
await wrapper.setData({
variables: {
currentPage: 2,