salix-front/test/cypress/components/VnTitle.spec.js

88 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-05-28 09:38:09 +00:00
import VnTitle from 'src/components/common/VnTitle.vue';
2024-04-16 12:13:44 +00:00
describe('<VnTitle />', () => {
2024-09-19 21:21:20 +00:00
it('renders text with link', () => {
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
props: {
url: 'https://example.com',
text: 'Example Link',
},
});
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', () => {
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
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', () => {
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
props: {
url: 'https://example.com',
},
});
cy.get('a').should('have.class', 'link');
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
props: {},
});
cy.get('a').should('have.class', 'color-vn-text');
});
it('displays icon when url is provided', () => {
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
props: {
url: 'https://example.com',
},
});
cy.get('.q-icon').should('exist');
});
it('does not display icon when url is not provided', () => {
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
props: {},
});
cy.get('.q-icon').should('not.exist');
});
it('applies correct cursor style based on url prop', () => {
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
props: {
url: 'https://example.com',
},
});
cy.get('.header-link').should('have.css', 'cursor', 'pointer');
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
props: {},
});
cy.get('.header-link').should('have.css', 'cursor', 'default');
});
it('renders default icon when no icon prop is provided', () => {
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-09-19 21:21:20 +00:00
props: {
url: 'https://example.com',
},
});
cy.get('i').should('contain.text', 'open_in_new');
});
it('renders custom icon when icon prop is provided', () => {
2024-09-19 21:56:28 +00:00
cy.vnMount(VnTitle, {
2024-05-28 09:38:09 +00:00
props: {
2024-09-19 21:21:20 +00:00
url: 'https://example.com',
icon: 'custom_icon',
2024-05-28 09:38:09 +00:00
},
2024-04-16 12:13:44 +00:00
});
2024-09-19 21:21:20 +00:00
cy.get('i').should('contain.text', 'custom_icon');
2024-04-16 12:13:44 +00:00
});
});