forked from verdnatura/salix-front
111 lines
3.8 KiB
JavaScript
Executable File
111 lines
3.8 KiB
JavaScript
Executable File
// ***********************************************
|
|
// 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
|
|
// import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress';
|
|
Cypress.Commands.add('login', (user) => {
|
|
//cy.visit('/#/login');
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/accounts/login',
|
|
body: {
|
|
user: user,
|
|
password: 'nightmare',
|
|
},
|
|
}).then((response) => {
|
|
window.localStorage.setItem('token', response.body.token);
|
|
});
|
|
});
|
|
|
|
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;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
// registerCommands();
|