From 694c5494ef256f0191af91d6f4843f3fabb723b3 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 8 Nov 2024 13:02:12 +0100 Subject: [PATCH] feat: refs #7220 2 tet --- .../components/common/VnAccountNumber.spec.js | 50 +++++++++++- .../components/common/VnBreadcrumbs.spec.js | 78 ++++++++++++++++++- 2 files changed, 120 insertions(+), 8 deletions(-) diff --git a/test/cypress/components/common/VnAccountNumber.spec.js b/test/cypress/components/common/VnAccountNumber.spec.js index 3bf3db78d..3421b6026 100644 --- a/test/cypress/components/common/VnAccountNumber.spec.js +++ b/test/cypress/components/common/VnAccountNumber.spec.js @@ -1,8 +1,50 @@ import VnAccountNumber from 'src/components/common/VnAccountNumber.vue'; +import { Quasar, QInput } from 'quasar'; -describe.skip('', () => { - it('TODO: boilerplate', () => { - // see: https://on.cypress.io/mounting-vue - cy.createWrapper(VnAccountNumber); +describe('', () => { + // VNAccountNumber.spec.js + + const mountComponent = (props = {}) => { + cy.createWeapper(VnAccountNumber, { + global: { + plugins: [Quasar], + components: { QInput }, + }, + props, + }); + }; + + it('renderiza correctamente el componente', () => { + mountComponent(); + cy.get('.q-input').should('exist'); + }); + + it('muestra el valor inicial proporcionado en modelValue', () => { + const initialValue = '12345'; + mountComponent({ modelValue: initialValue }); + cy.get('.q-field__native').should('have.value', initialValue); + }); + + it('actualiza modelValue al ingresar texto', () => { + const onUpdateModelValue = cy.stub(); + mountComponent({ 'onUpdate:modelValue': onUpdateModelValue }); + cy.get('.q-field__native').type('67890'); + cy.wrap(onUpdateModelValue).should('have.been.called'); + }); + + it('convierte el número de cuenta corto al formato estándar', () => { + const shortAccount = '123.'; + const expectedAccount = '123' + '0'.repeat(11 - 3); + mountComponent({ modelValue: shortAccount }); + cy.get('.q-field__native').should('have.value', expectedAccount); + }); + + it('actualiza internalValue al cambiar modelValue', () => { + const newValue = '98765'; + mountComponent({ modelValue: '' }); + cy.then(() => { + Cypress.vueWrapper.setProps({ modelValue: newValue }); + }); + cy.get('.q-field__native').should('have.value', newValue); }); }); diff --git a/test/cypress/components/common/VnBreadcrumbs.spec.js b/test/cypress/components/common/VnBreadcrumbs.spec.js index 80eefc32c..be1f35f41 100644 --- a/test/cypress/components/common/VnBreadcrumbs.spec.js +++ b/test/cypress/components/common/VnBreadcrumbs.spec.js @@ -1,8 +1,78 @@ import VnBreadcrumbs from 'src/components/common/VnBreadcrumbs.vue'; +import { createRouter, createMemoryHistory } from 'vue-router'; +describe('', () => { + const routes = [ + { + path: '/', + name: 'Home', + meta: { title: 'Home' }, + }, + { + path: '/dashboard', + name: 'Dashboard', + meta: { title: 'Dashboard' }, + children: [ + { + path: 'settings', + name: 'Settings', + meta: { title: 'Settings' }, + }, + ], + }, + ]; -describe.skip('', () => { - it('TODO: boilerplate', () => { - // see: https://on.cypress.io/mounting-vue - cy.createWrapper(VnBreadcrumbs); + const mountComponent = (initialRoute = '/') => { + const router = createRouter({ + history: createMemoryHistory(), + routes, + }); + + router.push(initialRoute); + return router.isReady().then(() => { + cy.createWrapper(VnBreadcrumbs, { + global: { + plugins: [router], + }, + }); + }); + }; + + it('renderiza correctamente el componente', () => { + mountComponent(); + cy.get('.breadcrumbs').should('exist'); + }); + + it('muestra correctamente el breadcrumb en la ruta raíz', () => { + mountComponent('/'); + cy.get('.breadcrumbs').contains('Home').should('exist'); + }); + + it('muestra correctamente los breadcrumbs en una ruta anidada', () => { + mountComponent('/dashboard/settings'); + cy.get('.breadcrumbs').contains('Dashboard').should('exist'); + cy.get('.breadcrumbs').contains('Settings').should('exist'); + }); + + it('no muestra breadcrumbs si la ruta no tiene meta', () => { + const routesWithoutMeta = [ + { + path: '/nometa', + name: 'NoMeta', + }, + ]; + const router = createRouter({ + history: createMemoryHistory(), + routes: routesWithoutMeta, + }); + + router.push('/nometa'); + router.isReady().then(() => { + mount(VnBreadcrumbs, { + global: { + plugins: [router, Quasar], + }, + }); + cy.get('.breadcrumbs').should('not.exist'); + }); }); });