WIP: #7354 zone_missing_e2e #1030

Draft
jsegarra wants to merge 191 commits from 7354_zone_missing_e2e into dev
2 changed files with 44 additions and 9 deletions
Showing only changes of commit be1cd824d8 - Show all commits

View File

@ -38,6 +38,10 @@ const $props = defineProps({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
maxlength: {
type: Number,
default: null,
},
}); });
const vnInputRef = ref(null); const vnInputRef = ref(null);
@ -90,6 +94,8 @@ const handleKeydown = (e) => {
if (e.key === 'Backspace') return; if (e.key === 'Backspace') return;
if ($props.insertable && e.key.match(/[0-9]/)) { if ($props.insertable && e.key.match(/[0-9]/)) {
handleInsertMode(e); handleInsertMode(e);
} else {
e.preventDefault();
} }
}; };
@ -100,8 +106,17 @@ const handleInsertMode = (e) => {
let currentValue = value.value; let currentValue = value.value;
if (!currentValue) currentValue = e.key; if (!currentValue) currentValue = e.key;
const newValue = Number(e.key); const newValue = e.key;
if (newValue && !isNaN(newValue)) {
if (
!newValue ||
($props.maxlength &&
currentValue.length >= $props.maxlength &&
cursorPos == $props.maxlength)
) {
return;
}
value.value = value.value =
currentValue.substring(0, cursorPos) + currentValue.substring(0, cursorPos) +
newValue + newValue +
@ -110,7 +125,6 @@ const handleInsertMode = (e) => {
nextTick(() => { nextTick(() => {
input.setSelectionRange(cursorPos + 1, cursorPos + 1); input.setSelectionRange(cursorPos + 1, cursorPos + 1);
}); });
}
}; };
</script> </script>

View File

@ -18,4 +18,25 @@ describe('VnInput Component', () => {
.find('input') .find('input')
.should('have.value', '9990000001'); .should('have.value', '9990000001');
}); });
it('should replace character at cursor position in insert mode', () => {
// Simula escribir en el input
cy.dataCy('supplierFiscalDataAccount').find('input').clear();
cy.dataCy('supplierFiscalDataAccount').find('input').type('4100000001');
// Coloca el cursor en la posición 0
cy.dataCy('supplierFiscalDataAccount').find('input').type('{movetostart}');
// Escribe un número y verifica que se reemplace correctamente en la posicion incial
cy.dataCy('supplierFiscalDataAccount').find('input').type('999');
cy.dataCy('supplierFiscalDataAccount')
.find('input')
.should('have.value', '9990000001');
});
it('should respect maxlength prop', () => {
cy.dataCy('supplierFiscalDataAccount').find('input').clear();
cy.dataCy('supplierFiscalDataAccount').find('input').type('123456789012345');
cy.dataCy('supplierFiscalDataAccount')
.find('input')
.should('have.value', '1234567890'); // asumiendo que maxlength es 10
});
}); });