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
|
|
|
|
2023-08-23 13:09:03 +00:00
|
|
|
Cypress.Commands.add('waitForElement', (element) => {
|
|
|
|
cy.get(element, { timeout: 2000 }).should('be.visible');
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('getValue', (selector) => {
|
|
|
|
cy.get(selector).then(($el) => {
|
|
|
|
if ($el.find('.q-checkbox__inner').length > 0) {
|
|
|
|
return cy.get(selector + '.q-checkbox__inner');
|
|
|
|
}
|
|
|
|
// Si es un QSelect
|
2023-12-11 10:59:01 +00:00
|
|
|
if ($el.find('.q-select__dropdown-icon').length) {
|
2023-08-23 13:09:03 +00:00
|
|
|
return cy.get(
|
|
|
|
selector +
|
2023-10-13 07:04:14 +00:00
|
|
|
'> .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > input'
|
2023-08-23 13:09:03 +00:00
|
|
|
);
|
|
|
|
}
|
2023-12-11 10:59:01 +00:00
|
|
|
// Puedes añadir un log o lanzar un error si el elemento no es reconocido
|
|
|
|
cy.log('Elemento no soportado');
|
2023-08-21 13:14:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-23 13:09:03 +00:00
|
|
|
// Fill Inputs
|
|
|
|
Cypress.Commands.add('selectOption', (selector, option) => {
|
|
|
|
cy.get(selector).find('.q-select__dropdown-icon').click();
|
|
|
|
cy.get('.q-menu .q-item').contains(option).click();
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('checkOption', (selector) => {
|
2023-10-18 08:18:25 +00:00
|
|
|
cy.get(selector).find('.q-checkbox__inner').click();
|
2023-08-23 13:09:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Global buttons
|
|
|
|
Cypress.Commands.add('saveCard', () => {
|
|
|
|
cy.get('[title="Save"]').click();
|
|
|
|
});
|
|
|
|
Cypress.Commands.add('resetCard', () => {
|
|
|
|
cy.get('[title="Reset"]').click();
|
|
|
|
});
|
|
|
|
Cypress.Commands.add('removeCard', () => {
|
|
|
|
cy.get('[title="Remove"]').click();
|
|
|
|
});
|
|
|
|
Cypress.Commands.add('addCard', () => {
|
|
|
|
cy.waitForElement('tbody');
|
|
|
|
cy.get('.q-page-sticky > div > .q-btn').click();
|
|
|
|
});
|
|
|
|
Cypress.Commands.add('clickConfirm', () => {
|
2023-11-17 13:06:43 +00:00
|
|
|
cy.waitForElement('.q-dialog__inner > .q-card');
|
|
|
|
cy.get('.q-card__actions > .q-btn--unelevated > .q-btn__content > .block').click();
|
2023-08-23 13:09:03 +00:00
|
|
|
});
|
|
|
|
|
2023-11-09 09:59:08 +00:00
|
|
|
Cypress.Commands.add('notificationHas', (selector, text) => {
|
|
|
|
cy.get(selector).should('have.text', text);
|
|
|
|
});
|
|
|
|
|
2023-08-23 13:09:03 +00:00
|
|
|
Cypress.Commands.add('fillRow', (rowSelector, data) => {
|
|
|
|
// Usar el selector proporcionado para obtener la fila deseada
|
|
|
|
cy.waitForElement('tbody');
|
|
|
|
cy.get(rowSelector).as('currentRow');
|
2023-08-21 13:14:19 +00:00
|
|
|
|
|
|
|
data.forEach((value, index) => {
|
2023-08-23 13:09:03 +00:00
|
|
|
if (value === null) return;
|
2023-08-21 13:14:19 +00:00
|
|
|
cy.get('@currentRow')
|
|
|
|
.find('td')
|
|
|
|
.eq(index)
|
2023-08-23 13:09:03 +00:00
|
|
|
.then((td) => {
|
|
|
|
if (td.find('.q-select__dropdown-icon').length) {
|
|
|
|
cy.selectOption(td, value);
|
2023-11-09 09:29:28 +00:00
|
|
|
} else if (td.find('.q-checkbox__inner').length && value) {
|
2023-08-23 13:09:03 +00:00
|
|
|
cy.checkOption(td);
|
2023-11-09 09:29:28 +00:00
|
|
|
} else if (td.find('input[type="text"]') && value)
|
|
|
|
cy.get(td).find('input').type(value);
|
2023-08-21 13:14:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-08-23 13:09:03 +00:00
|
|
|
|
2023-11-09 09:29:28 +00:00
|
|
|
Cypress.Commands.add('addRow', () => {
|
|
|
|
cy.waitForElement('tbody');
|
|
|
|
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content').click();
|
|
|
|
});
|
|
|
|
|
2023-08-23 13:09:03 +00:00
|
|
|
Cypress.Commands.add('validateRow', (rowSelector, expectedValues) => {
|
|
|
|
cy.waitForElement('tbody');
|
|
|
|
cy.get(rowSelector).within(() => {
|
|
|
|
for (const [index, value] of expectedValues.entries()) {
|
|
|
|
cy.log('CHECKING ', index, value);
|
|
|
|
if (typeof value == 'boolean') {
|
|
|
|
const prefix = value ? '' : 'not.';
|
|
|
|
cy.getValue(`:nth-child(${index + 1})`).should(`${prefix}be.checked`);
|
|
|
|
continue;
|
|
|
|
}
|
2023-10-13 07:04:14 +00:00
|
|
|
cy.getValue(`:nth-child(${index + 1})`).should('have.value', value);
|
2023-08-23 13:09:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-11-09 09:29:28 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('removeRow', (rowIndex) => {
|
|
|
|
let rowsBefore;
|
2024-01-10 13:01:36 +00:00
|
|
|
cy.get('tbody > tr:visible')
|
2023-11-09 09:29:28 +00:00
|
|
|
.its('length')
|
|
|
|
.then((length) => {
|
|
|
|
cy.get('.q-checkbox').eq(rowIndex).click();
|
|
|
|
cy.removeCard();
|
|
|
|
cy.get('.q-dialog button').eq(2).click();
|
2024-01-10 13:01:36 +00:00
|
|
|
rowsBefore = length;
|
2023-11-09 09:29:28 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
2024-01-10 13:01:36 +00:00
|
|
|
// Check the existence of tbody before performing the second assertion.
|
|
|
|
cy.get('tbody').then(($tbody) => {
|
|
|
|
if ($tbody.length > 0)
|
|
|
|
cy.get('tbody > tr:visible').should('have.length', rowsBefore - 1);
|
|
|
|
});
|
2023-11-09 09:29:28 +00:00
|
|
|
});
|
|
|
|
});
|
2023-10-04 13:46:15 +00:00
|
|
|
Cypress.Commands.add('openListSummary', (row) => {
|
|
|
|
cy.get('.card-list-body .actions .q-btn:nth-child(2)').eq(row).click();
|
|
|
|
});
|
2023-10-18 08:18:25 +00:00
|
|
|
|
2023-12-11 10:59:01 +00:00
|
|
|
Cypress.Commands.add('openRightMenu', (element) => {
|
|
|
|
if (element) cy.waitForElement(element);
|
|
|
|
cy.get('#actions-append').click();
|
2023-10-18 08:18:25 +00:00
|
|
|
});
|
|
|
|
|
2024-01-09 11:20:56 +00:00
|
|
|
Cypress.Commands.add('openLeftMenu', (element) => {
|
|
|
|
if (element) cy.waitForElement(element);
|
|
|
|
cy.get('.q-toolbar > .q-btn--round.q-btn--dense > .q-btn__content > .q-icon').click();
|
|
|
|
});
|
|
|
|
Cypress.Commands.add('closeLeftMenu', (element) => {
|
|
|
|
if (element) cy.waitForElement(element);
|
|
|
|
cy.get('.fullscreen').click();
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('clearSearchbar', (element) => {
|
|
|
|
if (element) cy.waitForElement(element);
|
|
|
|
cy.get('#searchbar > form > label > div:nth-child(1) input').clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('writeSearchbar', (value) => {
|
|
|
|
cy.get('#searchbar > form > label > div:nth-child(1) input').type(value);
|
|
|
|
});
|
2023-10-18 08:18:25 +00:00
|
|
|
Cypress.Commands.add('validateContent', (selector, expectedValue) => {
|
|
|
|
cy.get(selector).should('have.text', expectedValue);
|
|
|
|
});
|
2022-12-21 08:19:29 +00:00
|
|
|
// registerCommands();
|