diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0435d0c76..88a6ba8e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -441,7 +441,7 @@ jobs: report_name: Coverage Admin Interface type: lcov result_path: ./coverage/lcov.info - min_coverage: 69 + min_coverage: 76 token: ${{ github.token }} ############################################################################## diff --git a/admin/src/pages/Creation.spec.js b/admin/src/pages/Creation.spec.js index 02c2ed4ce..f0186099e 100644 --- a/admin/src/pages/Creation.spec.js +++ b/admin/src/pages/Creation.spec.js @@ -1,5 +1,6 @@ -import { mount } from '@vue/test-utils' +import { shallowMount } from '@vue/test-utils' import Creation from './Creation.vue' +import Vue from 'vue' const localVue = global.localVue @@ -7,11 +8,19 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ data: { searchUsers: [ { + id: 1, firstName: 'Bibi', lastName: 'Bloxberg', email: 'bibi@bloxberg.de', creation: [200, 400, 600], }, + { + id: 2, + firstName: 'Benjamin', + lastName: 'Blümchen', + email: 'benjamin@bluemchen.de', + creation: [800, 600, 400], + }, ], }, }) @@ -31,10 +40,10 @@ describe('Creation', () => { let wrapper const Wrapper = () => { - return mount(Creation, { localVue, mocks }) + return shallowMount(Creation, { localVue, mocks }) } - describe('mount', () => { + describe('shallowMount', () => { beforeEach(() => { wrapper = Wrapper() }) @@ -43,6 +52,165 @@ describe('Creation', () => { expect(wrapper.find('div.creation').exists()).toBeTruthy() }) + describe('apollo returns user array', () => { + it('calls the searchUser query', () => { + expect(apolloQueryMock).toBeCalled() + }) + + it('sets the data of itemsList', () => { + expect(wrapper.vm.itemsList).toEqual([ + { + id: 1, + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + creation: [200, 400, 600], + showDetails: false, + }, + { + id: 2, + firstName: 'Benjamin', + lastName: 'Blümchen', + email: 'benjamin@bluemchen.de', + creation: [800, 600, 400], + showDetails: false, + }, + ]) + }) + }) + + describe('update iten', () => { + beforeEach(() => { + jest.clearAllMocks() + }) + + describe('push', () => { + beforeEach(() => { + wrapper.findComponent({ name: 'UserTable' }).vm.$emit( + 'update-item', + { + id: 2, + firstName: 'Benjamin', + lastName: 'Blümchen', + email: 'benjamin@bluemchen.de', + creation: [800, 600, 400], + showDetails: false, + }, + 'push', + ) + }) + + it('removes the pushed item from itemsList', () => { + expect(wrapper.vm.itemsList).toEqual([ + { + id: 1, + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + creation: [200, 400, 600], + showDetails: false, + }, + ]) + }) + + it('adds the pushed item to itemsMassCreation', () => { + expect(wrapper.vm.itemsMassCreation).toEqual([ + { + id: 2, + firstName: 'Benjamin', + lastName: 'Blümchen', + email: 'benjamin@bluemchen.de', + creation: [800, 600, 400], + showDetails: false, + }, + ]) + }) + + describe('remove', () => { + beforeEach(() => { + wrapper.findComponent({ name: 'UserTable' }).vm.$emit( + 'update-item', + { + id: 2, + firstName: 'Benjamin', + lastName: 'Blümchen', + email: 'benjamin@bluemchen.de', + creation: [800, 600, 400], + showDetails: false, + }, + 'remove', + ) + }) + + it('removes the item from itemsMassCreation', () => { + expect(wrapper.vm.itemsMassCreation).toEqual([]) + }) + + it('adds the item to itemsList', () => { + expect(wrapper.vm.itemsList).toEqual([ + { + id: 1, + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + creation: [200, 400, 600], + showDetails: false, + }, + { + id: 2, + firstName: 'Benjamin', + lastName: 'Blümchen', + email: 'benjamin@bluemchen.de', + creation: [800, 600, 400], + showDetails: false, + }, + ]) + }) + }) + }) + + describe('error', () => { + const consoleErrorMock = jest.fn() + + beforeEach(() => { + Vue.config.warnHandler = (w) => {} + // eslint-disable-next-line no-console + console.error = consoleErrorMock + wrapper.findComponent({ name: 'UserTable' }).vm.$emit('update-item', {}, 'no-rule') + }) + + it('throws an error', () => { + expect(consoleErrorMock).toBeCalledWith(expect.objectContaining({ message: 'no-rule' })) + }) + }) + }) + + describe('remove all bookmarks', () => { + beforeEach(async () => { + await wrapper.findComponent({ name: 'UserTable' }).vm.$emit( + 'update-item', + { + id: 2, + firstName: 'Benjamin', + lastName: 'Blümchen', + email: 'benjamin@bluemchen.de', + creation: [800, 600, 400], + showDetails: false, + }, + 'push', + ) + wrapper.findComponent({ name: 'CreationFormular' }).vm.$emit('remove-all-bookmark') + }) + + it('removes all items from itemsMassCreation', () => { + expect(wrapper.vm.itemsMassCreation).toEqual([]) + }) + + it('adds all items to itemsList', () => { + expect(wrapper.vm.itemsList).toHaveLength(2) + }) + }) + describe('apollo returns error', () => { beforeEach(() => { apolloQueryMock.mockRejectedValue({ diff --git a/admin/src/pages/Creation.vue b/admin/src/pages/Creation.vue index 21d4aa11a..820f6382e 100644 --- a/admin/src/pages/Creation.vue +++ b/admin/src/pages/Creation.vue @@ -125,20 +125,9 @@ export default { throw new Error(event) } }, - - // updateRadioSelected(obj) { - // this.radioSelectedMass = obj[0] - // }, - removeAllBookmark() { - alert('remove all bookmarks') - const index = 0 - let i = 0 - - for (i; i < this.itemsMassCreation.length; i++) { - this.itemsList.push(this.itemsMassCreation[i]) - } - this.itemsMassCreation.splice(index, this.itemsMassCreation.length) + this.itemsMassCreation.forEach((item) => this.itemsList.push(item)) + this.itemsMassCreation = [] }, }, }