test: refs #7069 add unit tests for VnAccountNumber component
gitea/salix-front/pipeline/pr-dev This commit is unstable Details

This commit is contained in:
Jose Antonio Tubau 2025-04-30 10:41:49 +02:00
parent 2dfdfc2987
commit b21c5752b8
1 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,58 @@
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import VnAccountNumber from 'src/components/common/VnAccountNumber.vue';
const VnInputStub = {
name: 'VnInput',
props: ['modelValue'],
emits: ['input', 'keydown', 'blur'],
template: `
<input
:value="modelValue"
@input="$emit('input', $event)"
@keydown.tab="$emit('blur', $event)"
@blur="$emit('blur', $event)"
/>
`,
};
describe('VnAccountNumber', () => {
let wrapper;
let input;
let spyShort;
beforeEach(() => {
wrapper = createWrapper(VnAccountNumber, {
props: { modelValue: '' },
global: { stubs: { VnInput: VnInputStub } },
});
wrapper = wrapper.wrapper;
input = wrapper.findComponent(VnInputStub);
spyShort = vi.spyOn(wrapper.vm, 'useAccountShortToStandard');
});
it('should filters out non-numeric characters on input event', async () => {
await input.vm.$emit('input', { target: { value: 'abc123.45!@#' } });
const emitted = wrapper.emitted('update:modelValue');
expect(emitted.pop()[0]).toBe('123.45');
expect(spyShort).not.toHaveBeenCalled();
});
it('should applies conversion on blur when valid short value provided', async () => {
await input.vm.$emit('input', { target: { value: '123.45' } });
await input.trigger('keydown.tab');
const emitted = wrapper.emitted('update:modelValue');
expect(emitted.pop()[0]).toBe('1230000045');
expect(spyShort).toHaveBeenCalled();
});
it('should does not change value for invalid input values', async () => {
await input.vm.$emit('input', { target: { value: '123' } });
await input.trigger('keydown.tab');
const emitted = wrapper.emitted('update:modelValue');
expect(emitted.pop()[0]).toBe('123');
expect(spyShort).toHaveBeenCalled();
});
});