work on fixing tests

This commit is contained in:
einhornimmond 2023-11-16 12:00:35 +01:00
parent c61067c868
commit e7683fb05a
12 changed files with 92 additions and 39 deletions

View File

@ -12,6 +12,7 @@ describe('ContributionMessagesFormular', () => {
const propsData = {
contributionId: 42,
contributionMemo: 'It is a test memo',
}
const mocks = {
@ -52,9 +53,10 @@ describe('ContributionMessagesFormular', () => {
await wrapper.find('form').trigger('reset')
})
it('form has empty text', () => {
it('form has empty text and memo reset to contribution memo input', () => {
expect(wrapper.vm.form).toEqual({
text: '',
memo: 'It is a test memo',
})
})
})

View File

@ -148,6 +148,7 @@ export default {
},
onReset(event) {
this.form.text = ''
this.form.memo = this.contributionMemo
},
enableMemo() {
this.chatOrMemo = 1

View File

@ -86,6 +86,7 @@ describe('ContributionMessagesList', () => {
const propsData = {
contributionId: 42,
contributionMemo: 'test memo',
contributionUserId: 108,
contributionStatus: 'PENDING',
}

View File

@ -38,6 +38,8 @@ const defaultData = () => {
contributionDate: new Date(),
deletedBy: null,
deletedAt: null,
updatedAt: null,
updatedBy: null,
createdAt: new Date(),
moderatorId: null,
},
@ -61,6 +63,8 @@ const defaultData = () => {
contributionDate: new Date(),
deletedBy: null,
deletedAt: null,
updatedAt: null,
updatedBy: null,
createdAt: new Date(),
moderatorId: null,
},

View File

@ -0,0 +1,27 @@
import gql from 'graphql-tag'
export const getContribution = gql`
query ($id: Int!) {
contribution(id: $id) {
id
firstName
lastName
amount
memo
createdAt
contributionDate
confirmedAt
confirmedBy
updatedAt
updatedBy
status
messagesCount
deniedAt
deniedBy
deletedAt
deletedBy
moderatorId
userId
}
}
`

View File

@ -4,6 +4,7 @@ import { adminDeleteContribution } from '../graphql/adminDeleteContribution'
import { denyContribution } from '../graphql/denyContribution'
import { adminListContributions } from '../graphql/adminListContributions'
import { confirmContribution } from '../graphql/confirmContribution'
import { getContribution } from '../graphql/getContribution'
import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup'
import VueApollo from 'vue-apollo'
import { createMockClient } from 'mock-apollo-client'
@ -61,6 +62,8 @@ const defaultData = () => {
contributionDate: new Date(),
deletedBy: null,
deletedAt: null,
updatedAt: null,
updatedBy: null,
createdAt: new Date(),
},
{
@ -83,6 +86,8 @@ const defaultData = () => {
contributionDate: new Date(),
deletedBy: null,
deletedAt: null,
updatedAt: null,
updatedBy: null,
createdAt: new Date(),
},
],
@ -96,6 +101,7 @@ describe('CreationConfirm', () => {
const adminDeleteContributionMock = jest.fn()
const adminDenyContributionMock = jest.fn()
const confirmContributionMock = jest.fn()
const getContributionMock = jest.fn()
mockClient.setRequestHandler(
adminListContributions,
@ -121,6 +127,11 @@ describe('CreationConfirm', () => {
confirmContributionMock.mockResolvedValue({ data: { confirmContribution: true } }),
)
mockClient.setRequestHandler(
getContribution,
getContributionMock.mockResolvedValue({ data: {} }),
)
const Wrapper = () => {
return mount(CreationConfirm, { localVue, mocks, apolloProvider })
}
@ -141,7 +152,7 @@ describe('CreationConfirm', () => {
})
})
describe('server response is succes', () => {
describe('server response is success', () => {
it('has a DIV element with the class.creation-confirm', () => {
expect(wrapper.find('div.creation-confirm').exists()).toBeTruthy()
})
@ -150,7 +161,7 @@ describe('CreationConfirm', () => {
expect(wrapper.find('tbody').findAll('tr')).toHaveLength(2)
})
})
describe('actions in overlay', () => {
describe('delete creation', () => {
beforeEach(async () => {
@ -219,7 +230,7 @@ describe('CreationConfirm', () => {
expect(wrapper.find('#overlay').isVisible()).toBeTruthy()
})
describe('with succes', () => {
describe('with success', () => {
describe('cancel confirmation', () => {
beforeEach(async () => {
await wrapper.find('#overlay').findAll('button').at(0).trigger('click')
@ -278,7 +289,7 @@ describe('CreationConfirm', () => {
expect(wrapper.find('#overlay').isVisible()).toBeTruthy()
})
describe('with succes', () => {
describe('with success', () => {
describe('cancel deny', () => {
beforeEach(async () => {
await wrapper.find('#overlay').findAll('button').at(0).trigger('click')
@ -510,6 +521,18 @@ describe('CreationConfirm', () => {
})
})
describe('reload contribution', () => {
beforeEach(async () => {
await wrapper.findComponent({ name: 'OpenCreationsTable' }).vm.$emit('reload-contribution', 1)
})
it('reloaded contribution', () => {
expect(getContributionMock).toBeCalledWith({
id: 1
})
})
})
describe('unknown variant', () => {
beforeEach(async () => {
await wrapper.setData({ variant: 'unknown' })

View File

@ -3,7 +3,7 @@
<div class="creation-confirm">
<user-query class="mb-2 mt-2" v-model="query" :placeholder="$t('user_memo_search')" />
<label class="mb-4">
<input type="checkbox" class="noHashtag" v-model="noHashtag" @change="swapNoHashtag" />
<input type="checkbox" class="noHashtag" v-model="noHashtag" />
<span class="ml-2" v-b-tooltip="$t('no_hashtag_tooltip')">{{ $t('no_hashtag') }}</span>
</label>
<div>
@ -96,33 +96,7 @@ import { adminListContributions } from '../graphql/adminListContributions'
import { adminDeleteContribution } from '../graphql/adminDeleteContribution'
import { confirmContribution } from '../graphql/confirmContribution'
import { denyContribution } from '../graphql/denyContribution'
import gql from 'graphql-tag'
export const getContribution = gql`
query ($id: Int!) {
contribution(id: $id) {
id
firstName
lastName
amount
memo
createdAt
contributionDate
confirmedAt
confirmedBy
updatedAt
updatedBy
status
messagesCount
deniedAt
deniedBy
deletedAt
deletedBy
moderatorId
userId
}
}
`
import { getContribution } from '../graphql/getContribution'
const FILTER_TAB_MAP = [
['IN_PROGRESS', 'PENDING'],
@ -175,9 +149,6 @@ export default {
this.toastError(error.message)
})
},
swapNoHashtag() {
this.query()
},
deleteCreation() {
this.$apollo
.mutate({

View File

@ -53,6 +53,8 @@ const defaultData = () => {
contributionDate: new Date(),
deletedBy: null,
deletedAt: null,
updatedAt: null,
updatedBy: null,
createdAt: new Date(),
},
{
@ -75,6 +77,8 @@ const defaultData = () => {
contributionDate: new Date(),
deletedBy: null,
deletedAt: null,
updatedAt: null,
updatedBy: null,
createdAt: new Date(),
},
],

View File

@ -41,4 +41,13 @@ export class UnconfirmedContributionAdminRole extends UnconfirmedContributionRol
}
return this
}
protected async validate(clientTimezoneOffset: number): Promise<void> {
await super.validate(clientTimezoneOffset)
// creation date is currently not changeable
if (this.self.memo === this.updateData.memo &&
this.self.amount === this.updatedAmount &&
this.self.contributionDate.getTime() === (new Date(this.updatedCreationDate).getTime())) {
throw new LogError("the contribution wasn't changed at all")
}
}
}

View File

@ -43,4 +43,14 @@ export class UnconfirmedContributionUserRole extends UnconfirmedContributionRole
}
return this
}
protected async validate(clientTimezoneOffset: number): Promise<void> {
await super.validate(clientTimezoneOffset)
// creation date is currently not changeable
if (this.self.memo === this.updateData.memo &&
this.self.amount === this.updatedAmount &&
this.self.contributionDate.getTime() === (new Date(this.updatedCreationDate).getTime())) {
throw new LogError("the contribution wasn't changed at all")
}
}
}

View File

@ -16,7 +16,6 @@
reset-value=""
:label-no-date-selected="$t('contribution.noDateSelected')"
required
:disabled="this.form.id !== null"
:no-flip="true"
>
<template #nav-prev-year><span></span></template>

View File

@ -91,6 +91,7 @@ export default {
hours: 0,
amount: '',
},
originalContributionDate: '',
updateAmount: '',
maximalDate: new Date(),
openCreations: [],
@ -183,10 +184,10 @@ export default {
return 0
},
maxForMonths() {
const formDate = new Date(this.form.date)
const originalContributionDate = new Date(this.originalContributionDate)
if (this.openCreations && this.openCreations.length)
return this.openCreations.slice(1).map((creation) => {
if (creation.year === formDate.getFullYear() && creation.month === formDate.getMonth())
if (creation.year === originalContributionDate.getFullYear() && creation.month === originalContributionDate.getMonth())
return parseInt(creation.amount) + this.amountToAdd
return parseInt(creation.amount)
})
@ -280,6 +281,7 @@ export default {
updateContributionForm(item) {
this.form.id = item.id
this.form.date = item.contributionDate
this.originalContributionDate = item.contributionDate
this.form.memo = item.memo
this.form.amount = item.amount
this.form.hours = item.amount / 20