2022-03-11 13:05:16 +00:00
|
|
|
// ***********************************************
|
|
|
|
// This example commands.js shows you how to
|
|
|
|
// create various custom commands and overwrite
|
|
|
|
// existing commands.
|
|
|
|
//
|
|
|
|
// For more comprehensive examples of custom
|
|
|
|
// commands please read more here:
|
|
|
|
// https://on.cypress.io/custom-commands
|
|
|
|
// ***********************************************
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a parent command --
|
|
|
|
// Cypress.Commands.add("login", (email, password) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a child command --
|
|
|
|
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a dual command --
|
|
|
|
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is will overwrite an existing command --
|
|
|
|
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
|
|
|
|
|
|
|
// DO NOT REMOVE
|
|
|
|
// Imports Quasar Cypress AE predefined commands
|
2022-12-21 08:19:29 +00:00
|
|
|
// import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress';
|
2022-05-23 13:46:09 +00:00
|
|
|
Cypress.Commands.add('login', (user) => {
|
2023-02-24 11:51:29 +00:00
|
|
|
//cy.visit('/#/login');
|
2022-05-23 13:46:09 +00:00
|
|
|
cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/api/accounts/login',
|
|
|
|
body: {
|
|
|
|
user: user,
|
2022-12-21 08:19:29 +00:00
|
|
|
password: 'nightmare',
|
|
|
|
},
|
|
|
|
}).then((response) => {
|
2022-05-23 13:46:09 +00:00
|
|
|
window.localStorage.setItem('token', response.body.token);
|
2022-12-21 08:19:29 +00:00
|
|
|
});
|
|
|
|
});
|
2023-08-21 13:14:19 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('selectOption', (option) => {
|
|
|
|
//cy.visit('/#/login');
|
|
|
|
cy.get('.q-item__label').then(() => {
|
|
|
|
cy.contains('.q-item__label', option).click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Cypress.Commands.add('fillRow', (row, options) => {
|
|
|
|
// //cy.visit('/#/login');
|
|
|
|
// for (let [i, option] of options.entries()) {
|
|
|
|
// i++;
|
|
|
|
// console.log(i);
|
|
|
|
// const selector = `tbody > :nth-child(${row}) > :nth-child(${i})`;
|
|
|
|
// if (cy.get(selector).should('have.class', 'q-select'))
|
|
|
|
// cy.selectOption(selector, option);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
Cypress.Commands.add('fillTableRow', (rowNumber, data) => {
|
|
|
|
// Obtener todas las filas de la tabla
|
|
|
|
cy.get('table tbody tr').eq(rowNumber).as('currentRow');
|
|
|
|
|
|
|
|
// Iterar sobre cada dato en el array 'data'
|
|
|
|
data.forEach((value, index) => {
|
|
|
|
// Basándonos en el índice, encontramos la celda correspondiente y verificamos el tipo de input
|
|
|
|
cy.get('@currentRow')
|
|
|
|
.find('td')
|
|
|
|
.eq(index)
|
|
|
|
.find('input')
|
|
|
|
.invoke('attr', 'type')
|
|
|
|
.then((type) => {
|
|
|
|
switch (type) {
|
|
|
|
case 'text':
|
|
|
|
cy.get('@currentRow')
|
|
|
|
.find('td')
|
|
|
|
.eq(index)
|
|
|
|
.find('input[type="text"]')
|
|
|
|
.clear()
|
|
|
|
.type(value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'checkbox':
|
|
|
|
if (value) {
|
|
|
|
// Puede adaptar esto según cómo represente los valores booleanos en su array 'data'
|
|
|
|
cy.get('@currentRow')
|
|
|
|
.find('td')
|
|
|
|
.eq(index)
|
|
|
|
.find('input[type="checkbox"]')
|
|
|
|
.check();
|
|
|
|
} else {
|
|
|
|
cy.get('@currentRow')
|
|
|
|
.find('td')
|
|
|
|
.eq(index)
|
|
|
|
.find('input[type="checkbox"]')
|
|
|
|
.uncheck();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ... Puede agregar más casos para otros tipos de inputs según sea necesario
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Manejar cualquier otro tipo de input o agregar lógica de error aquí si es necesario
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-12-21 08:19:29 +00:00
|
|
|
// registerCommands();
|