add missing unit tests to input amout component

This commit is contained in:
mahula 2022-12-07 18:26:42 +01:00
parent 7c1f37d24c
commit 383e946594

View File

@ -5,6 +5,7 @@ const localVue = global.localVue
describe('InputAmount', () => {
let wrapper
let valid
const mocks = {
$t: jest.fn((t) => t),
@ -14,28 +15,105 @@ describe('InputAmount', () => {
$n: jest.fn((n) => String(n)),
}
const propsData = {
name: '',
label: '',
placeholder: '',
value: '',
}
describe('mount in a TransactionForm', () => {
const propsData = {
name: '',
label: '',
placeholder: '',
typ: 'TransactionForm',
value: '12.34',
}
const Wrapper = () => {
return mount(InputAmount, {
localVue,
mocks,
propsData,
})
}
const Wrapper = () => {
return mount(InputAmount, {
localVue,
mocks,
propsData,
})
}
describe('mount', () => {
beforeEach(() => {
wrapper = Wrapper()
wrapper.vm.$options.watch.value.call(wrapper.vm)
})
it('renders the component input-amount', () => {
expect(wrapper.find('div.input-amount').exists()).toBe(true)
})
describe('amount normalization', () => {
describe('if invalid', () => {
beforeEach(() => {
valid = false
})
it('is not normalized', () => {
wrapper.vm.normalizeAmount(valid)
expect(wrapper.vm.amountValue).toBe(0.0)
})
})
describe('if valid', () => {
beforeEach(() => {
valid = true
})
it('is normalized to a number - not rounded', async () => {
wrapper.vm.normalizeAmount(valid)
expect(wrapper.vm.currentValue).toBe('12.34')
})
})
})
})
describe('mount in a ContributionForm', () => {
const propsData = {
name: '',
label: '',
placeholder: '',
typ: 'ContributionForm',
value: '12.34',
}
const Wrapper = () => {
return mount(InputAmount, {
localVue,
mocks,
propsData,
})
}
beforeEach(() => {
wrapper = Wrapper()
wrapper.vm.$options.watch.value.call(wrapper.vm)
})
it('renders the component input-amount', () => {
expect(wrapper.find('div.input-amount').exists()).toBe(true)
})
describe('amount normalization', () => {
describe('if invalid', () => {
beforeEach(() => {
valid = false
})
it('is not normalized', () => {
wrapper.vm.normalizeAmount(valid)
expect(wrapper.vm.amountValue).toBe(0.0)
})
})
describe('if valid', () => {
beforeEach(() => {
valid = true
})
it('is normalized to a rounded number', () => {
wrapper.vm.normalizeAmount(valid)
expect(wrapper.vm.currentValue).toBe('12')
})
})
})
})
})