diff --git a/src/test/cypress/integration/catalog/CatalogView.spec.js b/src/test/cypress/integration/catalog/CatalogView.spec.js index 5969db9d..a01a0062 100644 --- a/src/test/cypress/integration/catalog/CatalogView.spec.js +++ b/src/test/cypress/integration/catalog/CatalogView.spec.js @@ -1,4 +1,38 @@ describe('CatalogView', () => { + before(() => { + cy.resetDB(); + }); + + beforeEach(() => { + cy.login('developer'); + }); + + it('if there is no pending order created and we go to catalog, it should return checkout view', () => { + cy.visit('/#/ecomerce/pending'); + // Comprobamos que no existe ninguna orden pendiente + cy.dataCy('pendingOrdersList').should('contain', 'Lista vacía'); + // Visitamos el catalogo + cy.visit('/#/ecomerce/catalog'); + // Debería redirigirnos al checkout + cy.url().should('contain', '/#/ecomerce/checkout'); + }); + + it('if there is a pending order created and we somehow remove order from basket it should return pending orders view', () => { + cy.createOrderReceiveFlow(); + // Una manera de perder la información de la orden es deslogueando + cy.logoutFlow(); + // Volvemos a loguear con el mismo usuario + cy.loginFlow('developer'); + // Visitamos catalog + cy.visit('/#/ecomerce/catalog'); + // Debería redirigirnos a pending orders con un mensaje de advertencia + cy.url().should('contain', '/#/ecomerce/pending'); + cy.checkNotify( + 'warning', + 'Por favor carga un pedido pendiente en la cesta o empieza uno nuevo' + ); + }); + it('Adds item to basket and goes to basket', () => { cy.resetDB(); cy.login('developer'); diff --git a/src/test/cypress/integration/login/LoginView.commands.js b/src/test/cypress/integration/login/LoginView.commands.js index 50428271..1e3ccdd8 100644 --- a/src/test/cypress/integration/login/LoginView.commands.js +++ b/src/test/cypress/integration/login/LoginView.commands.js @@ -63,3 +63,8 @@ Cypress.Commands.add('changeLanguageFlow', language => { cy.visit('/#/login'); cy.changeLanguage(language); }); + +Cypress.Commands.add('logoutFlow', language => { + cy.dataCy('logoutButton').should('exist'); + cy.dataCy('logoutButton').click(); +});