From 33095f0aa5602bf28da84a62965749bd2f51b794 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 19 Sep 2024 23:21:20 +0200 Subject: [PATCH] test: VnTitle --- test/cypress/components/VnTitle.spec.js | 104 ++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 5 deletions(-) diff --git a/test/cypress/components/VnTitle.spec.js b/test/cypress/components/VnTitle.spec.js index 72154348e9..385608f558 100644 --- a/test/cypress/components/VnTitle.spec.js +++ b/test/cypress/components/VnTitle.spec.js @@ -1,14 +1,108 @@ import VnTitle from 'src/components/common/VnTitle.vue'; +import { Quasar } from 'quasar'; describe('', () => { - it('renders', () => { - // see: https://on.cypress.io/mounting-vue + const globalConfig = { + global: { + plugins: [Quasar], + }, + }; + + beforeEach(() => { + cy.mount(VnTitle, globalConfig); + }); + + it('renders text with link', () => { cy.mount(VnTitle, { + ...globalConfig, props: { - url: 'url', - title: 'title', + url: 'https://example.com', + text: 'Example Link', }, }); - console.log(VnTitle); + cy.get('a').should('exist'); + cy.get('a').should('have.attr', 'href', 'https://example.com'); + cy.get('a').should('contain.text', 'Example Link'); + }); + it('renders text without link', () => { + cy.mount(VnTitle, { + ...globalConfig, + props: { + text: 'No Link', + }, + }); + cy.get('a').should('exist'); + cy.get('a').should('not.have.attr', 'href'); + cy.get('a').should('contain.text', 'No Link'); + }); + + it('applies correct classes based on url prop', () => { + cy.mount(VnTitle, { + ...globalConfig, + props: { + url: 'https://example.com', + }, + }); + cy.get('a').should('have.class', 'link'); + + cy.mount(VnTitle, { + ...globalConfig, + props: {}, + }); + cy.get('a').should('have.class', 'color-vn-text'); + }); + + it('displays icon when url is provided', () => { + cy.mount(VnTitle, { + ...globalConfig, + props: { + url: 'https://example.com', + }, + }); + cy.get('.q-icon').should('exist'); + }); + + it('does not display icon when url is not provided', () => { + cy.mount(VnTitle, { + ...globalConfig, + props: {}, + }); + cy.get('.q-icon').should('not.exist'); + }); + + it('applies correct cursor style based on url prop', () => { + cy.mount(VnTitle, { + ...globalConfig, + props: { + url: 'https://example.com', + }, + }); + cy.get('.header-link').should('have.css', 'cursor', 'pointer'); + + cy.mount(VnTitle, { + ...globalConfig, + props: {}, + }); + cy.get('.header-link').should('have.css', 'cursor', 'default'); + }); + it('renders default icon when no icon prop is provided', () => { + cy.mount(VnTitle, { + ...globalConfig, + props: { + url: 'https://example.com', + }, + }); + cy.get('i').should('contain.text', 'open_in_new'); + }); + + it('renders custom icon when icon prop is provided', () => { + cy.mount(VnTitle, { + ...globalConfig, + props: { + url: 'https://example.com', + icon: 'custom_icon', + }, + }); + cy.get('i').should('contain.text', 'custom_icon'); }); });