feat: refs #8163 add VnInput insert functionality and e2e test
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
bc173d9f6a
commit
ec40ef9351
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref, useAttrs } from 'vue';
|
import { computed, ref, useAttrs, nextTick } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRequired } from 'src/composables/useRequired';
|
import { useRequired } from 'src/composables/useRequired';
|
||||||
|
|
||||||
|
@ -78,6 +78,36 @@ const mixinRules = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const insertMode = ref(false);
|
||||||
|
|
||||||
|
const handleKeydown = (e) => {
|
||||||
|
if (e.key === 'Insert') {
|
||||||
|
insertMode.value = !insertMode.value;
|
||||||
|
}
|
||||||
|
if (insertMode.value && e.key !== 'Insert') {
|
||||||
|
handleInsertMode(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInsertMode = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const input = e.target;
|
||||||
|
const cursorPos = input.selectionStart;
|
||||||
|
|
||||||
|
const newValue = Number(e.key);
|
||||||
|
if (newValue && !isNaN(newValue)) {
|
||||||
|
const currentValue = value.value;
|
||||||
|
value.value =
|
||||||
|
currentValue.substring(0, cursorPos) +
|
||||||
|
newValue +
|
||||||
|
currentValue.substring(cursorPos + 1);
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
input.setSelectionRange(cursorPos + 1, cursorPos + 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -89,6 +119,7 @@ const mixinRules = [
|
||||||
:type="$attrs.type"
|
:type="$attrs.type"
|
||||||
:class="{ required: isRequired }"
|
:class="{ required: isRequired }"
|
||||||
@keyup.enter="emit('keyup.enter')"
|
@keyup.enter="emit('keyup.enter')"
|
||||||
|
@keydown="handleKeydown"
|
||||||
:clearable="false"
|
:clearable="false"
|
||||||
:rules="mixinRules"
|
:rules="mixinRules"
|
||||||
:lazy-rules="true"
|
:lazy-rules="true"
|
||||||
|
|
|
@ -104,6 +104,7 @@ function handleLocation(data, location) {
|
||||||
v-model="data.account"
|
v-model="data.account"
|
||||||
:label="t('supplier.fiscalData.account')"
|
:label="t('supplier.fiscalData.account')"
|
||||||
clearable
|
clearable
|
||||||
|
data-cy="supplierFiscalDataAccount"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('supplier.fiscalData.sageTaxTypeFk')"
|
:label="t('supplier.fiscalData.sageTaxTypeFk')"
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
describe('VnInput Component', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.login('developer');
|
||||||
|
cy.viewport(1920, 1080);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should replace character at cursor position in insert mode', () => {
|
||||||
|
cy.visit('/#/supplier/1/fiscal-data');
|
||||||
|
|
||||||
|
// Simula escribir en el input
|
||||||
|
cy.dataCy('supplierFiscalDataAccount').find('input').clear();
|
||||||
|
cy.dataCy('supplierFiscalDataAccount').find('input').type('0123456789');
|
||||||
|
// Activa el modo de inserción
|
||||||
|
cy.dataCy('supplierFiscalDataAccount')
|
||||||
|
.find('input')
|
||||||
|
.trigger('keydown', { key: 'Insert' });
|
||||||
|
// 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
|
||||||
|
cy.dataCy('supplierFiscalDataAccount').find('input').type('999');
|
||||||
|
cy.dataCy('supplierFiscalDataAccount')
|
||||||
|
.find('input')
|
||||||
|
.should('have.value', '9993456789');
|
||||||
|
});
|
||||||
|
});
|
|
@ -310,3 +310,7 @@ Cypress.Commands.add('checkValueSelectForm', (id, search) => {
|
||||||
Cypress.Commands.add('searchByLabel', (label, value) => {
|
Cypress.Commands.add('searchByLabel', (label, value) => {
|
||||||
cy.get(`[label="${label}"] > .q-field > .q-field__inner`).type(`${value}{enter}`);
|
cy.get(`[label="${label}"] > .q-field > .q-field__inner`).type(`${value}{enter}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Cypress.Commands.add('dataCy', (dataTestId, attr = 'data-cy') => {
|
||||||
|
return cy.get(`[${attr}="${dataTestId}"]`);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue