feat: refs #7069 VnAccountNumber
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Robert Ferrús 2025-01-14 10:49:08 +01:00
parent 0dc0c9efd0
commit 97aab52190
1 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,84 @@
import { createWrapper } from 'app/test/vitest/helper';
import { vi, describe, expect, it } from 'vitest';
import VnInput from 'src/components/common/VnAccountNumber.vue';
describe('VnInput', () => {
let vm;
let wrapper;
let input;
function generateWrapper(value, insertable) {
wrapper = createWrapper(VnInput, {
props: {
modelValue: value,
insertable,
},
});
wrapper = wrapper.wrapper;
vm = wrapper.vm;
input = wrapper.find('input');
}
describe('value', () => {
it('should emit update:modelValue when value changes', async () => {
generateWrapper('12345', true);
await input.setValue('123');
expect(wrapper.emitted('update:modelValue')).toBeTruthy();
expect(wrapper.emitted('update:modelValue')[0]).toEqual(['123']);
});
it('should emit update:modelValue with null when input is empty', async () => {
generateWrapper('12345', true);
await input.setValue('');
expect(wrapper.emitted('update:modelValue')[0]).toEqual([null]);
});
});
describe('styleAttrs', () => {
it('should return empty styleAttrs when isOutlined is false', async () => {
generateWrapper('123', false);
expect(vm.styleAttrs).toEqual({});
});
it('should set styleAttrs when isOutlined is true', async () => {
generateWrapper('123', false);
expect(vm.styleAttrs.outlined).toBe(true);
});
});
describe('handleKeydown', () => {
it('should do nothing when "Backspace" key is pressed', async () => {
generateWrapper('12345', true);
await input.trigger('keydown', { key: 'Backspace' });
expect(wrapper.emitted('update:modelValue')).toBeUndefined();
const spyhandler = vi.spyOn(vm, 'handleInsertMode');
expect(spyhandler).not.toHaveBeenCalled();
});
/*
Verify the component's behavior before removing the .skip, as it doesn't set the maxlength
property of the input and doesn't set the value.
*/
it('handleKeydown respects insertable behavior', async () => {
const expectedValue = '12345';
generateWrapper('1234', true);
await input.trigger('keydown', { key: '5' });
await vm.$nextTick();
// expect(wrapper.emitted('update:modelValue')).toBeTruthy();
// expect(wrapper.emitted('update:modelValue')[0]).toEqual([expectedValue]);
expect(vm.internalValue).toBe(expectedValue);
});
});
describe('focus', () => {
it('should call focus method when input is focused', async () => {
generateWrapper('123', true);
vm.setCursorPosition();
const focusSpy = vi.spyOn(input.element, 'focus');
const setSelectionRangeSpy = vi.spyOn(input.element, 'setSelectionRange');
expect(focusSpy).toHaveBeenCalled();
expect(setSelectionRangeSpy).toHaveBeenCalled();
});
});
});