mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
refactor tests for creation, change methods
This commit is contained in:
parent
bf239b1476
commit
c949bf6ebe
@ -284,11 +284,11 @@ export default {
|
|||||||
this.overlay = false
|
this.overlay = false
|
||||||
},
|
},
|
||||||
bookmarkPush(item) {
|
bookmarkPush(item) {
|
||||||
this.$emit('update-item', item, 'push')
|
this.$emit('push-item', item)
|
||||||
},
|
},
|
||||||
bookmarkRemove(item) {
|
bookmarkRemove(item) {
|
||||||
if (this.type === 'UserListMassCreation') {
|
if (this.type === 'UserListMassCreation') {
|
||||||
this.$emit('update-item', item, 'remove')
|
this.$emit('remove-item', item)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.type === 'PageCreationConfirm') {
|
if (this.type === 'PageCreationConfirm') {
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { shallowMount } from '@vue/test-utils'
|
import { shallowMount } from '@vue/test-utils'
|
||||||
import Creation from './Creation.vue'
|
import Creation from './Creation.vue'
|
||||||
import Vue from 'vue'
|
|
||||||
|
|
||||||
const localVue = global.localVue
|
const localVue = global.localVue
|
||||||
|
|
||||||
@ -66,6 +65,7 @@ describe('Creation', () => {
|
|||||||
|
|
||||||
describe('shallowMount', () => {
|
describe('shallowMount', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -75,7 +75,15 @@ describe('Creation', () => {
|
|||||||
|
|
||||||
describe('apollo returns user array', () => {
|
describe('apollo returns user array', () => {
|
||||||
it('calls the searchUser query', () => {
|
it('calls the searchUser query', () => {
|
||||||
expect(apolloQueryMock).toBeCalled()
|
expect(apolloQueryMock).toBeCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
variables: {
|
||||||
|
searchText: '',
|
||||||
|
currentPage: 1,
|
||||||
|
pageSize: 25,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets the data of itemsList', () => {
|
it('sets the data of itemsList', () => {
|
||||||
@ -100,151 +108,33 @@ describe('Creation', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('update item', () => {
|
describe('push item', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks()
|
wrapper.findComponent({ name: 'UserTable' }).vm.$emit('push-item', {
|
||||||
})
|
userId: 2,
|
||||||
|
firstName: 'Benjamin',
|
||||||
describe('push', () => {
|
lastName: 'Blümchen',
|
||||||
beforeEach(() => {
|
email: 'benjamin@bluemchen.de',
|
||||||
wrapper.findComponent({ name: 'UserTable' }).vm.$emit(
|
creation: [800, 600, 400],
|
||||||
'update-item',
|
showDetails: false,
|
||||||
{
|
|
||||||
userId: 2,
|
|
||||||
firstName: 'Benjamin',
|
|
||||||
lastName: 'Blümchen',
|
|
||||||
email: 'benjamin@bluemchen.de',
|
|
||||||
creation: [800, 600, 400],
|
|
||||||
showDetails: false,
|
|
||||||
},
|
|
||||||
'push',
|
|
||||||
)
|
|
||||||
})
|
|
||||||
beforeEach(() => {
|
|
||||||
mocks.$store.state.setUserSelectedInMassCreation = [
|
|
||||||
{
|
|
||||||
userId: 2,
|
|
||||||
firstName: 'Benjamin',
|
|
||||||
lastName: 'Blümchen',
|
|
||||||
email: 'benjamin@bluemchen.de',
|
|
||||||
creation: [800, 600, 400],
|
|
||||||
showDetails: false,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
|
||||||
it('removes the pushed item from itemsList', () => {
|
|
||||||
expect(wrapper.vm.itemsList).toEqual([
|
|
||||||
{
|
|
||||||
userId: 1,
|
|
||||||
firstName: 'Bibi',
|
|
||||||
lastName: 'Bloxberg',
|
|
||||||
email: 'bibi@bloxberg.de',
|
|
||||||
creation: [200, 400, 600],
|
|
||||||
showDetails: false,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('adds the pushed item to userSelectedInMassCreation', () => {
|
|
||||||
expect(storeCommitMock).toBeCalledWith('userSelectedInMassCreation', [
|
|
||||||
{
|
|
||||||
userId: 2,
|
|
||||||
firstName: 'Benjamin',
|
|
||||||
lastName: 'Blümchen',
|
|
||||||
email: 'benjamin@bluemchen.de',
|
|
||||||
creation: [800, 600, 400],
|
|
||||||
showDetails: false,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
// expect(wrapper.vm.userSelectedInMassCreation).toEqual([
|
|
||||||
// {
|
|
||||||
// userId: 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',
|
|
||||||
{
|
|
||||||
userId: 2,
|
|
||||||
firstName: 'Benjamin',
|
|
||||||
lastName: 'Blümchen',
|
|
||||||
email: 'benjamin@bluemchen.de',
|
|
||||||
creation: [800, 600, 400],
|
|
||||||
showDetails: false,
|
|
||||||
},
|
|
||||||
'remove',
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('removes the item from userSelectedInMassCreation', () => {
|
|
||||||
expect(storeCommitMock).toBeCalledWith('setUserSelectedInMassCreation', [
|
|
||||||
{
|
|
||||||
userId: 2,
|
|
||||||
firstName: 'Benjamin',
|
|
||||||
lastName: 'Blümchen',
|
|
||||||
email: 'benjamin@bluemchen.de',
|
|
||||||
creation: [800, 600, 400],
|
|
||||||
showDetails: false,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('adds the item to itemsList', () => {
|
|
||||||
expect(wrapper.vm.itemsList).toEqual([
|
|
||||||
{
|
|
||||||
userId: 1,
|
|
||||||
firstName: 'Bibi',
|
|
||||||
lastName: 'Bloxberg',
|
|
||||||
email: 'bibi@bloxberg.de',
|
|
||||||
creation: [200, 400, 600],
|
|
||||||
showDetails: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
userId: 2,
|
|
||||||
firstName: 'Benjamin',
|
|
||||||
lastName: 'Blümchen',
|
|
||||||
email: 'benjamin@bluemchen.de',
|
|
||||||
creation: [800, 600, 400],
|
|
||||||
showDetails: false,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('error', () => {
|
it('removes the pushed item from itemsList', () => {
|
||||||
const consoleErrorMock = jest.fn()
|
expect(wrapper.vm.itemsList).toEqual([
|
||||||
const warnHandler = Vue.config.warnHandler
|
{
|
||||||
|
userId: 1,
|
||||||
beforeEach(() => {
|
firstName: 'Bibi',
|
||||||
Vue.config.warnHandler = (w) => {}
|
lastName: 'Bloxberg',
|
||||||
// eslint-disable-next-line no-console
|
email: 'bibi@bloxberg.de',
|
||||||
console.error = consoleErrorMock
|
creation: [200, 400, 600],
|
||||||
wrapper.findComponent({ name: 'UserTable' }).vm.$emit('update-item', {}, 'no-rule')
|
showDetails: false,
|
||||||
})
|
},
|
||||||
|
])
|
||||||
afterEach(() => {
|
|
||||||
Vue.config.warnHandler = warnHandler
|
|
||||||
})
|
|
||||||
|
|
||||||
it('throws an error', () => {
|
|
||||||
expect(consoleErrorMock).toBeCalledWith(expect.objectContaining({ message: 'no-rule' }))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe('remove all bookmarks', () => {
|
it('adds the pushed item to itemsMassCreation', () => {
|
||||||
beforeEach(async () => {
|
expect(wrapper.vm.itemsMassCreation).toEqual([
|
||||||
await wrapper.findComponent({ name: 'UserTable' }).vm.$emit(
|
|
||||||
'update-item',
|
|
||||||
{
|
{
|
||||||
userId: 2,
|
userId: 2,
|
||||||
firstName: 'Benjamin',
|
firstName: 'Benjamin',
|
||||||
@ -253,17 +143,100 @@ describe('Creation', () => {
|
|||||||
creation: [800, 600, 400],
|
creation: [800, 600, 400],
|
||||||
showDetails: false,
|
showDetails: false,
|
||||||
},
|
},
|
||||||
'push',
|
])
|
||||||
)
|
})
|
||||||
|
|
||||||
|
it('updates userSelectedInMassCreation in store', () => {
|
||||||
|
expect(storeCommitMock).toBeCalledWith('setUserSelectedInMassCreation', [
|
||||||
|
{
|
||||||
|
userId: 2,
|
||||||
|
firstName: 'Benjamin',
|
||||||
|
lastName: 'Blümchen',
|
||||||
|
email: 'benjamin@bluemchen.de',
|
||||||
|
creation: [800, 600, 400],
|
||||||
|
showDetails: false,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('remove item', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await wrapper.findComponent({ name: 'UserTable' }).vm.$emit('push-item', {
|
||||||
|
userId: 2,
|
||||||
|
firstName: 'Benjamin',
|
||||||
|
lastName: 'Blümchen',
|
||||||
|
email: 'benjamin@bluemchen.de',
|
||||||
|
creation: [800, 600, 400],
|
||||||
|
showDetails: false,
|
||||||
|
})
|
||||||
|
await wrapper
|
||||||
|
.findAllComponents({ name: 'UserTable' })
|
||||||
|
.at(1)
|
||||||
|
.vm.$emit('remove-item', {
|
||||||
|
userId: 2,
|
||||||
|
firstName: 'Benjamin',
|
||||||
|
lastName: 'Blümchen',
|
||||||
|
email: 'benjamin@bluemchen.de',
|
||||||
|
creation: [800, 600, 400],
|
||||||
|
showDetails: false,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('adds the removed item to itemsList', () => {
|
||||||
|
expect(wrapper.vm.itemsList).toEqual([
|
||||||
|
{
|
||||||
|
userId: 2,
|
||||||
|
firstName: 'Benjamin',
|
||||||
|
lastName: 'Blümchen',
|
||||||
|
email: 'benjamin@bluemchen.de',
|
||||||
|
creation: [800, 600, 400],
|
||||||
|
showDetails: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userId: 1,
|
||||||
|
firstName: 'Bibi',
|
||||||
|
lastName: 'Bloxberg',
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
creation: [200, 400, 600],
|
||||||
|
showDetails: false,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('removes the item from itemsMassCreation', () => {
|
||||||
|
expect(wrapper.vm.itemsMassCreation).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('commits empty array as userSelectedInMassCreation', () => {
|
||||||
|
expect(storeCommitMock).toBeCalledWith('setUserSelectedInMassCreation', [])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('remove all bookmarks', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await wrapper.findComponent({ name: 'UserTable' }).vm.$emit('push-item', {
|
||||||
|
userId: 2,
|
||||||
|
firstName: 'Benjamin',
|
||||||
|
lastName: 'Blümchen',
|
||||||
|
email: 'benjamin@bluemchen.de',
|
||||||
|
creation: [800, 600, 400],
|
||||||
|
showDetails: false,
|
||||||
|
})
|
||||||
|
jest.clearAllMocks()
|
||||||
wrapper.findComponent({ name: 'CreationFormular' }).vm.$emit('remove-all-bookmark')
|
wrapper.findComponent({ name: 'CreationFormular' }).vm.$emit('remove-all-bookmark')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('removes all items from userSelectedInMassCreation', () => {
|
it('removes all items from itemsMassCreation', () => {
|
||||||
|
expect(wrapper.vm.itemsMassCreation).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('commits empty array to userSelectedInMassCreation', () => {
|
||||||
expect(storeCommitMock).toBeCalledWith('setUserSelectedInMassCreation', [])
|
expect(storeCommitMock).toBeCalledWith('setUserSelectedInMassCreation', [])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('adds all items to itemsList', () => {
|
it('calls searchUsers', () => {
|
||||||
expect(wrapper.vm.itemsList).toHaveLength(2)
|
expect(apolloQueryMock).toBeCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -274,12 +247,28 @@ describe('Creation', () => {
|
|||||||
|
|
||||||
it('calls API when criteria changes', async () => {
|
it('calls API when criteria changes', async () => {
|
||||||
await wrapper.setData({ criteria: 'XX' })
|
await wrapper.setData({ criteria: 'XX' })
|
||||||
expect(apolloQueryMock).toBeCalled()
|
expect(apolloQueryMock).toBeCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
variables: {
|
||||||
|
searchText: 'XX',
|
||||||
|
currentPage: 1,
|
||||||
|
pageSize: 25,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls API when currentPage changes', async () => {
|
it('calls API when currentPage changes', async () => {
|
||||||
await wrapper.setData({ currentPage: 2 })
|
await wrapper.setData({ currentPage: 2 })
|
||||||
expect(apolloQueryMock).toBeCalled()
|
expect(apolloQueryMock).toBeCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
variables: {
|
||||||
|
searchText: '',
|
||||||
|
currentPage: 2,
|
||||||
|
pageSize: 25,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
:fieldsTable="Searchfields"
|
:fieldsTable="Searchfields"
|
||||||
:criteria="criteria"
|
:criteria="criteria"
|
||||||
:creation="creation"
|
:creation="creation"
|
||||||
@update-item="updateItem"
|
@push-item="pushItem"
|
||||||
/>
|
/>
|
||||||
<b-pagination
|
<b-pagination
|
||||||
pills
|
pills
|
||||||
@ -31,11 +31,11 @@
|
|||||||
v-show="itemsMassCreation.length > 0"
|
v-show="itemsMassCreation.length > 0"
|
||||||
class="shadow p-3 mb-5 bg-white rounded"
|
class="shadow p-3 mb-5 bg-white rounded"
|
||||||
type="UserListMassCreation"
|
type="UserListMassCreation"
|
||||||
:itemsUser="itemsMassCreationReverse"
|
:itemsUser="itemsMassCreation"
|
||||||
:fieldsTable="fields"
|
:fieldsTable="fields"
|
||||||
:criteria="null"
|
:criteria="null"
|
||||||
:creation="creation"
|
:creation="creation"
|
||||||
@update-item="updateItem"
|
@remove-item="removeItem"
|
||||||
/>
|
/>
|
||||||
<div v-if="itemsMassCreation.length === 0">
|
<div v-if="itemsMassCreation.length === 0">
|
||||||
{{ $t('multiple_creation_text') }}
|
{{ $t('multiple_creation_text') }}
|
||||||
@ -113,7 +113,7 @@ export default {
|
|||||||
perPage: 25,
|
perPage: 25,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async created() {
|
||||||
await this.getUsers()
|
await this.getUsers()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -136,7 +136,7 @@ export default {
|
|||||||
showDetails: false,
|
showDetails: false,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (this.itemsMassCreation !== []) {
|
if (this.itemsMassCreation.length !== 0) {
|
||||||
const selectedIndices = this.itemsMassCreation.map((item) => item.userId)
|
const selectedIndices = this.itemsMassCreation.map((item) => item.userId)
|
||||||
this.itemsList = this.itemsList.filter((item) => !selectedIndices.includes(item.userId))
|
this.itemsList = this.itemsList.filter((item) => !selectedIndices.includes(item.userId))
|
||||||
}
|
}
|
||||||
@ -145,39 +145,30 @@ export default {
|
|||||||
this.$toasted.error(error.message)
|
this.$toasted.error(error.message)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
updateItem(selectedItem, event) {
|
pushItem(selectedItem) {
|
||||||
switch (event) {
|
this.itemsMassCreation = [
|
||||||
case 'push':
|
this.itemsList.find((item) => selectedItem.userId === item.userId),
|
||||||
this.itemsMassCreation.push(
|
...this.itemsMassCreation,
|
||||||
this.itemsList.find((item) => selectedItem.userId === item.userId),
|
]
|
||||||
)
|
this.itemsList = this.itemsList.filter((item) => selectedItem.userId !== item.userId)
|
||||||
this.itemsList = this.itemsList.filter((item) => selectedItem.userId !== item.userId)
|
this.$store.commit('setUserSelectedInMassCreation', this.itemsMassCreation)
|
||||||
break
|
},
|
||||||
case 'remove':
|
removeItem(selectedItem) {
|
||||||
this.itemsList.push(
|
this.itemsList = [
|
||||||
this.itemsMassCreation.find((item) => selectedItem.userId === item.userId),
|
this.itemsMassCreation.find((item) => selectedItem.userId === item.userId),
|
||||||
)
|
...this.itemsList,
|
||||||
this.itemsMassCreation = this.itemsMassCreation.filter(
|
]
|
||||||
(item) => selectedItem.userId !== item.userId,
|
this.itemsMassCreation = this.itemsMassCreation.filter(
|
||||||
)
|
(item) => selectedItem.userId !== item.userId,
|
||||||
break
|
)
|
||||||
default:
|
|
||||||
throw new Error(event)
|
|
||||||
}
|
|
||||||
this.$store.commit('setUserSelectedInMassCreation', this.itemsMassCreation)
|
this.$store.commit('setUserSelectedInMassCreation', this.itemsMassCreation)
|
||||||
},
|
},
|
||||||
removeAllBookmark() {
|
removeAllBookmark() {
|
||||||
this.itemsMassCreation = []
|
this.itemsMassCreation = []
|
||||||
this.$store.commit('setUserSelectedInMassCreation', this.itemsMassCreation)
|
this.$store.commit('setUserSelectedInMassCreation', [])
|
||||||
this.getUsers()
|
this.getUsers()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
itemsMassCreationReverse() {
|
|
||||||
const array = this.itemsMassCreation
|
|
||||||
return array.reverse()
|
|
||||||
},
|
|
||||||
},
|
|
||||||
watch: {
|
watch: {
|
||||||
currentPage() {
|
currentPage() {
|
||||||
this.getUsers()
|
this.getUsers()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user