From a142ceb1514c08ce169d0841e926f26d1c6b65f0 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Thu, 24 Oct 2024 14:30:25 -0300 Subject: [PATCH] Create check notify commands --- src/test/cypress/integration/admin/NewsView.spec.js | 4 ++-- src/test/cypress/integration/admin/PhotosView.spec.js | 9 +++------ .../integration/catalog/CatalogView.commands.js | 2 +- .../integration/checkout/CheckoutStepper.commands.js | 10 ++-------- .../integration/checkout/CheckoutStepper.spec.js | 9 +++------ .../integration/config/AccountConfig.commands.js | 2 +- src/test/cypress/integration/login/LoginView.spec.js | 4 ++-- src/test/cypress/integration/orders/OrdersView.spec.js | 4 ++-- .../cypress/integration/orders/PendingOrders.spec.js | 7 ++----- src/test/cypress/support/commands.js | 4 ++++ 10 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/test/cypress/integration/admin/NewsView.spec.js b/src/test/cypress/integration/admin/NewsView.spec.js index 20f9daea..48f54020 100644 --- a/src/test/cypress/integration/admin/NewsView.spec.js +++ b/src/test/cypress/integration/admin/NewsView.spec.js @@ -17,7 +17,7 @@ describe('NewsView', () => { cy.dataCy('deleteNewBtn').click(); }); cy.setConfirmDialog(); - cy.dataCy('positiveNotify').should('contain', 'Datos guardados'); + cy.checkNotify('positive', 'Datos guardados'); cy.dataCy('newsCard').should('have.length', 2); }); @@ -34,7 +34,7 @@ describe('NewsView', () => { cy.get('input[data-testid="newsPriorityInput"]').type('2'); cy.dataCy('formDefaultSaveButton').should('not.be.disabled'); cy.dataCy('formDefaultSaveButton').click(); - cy.dataCy('positiveNotify').should('contain', 'Datos guardados'); + cy.checkNotify('positive', 'Datos guardados'); cy.dataCy('newsCard').should('exist'); cy.dataCy('newsCard').should('contain', 'Test new'); cy.dataCy('newsCard').should('contain', '2'); diff --git a/src/test/cypress/integration/admin/PhotosView.spec.js b/src/test/cypress/integration/admin/PhotosView.spec.js index 221fafcf..3df15fb6 100644 --- a/src/test/cypress/integration/admin/PhotosView.spec.js +++ b/src/test/cypress/integration/admin/PhotosView.spec.js @@ -49,10 +49,7 @@ describe('Photo Uploader Component', () => { 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' - ); + cy.checkNotify('positive', 'Imágenes subidas correctamente'); }); it('should show the correct status icon', () => { @@ -75,8 +72,8 @@ describe('Photo Uploader Component', () => { 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', + cy.checkNotify( + 'negative', 'Ocurrieron errores al subir alguna de las imágenes' ); }); diff --git a/src/test/cypress/integration/catalog/CatalogView.commands.js b/src/test/cypress/integration/catalog/CatalogView.commands.js index 3b89444f..45c4a602 100644 --- a/src/test/cypress/integration/catalog/CatalogView.commands.js +++ b/src/test/cypress/integration/catalog/CatalogView.commands.js @@ -18,5 +18,5 @@ Cypress.Commands.add('addItemToBasketFlow', () => { cy.get('[data-testid="addItemQuantityButton"]:first').click(); cy.dataCy('catalogAddToBasketButton').should('exist'); cy.dataCy('catalogAddToBasketButton').click(); - cy.dataCy('positiveNotify').should('contain', 'Añadido'); + cy.checkNotify('positive', 'Añadido'); }); diff --git a/src/test/cypress/integration/checkout/CheckoutStepper.commands.js b/src/test/cypress/integration/checkout/CheckoutStepper.commands.js index cb6ea823..f9ae426c 100644 --- a/src/test/cypress/integration/checkout/CheckoutStepper.commands.js +++ b/src/test/cypress/integration/checkout/CheckoutStepper.commands.js @@ -40,10 +40,7 @@ Cypress.Commands.add('createOrderReceiveFlow', () => { cy.dataCy('pendingOrdersNewOrder').should('exist'); cy.dataCy('pendingOrdersNewOrder').click(); cy.createOrderReceive(); - cy.dataCy('positiveNotify').should( - 'contain', - '¡Pedido cargado en la cesta!' - ); + cy.checkNotify('positive', '¡Pedido cargado en la cesta!'); }); Cypress.Commands.add('createOrderPickup', () => { @@ -84,8 +81,5 @@ Cypress.Commands.add('createOrderPickupFlow', (changeLanguage = false) => { cy.dataCy('pendingOrdersNewOrder').should('exist'); cy.dataCy('pendingOrdersNewOrder').click(); cy.createOrderPickup(); - cy.dataCy('positiveNotify').should( - 'contain', - '¡Pedido cargado en la cesta!' - ); + cy.checkNotify('positive', '¡Pedido cargado en la cesta!'); }); diff --git a/src/test/cypress/integration/checkout/CheckoutStepper.spec.js b/src/test/cypress/integration/checkout/CheckoutStepper.spec.js index fe2f0c41..82fd4fe1 100644 --- a/src/test/cypress/integration/checkout/CheckoutStepper.spec.js +++ b/src/test/cypress/integration/checkout/CheckoutStepper.spec.js @@ -14,14 +14,11 @@ describe('CheckoutStepper', () => { it('Modifies an order', () => { cy.createOrderReceiveFlow(); cy.dataCy('orderModifyButton').click(); - cy.dataCy('warningNotify').should( - 'include.text', + cy.checkNotify( + 'warning', 'Recuerda que si vuelves a configurar el pedido los precios o cantidades de tus artículos podrían cambiar' ); cy.createOrderPickup(false); - cy.dataCy('positiveNotify').should( - 'include.text', - 'Pedido actualizado' - ); + cy.checkNotify('positive', 'Pedido actualizado'); }); }); diff --git a/src/test/cypress/integration/config/AccountConfig.commands.js b/src/test/cypress/integration/config/AccountConfig.commands.js index 3f7b3d22..6da15d71 100644 --- a/src/test/cypress/integration/config/AccountConfig.commands.js +++ b/src/test/cypress/integration/config/AccountConfig.commands.js @@ -8,5 +8,5 @@ Cypress.Commands.add('changeUserNickname', (oldNickname, newNickname) => { cy.get(nicknameInput).clear(); cy.get(nicknameInput).type(newNickname); cy.get(nicknameInput).blur(); - cy.dataCy('positiveNotify').should('contain', 'Datos guardados'); + cy.checkNotify('positive', 'Datos guardados'); }); diff --git a/src/test/cypress/integration/login/LoginView.spec.js b/src/test/cypress/integration/login/LoginView.spec.js index 7245fcd3..b180ce92 100644 --- a/src/test/cypress/integration/login/LoginView.spec.js +++ b/src/test/cypress/integration/login/LoginView.spec.js @@ -25,14 +25,14 @@ describe('Login Tests', () => { cy.dataCy('loginUserInput').type('incorrectUser'); cy.dataCy('loginPasswordInput').type('nightmare'); cy.get('button[type="submit"]').click(); - cy.dataCy('negativeNotify').should('contain', 'login failed'); + cy.checkNotify('negative', 'login failed'); }); it('should fail to log in using wrong password', () => { cy.dataCy('loginUserInput').type('incorrectUser'); cy.dataCy('loginPasswordInput').type('nightmare'); cy.get('button[type="submit"]').click(); - cy.dataCy('negativeNotify').should('contain', 'login failed'); + cy.checkNotify('negative', 'login failed'); }); it('should log in', () => { diff --git a/src/test/cypress/integration/orders/OrdersView.spec.js b/src/test/cypress/integration/orders/OrdersView.spec.js index 20989018..22af8b8f 100644 --- a/src/test/cypress/integration/orders/OrdersView.spec.js +++ b/src/test/cypress/integration/orders/OrdersView.spec.js @@ -23,8 +23,8 @@ describe('PendingOrders', () => { it('fails payment if pay amount is 0', () => { cy.visit('/#/ecomerce/orders'); makePayment(0); - cy.dataCy('negativeNotify').should( - 'contain', + cy.checkNotify( + 'negative', 'La cantidad debe ser un número positivo e inferior o igual al importe pendiente' ); }); diff --git a/src/test/cypress/integration/orders/PendingOrders.spec.js b/src/test/cypress/integration/orders/PendingOrders.spec.js index 37c7e214..1c2ed688 100644 --- a/src/test/cypress/integration/orders/PendingOrders.spec.js +++ b/src/test/cypress/integration/orders/PendingOrders.spec.js @@ -41,7 +41,7 @@ describe('PendingOrders', () => { cy.dataCy('pendingOrderCard').should('have.length', 1); cy.dataCy('pendingOrderCardDelete').click(); cy.setConfirmDialog(); - cy.dataCy('positiveNotify').should('contain', 'Datos guardados'); + cy.checkNotify('positive', 'Datos guardados'); checkEmptyList(); }); @@ -50,9 +50,6 @@ describe('PendingOrders', () => { cy.visit('/#/ecomerce/pending'); cy.dataCy('addOrderToBasket').should('exist'); cy.dataCy('addOrderToBasket').click(); - cy.dataCy('positiveNotify').should( - 'contain', - '¡Pedido cargado en la cesta!' - ); + cy.checkNotify('positive', '¡Pedido cargado en la cesta!'); }); }); diff --git a/src/test/cypress/support/commands.js b/src/test/cypress/support/commands.js index d7daab2c..b4ec3d42 100644 --- a/src/test/cypress/support/commands.js +++ b/src/test/cypress/support/commands.js @@ -87,3 +87,7 @@ Cypress.Commands.add('setConfirmDialog', () => { cy.dataCy('confirmDialogButton').should('exist'); cy.dataCy('confirmDialogButton').click(); }); + +Cypress.Commands.add('checkNotify', (status, content) => { + cy.dataCy(`${status}Notify`).should('contain', content); +});