test: VnTitle
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-09-19 23:21:20 +02:00
parent 6272f300ee
commit 33095f0aa5
1 changed files with 99 additions and 5 deletions

View File

@ -1,14 +1,108 @@
import VnTitle from 'src/components/common/VnTitle.vue';
import { Quasar } from 'quasar';
describe('<VnTitle />', () => {
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');
});
});