Several changes and more tests
gitea/hedera-web/pipeline/pr-4922-vueMigration This commit looks good Details

This commit is contained in:
William Buezas 2024-10-17 16:34:23 -03:00
parent 62349278ed
commit 693b309e79
12 changed files with 221 additions and 164 deletions

View File

@ -3,8 +3,8 @@ describe('User flow: Login, create a new order, add item to basket', () => {
// 2- Loguear como empleado // 2- Loguear como empleado
cy.login('employee'); cy.login('employee');
// 2- Crear una orden // 2- Crear una orden
cy.CreateOrderReceiveFlow(); cy.createOrderReceiveFlow();
// 3- Filtrar items y agregar item al carrito // 3- Filtrar items y agregar item al carrito
cy.AddItemToBasketFlow(); cy.addItemToBasketFlow();
}); });
}); });

View File

@ -0,0 +1,22 @@
Cypress.Commands.add('addItemToBasketFlow', () => {
// 1- Seleccionar categoría
cy.dataCy('catalogCategoryButton').should('exist');
cy.get('[data-testid="catalogCategoryButton"]:first').click();
// 2- Seleccionar familia
cy.dataCy('catalogFamilySelect').should('exist');
cy.selectOption('[data-testid="catalogFamilySelect"]', 'Anthurium');
cy.getValue('[data-testid="catalogFamilySelect"]').should(
'equal',
'Anthurium'
);
cy.dataCy('catalogFamilySelect').should('exist');
// 3- Seleccionar item
cy.dataCy('catalogCardGridBody').should('exist');
cy.get('[data-testid="catalogCardGridBody"]:first').click();
// 4- Añadir item al carrito
cy.dataCy('addItemQuantityButton').should('exist');
cy.get('[data-testid="addItemQuantityButton"]:first').click();
cy.dataCy('catalogAddToBasketButton').should('exist');
cy.dataCy('catalogAddToBasketButton').click();
cy.dataCy('positiveNotify').should('contain', 'Añadido');
});

View File

@ -3,14 +3,14 @@ describe('CatalogView', () => {
// 1- Loguear usuario // 1- Loguear usuario
cy.login('employee'); cy.login('employee');
// 2- Crear una orden // 2- Crear una orden
cy.CreateOrderReceiveFlow(); cy.createOrderReceiveFlow();
}); });
it('Adds item to basket', () => cy.AddItemToBasketFlow()); it('Adds item to basket', () => cy.addItemToBasketFlow());
it('Goes to basket', () => { it('Goes to basket', () => {
cy.get('[data-testid="catalogGoToBasketButton"]').should('exist'); cy.dataCy('catalogGoToBasketButton').should('exist');
cy.get('[data-testid="catalogGoToBasketButton"]').click(); cy.dataCy('catalogGoToBasketButton').click();
cy.url().should('contain', '/#/ecomerce/basket'); cy.url().should('contain', '/#/ecomerce/basket');
}); });
}); });

View File

@ -1,22 +0,0 @@
Cypress.Commands.add('AddItemToBasketFlow', () => {
// 1- Seleccionar categoría
cy.get('[data-testid="catalogCategoryButton"]').should('exist');
cy.get('[data-testid="catalogCategoryButton"]:first').click();
// 2- Seleccionar familia
cy.get('[data-testid="catalogFamilySelect"]').should('exist');
cy.selectOption('[data-testid="catalogFamilySelect"]', 'Anthurium');
cy.getValue('[data-testid="catalogFamilySelect"]').should(
'equal',
'Anthurium'
);
cy.get('[data-testid="catalogFamilySelect"]').should('exist');
// 3- Seleccionar item
cy.get('[data-testid="catalogCardGridBody"]').should('exist');
cy.get('[data-testid="catalogCardGridBody"]:first').click();
// 4- Añadir item al carrito
cy.get('[data-testid="addItemQuantityButton"]').should('exist');
cy.get('[data-testid="addItemQuantityButton"]:first').click();
cy.get('[data-testid="catalogAddToBasketButton"]').should('exist');
cy.get('[data-testid="catalogAddToBasketButton"]').click();
cy.get('[data-testid="positiveNotify"]').should('include.text', 'Añadido');
});

View File

@ -0,0 +1,91 @@
const checkoutNextStep = () => {
cy.dataCy('checkoutStepperRightButton').should('be.visible').click();
};
Cypress.Commands.add('createOrderReceive', () => {
cy.dataCy('checkoutStepper').should('exist');
cy.dataCy('checkoutStepper').should(
'contain',
'¿Quieres recibir o recoger el pedido?'
);
cy.dataCy('Recibir en mi tienda', 'aria-label').click();
checkoutNextStep();
cy.dataCy('checkoutStepper').should(
'contain',
'¿Qué día quieres recibir el pedido?'
);
checkoutNextStep();
cy.dataCy('checkoutStepper').should(
'contain',
'¿Dónde quieres recibir el pedido?'
);
cy.dataCy('checkoutAddressStep').within(() => {
cy.get('label:first').click();
});
checkoutNextStep();
cy.dataCy('checkoutStepper').should(
'contain',
'¿Cómo quieres recibir el pedido?'
);
cy.dataCy('agencyStepSelect').should('exist');
cy.selectOption('[data-testid="agencyStepSelect"]', 'Other agency');
checkoutNextStep();
checkoutNextStep();
cy.url().should('contain', '/#/ecomerce/catalog');
});
Cypress.Commands.add('createOrderReceiveFlow', () => {
cy.visit('/#/ecomerce/pending');
cy.dataCy('pendingOrdersNewOrder').should('exist');
cy.dataCy('pendingOrdersNewOrder').click();
cy.createOrderReceive();
cy.dataCy('positiveNotify').should(
'contain',
'¡Pedido cargado en la cesta!'
);
});
Cypress.Commands.add('createOrderPickup', () => {
cy.dataCy('checkoutStepper').should('exist');
cy.dataCy('checkoutStepper').should(
'contain',
'¿Quieres recibir o recoger el pedido?'
);
cy.dataCy('Recoger en almacén', 'aria-label').click();
checkoutNextStep();
cy.dataCy('checkoutStepper').should(
'contain',
'¿Qué día quieres recibir el pedido?'
);
checkoutNextStep();
cy.dataCy('checkoutStepper').should(
'contain',
'¿A qué dirección quieres asociar el pedido? (Opcional)'
);
cy.dataCy('checkoutAddressStep').within(() => {
cy.get('label:first').click();
});
checkoutNextStep();
cy.dataCy('checkoutStepper').should(
'contain',
'¿En qué almacén quieres recoger tu pedido?'
);
cy.dataCy('pickupStepSelect').should('exist');
cy.selectOption('[data-testid="pickupStepSelect"]', 'Teleportation device');
checkoutNextStep();
checkoutNextStep();
cy.url().should('contain', '/#/ecomerce/catalog');
});
Cypress.Commands.add('createOrderPickupFlow', (changeLanguage = false) => {
if (changeLanguage) cy.changeLanguageFlow('es');
cy.visit('/#/ecomerce/pending');
cy.dataCy('pendingOrdersNewOrder').should('exist');
cy.dataCy('pendingOrdersNewOrder').click();
cy.createOrderPickup();
cy.dataCy('positiveNotify').should(
'contain',
'¡Pedido cargado en la cesta!'
);
});

View File

@ -3,19 +3,19 @@ describe('CheckoutStepper', () => {
cy.login('employee'); cy.login('employee');
}); });
it('Creates new order to receive', () => cy.CreateOrderReceiveFlow()); it('Creates new order to receive', () => cy.createOrderReceiveFlow());
it('Creates new pickup order', () => cy.CreateOrderPickupFlow()); it('Creates new pickup order', () => cy.createOrderPickupFlow());
it('Modifies an order', () => { it('Modifies an order', () => {
cy.CreateOrderReceiveFlow(); cy.createOrderReceiveFlow();
cy.get('[data-testid="orderModifyButton"]').click(); cy.dataCy('orderModifyButton').click();
cy.get('[data-testid="warningNotify"]').should( cy.dataCy('warningNotify').should(
'include.text', 'include.text',
'Recuerda que si vuelves a configurar el pedido los precios o cantidades de tus artículos podrían cambiar' 'Recuerda que si vuelves a configurar el pedido los precios o cantidades de tus artículos podrían cambiar'
); );
cy.CreateOrderPickup(false); cy.createOrderPickup(false);
cy.get('[data-testid="positiveNotify"]').should( cy.dataCy('positiveNotify').should(
'include.text', 'include.text',
'Pedido actualizado' 'Pedido actualizado'
); );

View File

@ -1,95 +0,0 @@
const checkoutNextStep = () => {
cy.get('[data-testid="checkoutStepperRightButton"]')
.should('be.visible')
.click();
};
Cypress.Commands.add('CreateOrderReceive', () => {
cy.get('[data-testid="checkoutStepper"]').should('exist');
cy.get('[data-testid="checkoutStepper"]').should(
'contain',
'¿Quieres recibir o recoger el pedido?'
);
cy.get('[aria-label="Recibir en mi tienda"]').click();
checkoutNextStep();
cy.get('[data-testid="checkoutStepper"]').should(
'contain',
'¿Qué día quieres recibir el pedido?'
);
checkoutNextStep();
cy.get('[data-testid="checkoutStepper"]').should(
'contain',
'¿Dónde quieres recibir el pedido?'
);
cy.get('[data-testid="checkoutAddressStep"]').within(() => {
cy.get('label:first').click();
});
checkoutNextStep();
cy.get('[data-testid="checkoutStepper"]').should(
'contain',
'¿Cómo quieres recibir el pedido?'
);
cy.get('[data-testid="agencyStepSelect"]').should('exist');
cy.selectOption('[data-testid="agencyStepSelect"]', 'Other agency');
checkoutNextStep();
checkoutNextStep();
cy.url().should('contain', '/#/ecomerce/catalog');
});
Cypress.Commands.add('CreateOrderReceiveFlow', (changeLanguage = false) => {
if (changeLanguage) cy.changeLanguageFlow('es');
cy.visit('/#/ecomerce/pending');
cy.get('[data-testid="pendingOrdersNewOrder"]').should('exist');
cy.get('[data-testid="pendingOrdersNewOrder"]').click();
cy.CreateOrderReceive();
cy.get('.q-notification__message:first').should(
'have.text',
'¡Pedido cargado en la cesta!'
);
});
Cypress.Commands.add('CreateOrderPickup', () => {
cy.get('[data-testid="checkoutStepper"]').should('exist');
cy.get('[data-testid="checkoutStepper"]').should(
'contain',
'¿Quieres recibir o recoger el pedido?'
);
cy.get('[aria-label="Recoger en almacén"]').click();
checkoutNextStep();
cy.get('[data-testid="checkoutStepper"]').should(
'contain',
'¿Qué día quieres recibir el pedido?'
);
checkoutNextStep();
cy.get('[data-testid="checkoutStepper"]').should(
'contain',
'¿A qué dirección quieres asociar el pedido? (Opcional)'
);
cy.get('[data-testid="checkoutAddressStep"]').within(() => {
cy.get('label:first').click();
});
checkoutNextStep();
cy.get('[data-testid="checkoutStepper"]').should(
'contain',
'¿En qué almacén quieres recoger tu pedido?'
);
cy.get('[data-testid="pickupStepSelect"]').should('exist');
cy.selectOption('[data-testid="pickupStepSelect"]', 'Teleportation device');
checkoutNextStep();
checkoutNextStep();
cy.url().should('contain', '/#/ecomerce/catalog');
});
Cypress.Commands.add('CreateOrderPickupFlow', (changeLanguage = false) => {
if (changeLanguage) cy.changeLanguageFlow('es');
cy.visit('/#/ecomerce/pending');
cy.get('[data-testid="pendingOrdersNewOrder"]').should('exist');
cy.get('[data-testid="pendingOrdersNewOrder"]').click();
cy.CreateOrderPickup();
cy.get('.q-notification__message:first').should(
'have.text',
'¡Pedido cargado en la cesta!'
);
});

View File

@ -39,9 +39,9 @@ Cypress.Commands.add('logout', user => {
Cypress.Commands.add('loginFlow', (user, visitLogin = true) => { Cypress.Commands.add('loginFlow', (user, visitLogin = true) => {
if (visitLogin) cy.visit('/#/login'); if (visitLogin) cy.visit('/#/login');
cy.get('[data-testid="loginUserInput"]').type(user); cy.dataCy('loginUserInput').type(user);
cy.getValue('[data-testid="loginUserInput"]').should('equal', user); cy.getValue('[data-testid="loginUserInput"]').should('equal', user);
cy.get('[data-testid="loginPasswordInput"]').type('nightmare'); cy.dataCy('loginPasswordInput').type('nightmare');
cy.getValue('[data-testid="loginPasswordInput"]').should( cy.getValue('[data-testid="loginPasswordInput"]').should(
'equal', 'equal',
'nightmare' 'nightmare'
@ -55,7 +55,7 @@ Cypress.Commands.add('changeLanguage', language => {
const languagesOrder = ['en', 'es', 'ca', 'fr', 'pt']; const languagesOrder = ['en', 'es', 'ca', 'fr', 'pt'];
const index = languagesOrder.indexOf(language); const index = languagesOrder.indexOf(language);
cy.waitForElement('[data-testid="switchLanguage"]'); cy.waitForElement('[data-testid="switchLanguage"]');
cy.get('[data-testid="switchLanguage"]').click(); cy.dataCy('switchLanguage').click();
cy.get('.q-menu .q-item').eq(index).click(); // Selecciona y hace clic en el tercer elemento "index" de la lista cy.get('.q-menu .q-item').eq(index).click(); // Selecciona y hace clic en el tercer elemento "index" de la lista
}); });

View File

@ -1,24 +1,20 @@
describe('Login Tests', () => { describe('Login Tests', () => {
const rememberCheckbox = '[data-testid="rememberCheckbox"]';
beforeEach(() => { beforeEach(() => {
cy.visit('/#/login'); cy.visit('/#/login');
}); });
it('should toggle password visibility', () => { it('should toggle password visibility', () => {
cy.get('[data-testid="showPasswordIcon"]').should('exist'); cy.dataCy('showPasswordIcon').should('exist');
cy.get('[data-testid="showPasswordIcon"]').click(); cy.dataCy('showPasswordIcon').click();
cy.get('[data-testid="showPasswordIcon"]').should( cy.dataCy('showPasswordIcon').should('have.text', 'visibility_off');
'have.text', cy.dataCy('showPasswordIcon').click();
'visibility_off' cy.dataCy('showPasswordIcon').should('have.text', 'visibility');
);
cy.get('[data-testid="showPasswordIcon"]').click();
cy.get('[data-testid="showPasswordIcon"]').should(
'have.text',
'visibility'
);
}); });
it('should select a language from the dropdown', () => { it('should select a language from the dropdown', () => {
cy.get('[data-testid="switchLanguage"]').should('exist'); cy.dataCy('switchLanguage').should('exist');
cy.changeLanguage('en'); cy.changeLanguage('en');
cy.get('button[type="submit"]').should('contain', 'Log in'); cy.get('button[type="submit"]').should('contain', 'Log in');
cy.changeLanguage('es'); cy.changeLanguage('es');
@ -26,23 +22,17 @@ describe('Login Tests', () => {
}); });
it('should fail to log in using wrong user', () => { it('should fail to log in using wrong user', () => {
cy.get('[data-testid="loginUserInput"]').type('incorrectUser'); cy.dataCy('loginUserInput').type('incorrectUser');
cy.get('[data-testid="loginPasswordInput"]').type('nightmare'); cy.dataCy('loginPasswordInput').type('nightmare');
cy.get('button[type="submit"]').click(); cy.get('button[type="submit"]').click();
cy.get('.q-notification__message:first').should( cy.dataCy('negativeNotify').should('contain', 'login failed');
'have.text',
'login failed'
);
}); });
it('should fail to log in using wrong password', () => { it('should fail to log in using wrong password', () => {
cy.get('[data-testid="loginUserInput"]').type('incorrectUser'); cy.dataCy('loginUserInput').type('incorrectUser');
cy.get('[data-testid="loginPasswordInput"]').type('nightmare'); cy.dataCy('loginPasswordInput').type('nightmare');
cy.get('button[type="submit"]').click(); cy.get('button[type="submit"]').click();
cy.get('.q-notification__message:first').should( cy.dataCy('negativeNotify').should('contain', 'login failed');
'have.text',
'login failed'
);
}); });
it('should log in', () => { it('should log in', () => {
@ -50,8 +40,52 @@ describe('Login Tests', () => {
}); });
it('should log in as guest', () => { it('should log in as guest', () => {
cy.get('[data-testid="loginAsGuestButton"]').should('exist'); cy.dataCy('loginAsGuestButton').should('exist');
cy.get('[data-testid="loginAsGuestButton"]').click(); cy.dataCy('loginAsGuestButton').click();
cy.url().should('contain', '/#/cms/home'); cy.url().should('contain', '/#/cms/home');
}); });
it('should save localStorage keepLogin true value if remember checkbox is checked', () => {
cy.dataCy('rememberCheckbox').should('exist');
cy.dataCy('rememberCheckbox').click();
cy.getValue(rememberCheckbox).should('equal', 'true');
cy.loginFlow('employee', false);
cy.window().then(window => {
expect(window.localStorage.getItem('keepLogin')).to.eq('true');
});
});
it('should save localStorage keepLogin false value if remember checkbox is not checked', () => {
cy.dataCy('rememberCheckbox').should('exist');
cy.getValue(rememberCheckbox).should('equal', 'false');
cy.loginFlow('employee', false);
cy.window().then(window => {
expect(window.localStorage.getItem('keepLogin')).to.eq('false');
});
});
it('saves data in session storage if remember is not checked', () => {
cy.dataCy('rememberCheckbox').should('exist');
cy.getValue(rememberCheckbox).should('equal', 'false');
cy.loginFlow('employee', false);
cy.window().then(window => {
expect(window.sessionStorage.getItem('hederaLastUser')).to.eq(
'employee'
);
expect(window.localStorage.getItem('hederaLastUser')).to.eq(null);
});
});
it('saves data in local storage if remember is checked', () => {
cy.dataCy('rememberCheckbox').should('exist');
cy.dataCy('rememberCheckbox').click();
cy.getValue(rememberCheckbox).should('equal', 'true');
cy.loginFlow('employee', false);
cy.window().then(window => {
expect(window.localStorage.getItem('hederaLastUser')).to.eq(
'employee'
);
expect(window.sessionStorage.getItem('hederaLastUser')).to.eq(null);
});
});
}); });

View File

@ -24,9 +24,14 @@
// -- This will overwrite an existing command -- // -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
import '../integration/catalog/CatalogViewCommands'; // CatalogView component commands // Importar dinámicamente todos los archivos con el sufijo .commands.js dentro de la carpeta src/test/cypress/integration
import '../integration/login/LoginViewCommands'; // LoginView component commands const requireCommands = require.context(
import '../integration/checkout/CheckoutStepperCommands'; // CheckoutStepper component commands '../integration',
true,
/\.commands\.js$/
);
// Iterar sobre cada archivo y requerirlo
requireCommands.keys().forEach(requireCommands);
// Common commands // Common commands
Cypress.Commands.add('selectOption', (selector, option) => { Cypress.Commands.add('selectOption', (selector, option) => {
@ -49,3 +54,17 @@ Cypress.Commands.add('getValue', selector => {
Cypress.Commands.add('waitForElement', (element, timeout = 5000) => { Cypress.Commands.add('waitForElement', (element, timeout = 5000) => {
cy.get(element, { timeout }).should('be.visible'); cy.get(element, { timeout }).should('be.visible');
}); });
Cypress.Commands.add('dataCy', (dataTestId, attr = 'data-testid') => {
return cy.get(`[${attr}="${dataTestId}"]`);
});
Cypress.Commands.add('getSessionStorage', key => {
cy.window().then(window => window.sessionStorage.getItem(key));
});
Cypress.Commands.add('setSessionStorage', (key, value) => {
cy.window().then(window => {
window.sessionStorage.setItem(key, value);
});
});

View File

@ -14,7 +14,7 @@
// *********************************************************** // ***********************************************************
// Import commands.js using ES2015 syntax: // Import commands.js using ES2015 syntax:
import './commands' import './commands';
// Alternatively you can use CommonJS syntax: // Alternatively you can use CommonJS syntax:
// require('./commands') // require('./commands')

View File

@ -14,3 +14,11 @@
// *********************************************************** // ***********************************************************
import './commands'; import './commands';
/* eslint-disable */
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false;
});
/* eslint-enable */