mirror of
https://github.com/IT4Change/gradido.git
synced 2026-04-06 01:25:28 +00:00
test complete creation formular, coverage to 81%
This commit is contained in:
parent
ae92cbb781
commit
14bd0cb9eb
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -470,7 +470,7 @@ jobs:
|
|||||||
report_name: Coverage Admin Interface
|
report_name: Coverage Admin Interface
|
||||||
type: lcov
|
type: lcov
|
||||||
result_path: ./coverage/lcov.info
|
result_path: ./coverage/lcov.info
|
||||||
min_coverage: 80
|
min_coverage: 81
|
||||||
token: ${{ github.token }}
|
token: ${{ github.token }}
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|||||||
@ -15,8 +15,11 @@ const toastedErrorMock = jest.fn()
|
|||||||
const toastedSuccessMock = jest.fn()
|
const toastedSuccessMock = jest.fn()
|
||||||
|
|
||||||
const mocks = {
|
const mocks = {
|
||||||
$t: jest.fn((t) => t),
|
$t: jest.fn((t, options) => (options ? [t, options] : t)),
|
||||||
$d: jest.fn((d) => d),
|
$d: jest.fn((d) => {
|
||||||
|
const date = new Date(d)
|
||||||
|
return date.toISOString().split('T')[0]
|
||||||
|
}),
|
||||||
$apollo: {
|
$apollo: {
|
||||||
mutate: apolloMutateMock,
|
mutate: apolloMutateMock,
|
||||||
},
|
},
|
||||||
@ -41,6 +44,12 @@ const propsData = {
|
|||||||
itemsMassCreation: {},
|
itemsMassCreation: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const now = new Date(Date.now())
|
||||||
|
const getCreationDate = (sub) => {
|
||||||
|
const date = sub === 0 ? now : new Date(now.getFullYear(), now.getMonth() - sub, 1, 0)
|
||||||
|
return date.toISOString().split('T')[0]
|
||||||
|
}
|
||||||
|
|
||||||
describe('CreationFormular', () => {
|
describe('CreationFormular', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
|
|
||||||
@ -57,59 +66,32 @@ describe('CreationFormular', () => {
|
|||||||
expect(wrapper.find('.component-creation-formular').exists()).toBeTruthy()
|
expect(wrapper.find('.component-creation-formular').exists()).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('text and value form props', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
wrapper = mount(CreationFormular, {
|
||||||
|
localVue,
|
||||||
|
mocks,
|
||||||
|
propsData: {
|
||||||
|
creationUserData: { memo: 'Memo from property', amount: 42 },
|
||||||
|
...propsData,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('has text taken from props', () => {
|
||||||
|
expect(wrapper.vm.text).toBe('Memo from property')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('has value taken from props', () => {
|
||||||
|
expect(wrapper.vm.value).toBe(42)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('radio buttons to selcet month', () => {
|
describe('radio buttons to selcet month', () => {
|
||||||
it('has three radio buttons', () => {
|
it('has three radio buttons', () => {
|
||||||
expect(wrapper.findAll('input[type="radio"]').length).toBe(3)
|
expect(wrapper.findAll('input[type="radio"]').length).toBe(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
|
||||||
describe('with mass creation', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
jest.clearAllMocks()
|
|
||||||
await wrapper.setProps({ type: 'massCreation', creation: [200, 400, 600] })
|
|
||||||
await wrapper.setData({ rangeMin: 180 })
|
|
||||||
await wrapper.setData({ text: 'Test create coins' })
|
|
||||||
await wrapper.setData({ value: 90 })
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('first radio button', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
await wrapper.findAll('input[type="radio"]').at(0).setChecked()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('emits update-radio-selected with index 0', () => {
|
|
||||||
expect(wrapper.emitted()['update-radio-selected']).toEqual([
|
|
||||||
[expect.arrayContaining([0])],
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('second radio button', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
await wrapper.findAll('input[type="radio"]').at(1).setChecked()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('emits update-radio-selected with index 1', () => {
|
|
||||||
expect(wrapper.emitted()['update-radio-selected']).toEqual([
|
|
||||||
[expect.arrayContaining([1])],
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('third radio button', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
await wrapper.findAll('input[type="radio"]').at(2).setChecked()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('emits update-radio-selected with index 2', () => {
|
|
||||||
expect(wrapper.emitted()['update-radio-selected']).toEqual([
|
|
||||||
[expect.arrayContaining([2])],
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe('with single creation', () => {
|
describe('with single creation', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
@ -119,17 +101,17 @@ describe('CreationFormular', () => {
|
|||||||
item: { email: 'benjamin@bluemchen.de' },
|
item: { email: 'benjamin@bluemchen.de' },
|
||||||
})
|
})
|
||||||
await wrapper.findAll('input[type="radio"]').at(1).setChecked()
|
await wrapper.findAll('input[type="radio"]').at(1).setChecked()
|
||||||
await wrapper.find('textarea').setValue('Test create coins')
|
|
||||||
await wrapper.find('input[type="number"]').setValue(90)
|
await wrapper.find('input[type="number"]').setValue(90)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('first radio button', () => {
|
describe('first radio button', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await wrapper.findAll('input[type="radio"]').at(0).setChecked()
|
await wrapper.findAll('input[type="radio"]').at(0).setChecked()
|
||||||
|
await wrapper.find('textarea').setValue('Test create coins')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets rangeMax to 200', () => {
|
it('sets rangeMax to 200', () => {
|
||||||
expect(wrapper.vm.rangeMax).toBe(400)
|
expect(wrapper.vm.rangeMax).toBe(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('sendForm', () => {
|
describe('sendForm', () => {
|
||||||
@ -143,7 +125,7 @@ describe('CreationFormular', () => {
|
|||||||
mutation: createPendingCreation,
|
mutation: createPendingCreation,
|
||||||
variables: {
|
variables: {
|
||||||
email: 'benjamin@bluemchen.de',
|
email: 'benjamin@bluemchen.de',
|
||||||
creationDate: 'YYYY-MM-01',
|
creationDate: getCreationDate(2),
|
||||||
amount: 90,
|
amount: 90,
|
||||||
memo: 'Test create coins',
|
memo: 'Test create coins',
|
||||||
moderator: 0,
|
moderator: 0,
|
||||||
@ -151,9 +133,30 @@ describe('CreationFormular', () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('emits update-user-data', () => {
|
||||||
|
expect(wrapper.emitted('update-user-data')).toEqual([
|
||||||
|
[{ email: 'benjamin@bluemchen.de' }, [0, 0, 0]],
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('toasts a success message', () => {
|
||||||
|
expect(toastedSuccessMock).toBeCalledWith([
|
||||||
|
'creation_form.toasted',
|
||||||
|
{ email: 'benjamin@bluemchen.de', value: '90' },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates open creations in store', () => {
|
||||||
|
expect(stateCommitMock).toBeCalledWith('openCreationsPlus', 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('resets the form data', () => {
|
||||||
|
expect(wrapper.vm.value).toBe(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('sendForm', () => {
|
describe('sendForm with server error', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
apolloMutateMock.mockRejectedValueOnce({ message: 'Ouch!' })
|
apolloMutateMock.mockRejectedValueOnce({ message: 'Ouch!' })
|
||||||
await wrapper.find('.test-submit').trigger('click')
|
await wrapper.find('.test-submit').trigger('click')
|
||||||
@ -339,9 +342,18 @@ describe('CreationFormular', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with mass creation', () => {
|
describe('mass creation with success', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
|
apolloMutateMock.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
createPendingCreations: {
|
||||||
|
success: true,
|
||||||
|
successfulCreation: ['bob@baumeister.de', 'bibi@bloxberg.de'],
|
||||||
|
failedCreation: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
await wrapper.setProps({
|
await wrapper.setProps({
|
||||||
type: 'massCreation',
|
type: 'massCreation',
|
||||||
creation: [200, 400, 600],
|
creation: [200, 400, 600],
|
||||||
@ -361,14 +373,14 @@ describe('CreationFormular', () => {
|
|||||||
pendingCreations: [
|
pendingCreations: [
|
||||||
{
|
{
|
||||||
email: 'bob@baumeister.de',
|
email: 'bob@baumeister.de',
|
||||||
creationDate: 'YYYY-MM-01',
|
creationDate: getCreationDate(1),
|
||||||
amount: 200,
|
amount: 200,
|
||||||
memo: 'Test mass create coins',
|
memo: 'Test mass create coins',
|
||||||
moderator: 0,
|
moderator: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: 'bibi@bloxberg.de',
|
email: 'bibi@bloxberg.de',
|
||||||
creationDate: 'YYYY-MM-01',
|
creationDate: getCreationDate(1),
|
||||||
amount: 200,
|
amount: 200,
|
||||||
memo: 'Test mass create coins',
|
memo: 'Test mass create coins',
|
||||||
moderator: 0,
|
moderator: 0,
|
||||||
@ -378,6 +390,73 @@ describe('CreationFormular', () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('updates open creations in store', () => {
|
||||||
|
expect(stateCommitMock).toBeCalledWith('openCreationsPlus', 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('emits remove-all-bookmark', () => {
|
||||||
|
expect(wrapper.emitted('remove-all-bookmark')).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mass creation with success but all failed', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
apolloMutateMock.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
createPendingCreations: {
|
||||||
|
success: true,
|
||||||
|
successfulCreation: [],
|
||||||
|
failedCreation: ['bob@baumeister.de', 'bibi@bloxberg.de'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await wrapper.setProps({
|
||||||
|
type: 'massCreation',
|
||||||
|
creation: [200, 400, 600],
|
||||||
|
items: [{ email: 'bob@baumeister.de' }, { email: 'bibi@bloxberg.de' }],
|
||||||
|
})
|
||||||
|
await wrapper.findAll('input[type="radio"]').at(1).setChecked()
|
||||||
|
await wrapper.find('textarea').setValue('Test mass create coins')
|
||||||
|
await wrapper.find('input[type="number"]').setValue(200)
|
||||||
|
await wrapper.find('.test-submit').trigger('click')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates open creations in store', () => {
|
||||||
|
expect(stateCommitMock).toBeCalledWith('openCreationsPlus', 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('toasts two errors', () => {
|
||||||
|
expect(toastedErrorMock).toBeCalledWith(
|
||||||
|
'Could not created PendingCreation for bob@baumeister.de',
|
||||||
|
)
|
||||||
|
expect(toastedErrorMock).toBeCalledWith(
|
||||||
|
'Could not created PendingCreation for bibi@bloxberg.de',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mass creation with error', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
apolloMutateMock.mockRejectedValue({
|
||||||
|
message: 'Oh no!',
|
||||||
|
})
|
||||||
|
await wrapper.setProps({
|
||||||
|
type: 'massCreation',
|
||||||
|
creation: [200, 400, 600],
|
||||||
|
items: [{ email: 'bob@baumeister.de' }, { email: 'bibi@bloxberg.de' }],
|
||||||
|
})
|
||||||
|
await wrapper.findAll('input[type="radio"]').at(1).setChecked()
|
||||||
|
await wrapper.find('textarea').setValue('Test mass create coins')
|
||||||
|
await wrapper.find('input[type="number"]').setValue(200)
|
||||||
|
await wrapper.find('.test-submit').trigger('click')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('toasts an error message', () => {
|
||||||
|
expect(toastedErrorMock).toBeCalledWith('Oh no!')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -138,6 +138,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateRadioSelected(name) {
|
updateRadioSelected(name) {
|
||||||
|
// do we want to reset the memo everytime the month changes?
|
||||||
this.text = this.$t('creation_form.creation_for') + ' ' + name.short + ' ' + name.year
|
this.text = this.$t('creation_form.creation_for') + ' ' + name.short + ' ' + name.year
|
||||||
if (this.type === 'singleCreation') {
|
if (this.type === 'singleCreation') {
|
||||||
this.rangeMin = 0
|
this.rangeMin = 0
|
||||||
@ -171,6 +172,7 @@ export default {
|
|||||||
)
|
)
|
||||||
if (result.data.createPendingCreations.failedCreation.length > 0) {
|
if (result.data.createPendingCreations.failedCreation.length > 0) {
|
||||||
result.data.createPendingCreations.failedCreation.forEach((failed) => {
|
result.data.createPendingCreations.failedCreation.forEach((failed) => {
|
||||||
|
// TODO: Please localize this error message
|
||||||
this.$toasted.error('Could not created PendingCreation for ' + failed)
|
this.$toasted.error('Could not created PendingCreation for ' + failed)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -201,6 +203,7 @@ export default {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
this.$store.commit('openCreationsPlus', 1)
|
this.$store.commit('openCreationsPlus', 1)
|
||||||
|
// what is this? Tests says that this.text is not reseted
|
||||||
this.$refs.creationForm.reset()
|
this.$refs.creationForm.reset()
|
||||||
this.value = 0
|
this.value = 0
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user