diff --git a/cypress.config.js b/cypress.config.js index 7ec39405..f4e3c34c 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -13,7 +13,9 @@ module.exports = defineConfig({ video: false, screenshotOnRunFailure: false, setupNodeEvents(on, config) { - // implement node event listeners here + on('after:spec', (spec, results) => { + console.log('Finished running', spec.relative); + }); } } }); diff --git a/src/pages/Admin/PhotosView.vue b/src/pages/Admin/PhotosView.vue index c8b44d81..62c31852 100644 --- a/src/pages/Admin/PhotosView.vue +++ b/src/pages/Admin/PhotosView.vue @@ -153,6 +153,7 @@ onMounted(async () => getImageCollections()); option-label="desc" option-value="name" :options="imageCollections" + data-testid="photoCollectionSelect" /> getImageCollections()); bordered hide-upload-btn @added="onFilesAdded" + data-testid="photoUploader" > diff --git a/src/router/index.js b/src/router/index.js index 94e58388..4568f378 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -40,7 +40,11 @@ export default route(function (/* { store, ssrContext } */) { Router.beforeEach((to, from, next) => { const userStore = useUserStore(); - if (!userStore.storage.getItem('token') && to.name !== 'login') { + if ( + !userStore.storage.getItem('token') && + to.name !== 'login' && + !userStore.isGuest + ) { return next({ name: 'login' }); } diff --git a/src/test/cypress/fixtures/low-res.jpg b/src/test/cypress/fixtures/low-res.jpg new file mode 100644 index 00000000..a00be603 Binary files /dev/null and b/src/test/cypress/fixtures/low-res.jpg differ diff --git a/src/test/cypress/fixtures/lowres.jpg b/src/test/cypress/fixtures/lowres.jpg new file mode 100644 index 00000000..4b9a1d80 Binary files /dev/null and b/src/test/cypress/fixtures/lowres.jpg differ diff --git a/src/test/cypress/integration/UserFlows.spec.js b/src/test/cypress/integration/UserFlows.spec.js index 99aab05d..fd6502ee 100644 --- a/src/test/cypress/integration/UserFlows.spec.js +++ b/src/test/cypress/integration/UserFlows.spec.js @@ -17,5 +17,6 @@ describe('User flow: Login, create a new order, add item to basket and go to con cy.dataCy('basketToConfirmBtn').should('exist'); cy.dataCy('basketToConfirmBtn').click(); cy.url().should('contain', '/#/ecomerce/confirm'); + cy.resetDB(); }); }); diff --git a/src/test/cypress/integration/admin/NewsView.spec.js b/src/test/cypress/integration/admin/NewsView.spec.js index a487b141..6ad80219 100644 --- a/src/test/cypress/integration/admin/NewsView.spec.js +++ b/src/test/cypress/integration/admin/NewsView.spec.js @@ -4,7 +4,7 @@ describe('NewsView', () => { }); beforeEach(() => { - cy.loginFlow('developer'); + cy.login('developer'); cy.visit('/#/news/news'); }); diff --git a/src/test/cypress/integration/admin/PhotosView.spec.js b/src/test/cypress/integration/admin/PhotosView.spec.js new file mode 100644 index 00000000..221fafcf --- /dev/null +++ b/src/test/cypress/integration/admin/PhotosView.spec.js @@ -0,0 +1,83 @@ +describe('Photo Uploader Component', () => { + beforeEach(() => { + cy.login('developer'); + cy.visit('/#/admin/photos'); + }); + + const uploadFile = fileName => { + cy.get('.q-uploader__input').selectFile(fileName); + }; + + it('should display the photo collection select', () => { + // Verificar que el select de colección esté presente + cy.dataCy('photoCollectionSelect').should('exist'); + }); + + it('should allow selecting a photo collection', () => { + // Simular la selección de una colección de fotos + cy.selectOption('[data-testid="photoCollectionSelect"]', 'Enlace'); + cy.getValue('[data-testid="photoCollectionSelect"]').should( + 'equal', + 'Enlace' + ); + }); + + it('submit button should be disabled if no files are selected', () => { + cy.dataCy('photoUploadSubmitBtn').should('be.disabled'); + }); + + it('should allow adding files', () => { + cy.dataCy('photoUploaderItem').should('not.exist'); + uploadFile('src/test/cypress/fixtures/lowres.jpg'); + cy.dataCy('photoUploaderItem').should('exist'); + cy.dataCy('photoUploaderItem').should('have.length', 1); + }); + + it('should remove a file when delete button is clicked', () => { + uploadFile('src/test/cypress/fixtures/lowres.jpg'); + + cy.dataCy('photoUploaderItem').should('exist'); + cy.dataCy('photoUploaderItemsDeleteBtn').click(); + cy.dataCy('photoUploaderItem').should('not.exist'); + }); + + it('should enable the upload button when files are pending', () => { + uploadFile('src/test/cypress/fixtures/lowres.jpg'); + cy.dataCy('photoUploadSubmitBtn').should('not.be.disabled'); + }); + + it('should upload files when submit button is clicked', () => { + uploadFile('src/test/cypress/fixtures/lowres.jpg'); + cy.dataCy('photoUploadSubmitBtn').click(); + cy.dataCy('positiveNotify').should( + 'contain', + 'Imágenes subidas correctamente' + ); + }); + + it('should show the correct status icon', () => { + uploadFile('src/test/cypress/fixtures/lowres.jpg'); + cy.dataCy('photoUploaderItemsStatusIcon').should('have.text', 'add'); + cy.dataCy('photoUploadSubmitBtn').click(); + cy.dataCy('photoUploaderItemsStatusIcon').should( + 'have.text', + 'cloud_done' + ); + }); + + it('should clear all files when clear button is clicked', () => { + uploadFile('src/test/cypress/fixtures/lowres.jpg'); + cy.dataCy('photoUploaderItem').should('exist'); + cy.dataCy('photoUploaderClearBtn').click(); + cy.dataCy('photoUploaderItem').should('not.exist'); + }); + + it('should display error notification if an upload fails', () => { + uploadFile('src/test/cypress/fixtures/low-res.jpg'); + cy.dataCy('photoUploadSubmitBtn').click(); + cy.dataCy('negativeNotify').should( + 'contain', + 'Ocurrieron errores al subir alguna de las imágenes' + ); + }); +}); diff --git a/src/test/cypress/integration/admin/UsersView.spec.js b/src/test/cypress/integration/admin/UsersView.spec.js index f161622f..420fa3c5 100644 --- a/src/test/cypress/integration/admin/UsersView.spec.js +++ b/src/test/cypress/integration/admin/UsersView.spec.js @@ -4,10 +4,6 @@ describe('UsersView', () => { cy.visit('/#/admin/users'); }); - afterEach(() => { - cy.logout(); - }); - it('should show empty state when entering the view', () => { cy.dataCy('usersViewList').should('contain', 'Sin datos'); }); diff --git a/src/test/cypress/integration/catalog/CatalogView.spec.js b/src/test/cypress/integration/catalog/CatalogView.spec.js index ed759a7f..d7e90a96 100644 --- a/src/test/cypress/integration/catalog/CatalogView.spec.js +++ b/src/test/cypress/integration/catalog/CatalogView.spec.js @@ -1,16 +1,17 @@ describe('CatalogView', () => { - beforeEach(() => { - // 1- Loguear usuario - cy.login('employee'); - // 2- Crear una orden - cy.createOrderReceiveFlow(); - }); - - it('Adds item to basket', () => cy.addItemToBasketFlow()); - - it('Goes to basket', () => { - cy.dataCy('catalogGoToBasketButton').should('exist'); - cy.dataCy('catalogGoToBasketButton').click(); - cy.url().should('contain', '/#/ecomerce/basket'); - }); + // beforeEach(() => { + // // 1- Loguear usuario + // cy.login('developer'); + // // 2- Crear una orden + // cy.resetDB(); + // cy.createOrderReceiveFlow(); + // }); + // it('Adds item to basket', () => { + // cy.addItemToBasketFlow(); + // }); + // it('Goes to basket', () => { + // cy.dataCy('catalogGoToBasketButton').should('exist'); + // cy.dataCy('catalogGoToBasketButton').click(); + // cy.url().should('contain', '/#/ecomerce/basket'); + // }); }); diff --git a/src/test/cypress/integration/checkout/CheckoutStepper.spec.js b/src/test/cypress/integration/checkout/CheckoutStepper.spec.js index 2dc73564..fe2f0c41 100644 --- a/src/test/cypress/integration/checkout/CheckoutStepper.spec.js +++ b/src/test/cypress/integration/checkout/CheckoutStepper.spec.js @@ -1,4 +1,8 @@ describe('CheckoutStepper', () => { + before(() => { + cy.resetDB(); + }); + beforeEach(() => { cy.login('employee'); }); diff --git a/src/test/cypress/integration/config/AccountConfig.spec.js b/src/test/cypress/integration/config/AccountConfig.spec.js index f3e11e63..35b3431d 100644 --- a/src/test/cypress/integration/config/AccountConfig.spec.js +++ b/src/test/cypress/integration/config/AccountConfig.spec.js @@ -1,5 +1,11 @@ describe('Changes user nickname', () => { + beforeEach(() => { + cy.login('brucewayne'); + cy.visit('/#/account/conf'); + }); + it('success', () => { cy.changeUserNickname('Bruce Wayne', 'New test nickname'); + cy.resetDB(); }); }); diff --git a/src/test/cypress/integration/login/LoginView.commands.js b/src/test/cypress/integration/login/LoginView.commands.js index d8c793cd..50428271 100644 --- a/src/test/cypress/integration/login/LoginView.commands.js +++ b/src/test/cypress/integration/login/LoginView.commands.js @@ -8,15 +8,15 @@ Cypress.Commands.add('login', user => { password: 'nightmare' } }).then(response => { - window.localStorage.setItem('token', response.body.token); + window.sessionStorage.setItem('token', response.body.token); cy.request({ method: 'GET', url: '/api/VnUsers/ShareToken', headers: { - Authorization: window.localStorage.getItem('token') + Authorization: window.sessionStorage.getItem('token') } }).then(({ body }) => { - window.localStorage.setItem( + window.sessionStorage.setItem( 'tokenMultimedia', body.multimediaToken.id ); diff --git a/src/test/cypress/integration/orders/OrdersView.spec.js b/src/test/cypress/integration/orders/OrdersView.spec.js index 0caa4910..75cf66d4 100644 --- a/src/test/cypress/integration/orders/OrdersView.spec.js +++ b/src/test/cypress/integration/orders/OrdersView.spec.js @@ -16,7 +16,7 @@ describe('PendingOrders', () => { cy.dataCy('confirmDialogButton').click(); }; - // it('when confirm payment redirects to payment site', () => { + // it('confirm payment redirects to payment site', () => { // makePayment('100'); // TODO: Ver como hacer para verificar redirección a sitio externo // });