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

84 lines
2.9 KiB
JavaScript
Raw Normal View History

2024-10-18 11:51:41 +00:00
import axios from 'axios';
2024-05-28 09:38:09 +00:00
import CreateBankEntityForm from 'src/components/CreateBankEntityForm.vue';
2024-10-18 11:51:41 +00:00
import { useArrayData } from 'src/composables/useArrayData';
import { useArrayDataStore } from 'src/stores/useArrayDataStore';
2024-05-28 09:38:09 +00:00
2024-10-18 11:51:41 +00:00
// import { useRouter } from 'vue-router';
// import vueRouter from 'vue-router';
2024-05-28 09:38:09 +00:00
describe('<CreateBankEntityForm />', () => {
2024-10-18 11:51:41 +00:00
const mockApiResponse = { results: [{ id: 1, name: 'Test' }] };
const arrayDataStore = useArrayDataStore();
const mockStoreData = { filter: {}, userFilter: {}, userParams: {}, url: 'mockUrl' };
before(() => {
cy.login('developer');
// cy.stub(arrayDataStore, 'get').callsFake(() => 'asd');
cy.stub(arrayDataStore, 'get')
.callsFake((e, fn) => (e = fn))
.as('update');
const arrayData = useArrayData('ArrayData', { url: 'mockUrl' });
cy.stub(arrayData).callsFake(() => ({
userParams: {},
userFilter: {},
order: {},
searchUrl: 'searchUrl',
}));
// cy.stub(vueRouter, 'useRouter').callsFake(() => ({
// push: () => {},
// replace: () => {},
// currentRoute: {
// value: {
// params: {
// id: 1,
// },
// meta: { moduleName: 'mockName' },
// matched: [{ path: 'mockName/list' }],
// },
// },
// }));
});
beforeEach(() => {
// Stub del método get del store
// cy.spy(useRouter(), 'replace');
// cy.spy(useRouter(), 'push');
});
it('should intercept axios.get for a specific route', () => {
// Intercepta la llamada a axios.get para una ruta específica
cy.stub(axios, 'get')
.callsFake((url, params) => {
if (url === 'Countries') {
return Promise.resolve({ data: mockApiResponse });
}
// Si la URL no coincide, llama al método original
return axios.get.wrappedMethod(url, params);
})
.as('axiosStub');
const onFetchSpy = cy.spy().as('onFetchSpy');
cy.createWrapper(CreateBankEntityForm, {
props: {
showEntityField: true,
},
attrs: {
onFetch: onFetchSpy,
},
});
cy.get('@axiosStub').should((spy) => {
expect(spy).to.have.been.calledWith('Countries');
});
cy.get('@onFetchSpy').should((spy) => {
expect(spy).to.have.been.calledWith(mockApiResponse);
});
// Verifica que los datos emitidos por el hijo son manejados por el padre
// cy.get('p').should('contain', 'Datos recibidos:'); // Verifica que los datos se muestran en el DOM
// cy.get('p').should('contain', 'Test'); // Verifica que el contenido de los datos es correcto
2024-05-28 09:38:09 +00:00
});
});