salix-front/test/cypress/components/ui/VnSms.spec.js

70 lines
2.2 KiB
JavaScript

// VnSms.spec.js
import VnSms from 'src/components/common/VnSms.vue';
describe.only('<VnSms />', () => {
beforeEach(() => {
// Stub axios to prevent real HTTP requests
cy.stub(window, 'axios').as('axiosStub');
});
it('renders without errors', () => {
cy.createWrapper(VnSms);
cy.get('.vn-sms').should('exist');
});
it('computes the correct filter based on props', () => {
const whereProp = { status: 'delivered' };
cy.createWrapper(VnSms, {
props: {
where: whereProp,
},
});
cy.wrap(Cypress.vueWrapper.setupState.filter).then((filter) => {
expect(filter.value.where).to.deep.equal(whereProp);
expect(filter.value.fields).to.include('smsFk');
expect(filter.value.include.relation).to.equal('sms');
});
});
it('displays SMS data correctly', () => {
const smsData = [
{
smsFk: 1,
sms: {
senderFk: 1,
sender: 'Jane Smith',
destination: '+1234567890',
message: 'Test message content',
statusCode: 'sent',
status: 'Sent',
created: '2023-10-10T10:00:00Z',
// sender: {
// name: 'Jane Smith',
// },
},
},
];
cy.intercept('GET', '**/api/**', { body: smsData }).as('getSmsData');
cy.createWrapper(VnSms);
cy.wait('@getSmsData');
cy.get('.sms-message').should('contain', 'Test message content');
cy.get('.sms-destination').should('contain', '+1234567890');
});
it('handles pagination through VnPaginate', () => {
cy.createWrapper(VnSms);
cy.get('.vn-paginate').should('exist');
cy.get('.paginate-next').click();
cy.get('@axiosStub').should('have.been.called');
});
it('renders VnAvatar and VnUserLink components', () => {
cy.createWrapper(VnSms);
cy.getComponent('VnAvatar').should('exist');
cy.getComponent('VnUserLink').should('exist');
});
});