From fdc1c0bf8858b27261708f63c9fbec6300e00102 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 24 Nov 2021 11:16:36 +0100 Subject: [PATCH] more tests for CreationFormular. Fix update for properties --- admin/src/components/CreationFormular.spec.js | 101 +++++++++++++++++- admin/src/components/CreationFormular.vue | 13 ++- admin/src/components/UserTable.vue | 6 ++ 3 files changed, 114 insertions(+), 6 deletions(-) diff --git a/admin/src/components/CreationFormular.spec.js b/admin/src/components/CreationFormular.spec.js index f218cf8e2..fcdf97cfa 100644 --- a/admin/src/components/CreationFormular.spec.js +++ b/admin/src/components/CreationFormular.spec.js @@ -19,7 +19,7 @@ const mocks = { const propsData = { type: '', item: {}, - creation: {}, + creation: [], itemsMassCreation: {}, } @@ -38,5 +38,104 @@ describe('CreationFormular', () => { it('has a DIV element with the class.component-creation-formular', () => { expect(wrapper.find('.component-creation-formular').exists()).toBeTruthy() }) + + describe('radio buttons to selcet month', () => { + it('has three radio buttons', () => { + expect(wrapper.findAll('input[type="radio"]').length).toBe(3) + }) + + describe('with mass creation', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'massCreation' }) + }) + + 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', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ rangeMin: 180 }) + }) + + describe('first radio button', () => { + beforeEach(async () => { + await wrapper.findAll('input[type="radio"]').at(0).setChecked() + }) + + it('sets rangeMin to 0', () => { + expect(wrapper.vm.rangeMin).toBe(0) + }) + + it('sets rangeMax to 200', () => { + expect(wrapper.vm.rangeMax).toBe(200) + }) + }) + + describe('second radio button', () => { + beforeEach(async () => { + await wrapper.findAll('input[type="radio"]').at(1).setChecked() + }) + + it('sets rangeMin to 0', () => { + expect(wrapper.vm.rangeMin).toBe(0) + }) + + it('sets rangeMax to 400', () => { + expect(wrapper.vm.rangeMax).toBe(400) + }) + }) + + describe('third radio button', () => { + beforeEach(async () => { + await wrapper.findAll('input[type="radio"]').at(2).setChecked() + }) + + it('sets rangeMin to 0', () => { + expect(wrapper.vm.rangeMin).toBe(0) + }) + + it('sets rangeMax to 400', () => { + expect(wrapper.vm.rangeMax).toBe(600) + }) + }) + }) + }) }) }) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 9334f5d00..d6b637152 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -146,7 +146,7 @@ export default { required: false, }, creation: { - type: Object, + type: Array, required: true, }, itemsMassCreation: { @@ -198,9 +198,10 @@ export default { this.text = this.creationUserData.text break case 'range': - this.value = this.creationUserData.creation_gdd + this.value = this.creationUserData.creationGdd break default: + // TODO: Toast alert("I don't know such values") } }, @@ -262,9 +263,11 @@ export default { // hinweis das eine ein einzelne Schöpfung abgesendet wird an (email) alert('UPDATE EINZEL SCHÖPFUNG ABSENDEN FÜR >> ') // umschreiben, update eine bestehende Schöpfung eine - this.creationUserData.datum = this.radioSelected.long - this.creationUserData.creation_gdd = this.value - this.creationUserData.text = this.text + this.$emit('update-creation-data', { + datum: this.radioSelected.long, + creationGdd: this.value, + text: this.text, + }) } else { // hinweis das eine ein einzelne Schöpfung abgesendet wird an (email) alert('EINZEL SCHÖPFUNG ABSENDEN FÜR >> ' + this.item.firstName + '') diff --git a/admin/src/components/UserTable.vue b/admin/src/components/UserTable.vue index 92ee0cba0..d382af138 100644 --- a/admin/src/components/UserTable.vue +++ b/admin/src/components/UserTable.vue @@ -67,6 +67,7 @@ :creation="row.item.creation" :item="row.item" :creationUserData="creationData" + @update-creation-data="updateCreationData" /> @@ -226,6 +227,11 @@ export default { } row.toggleDetails() }, + updateCreationData(data) { + this.creationData = { + ...data, + } + }, }, }