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';
|
2024-10-29 13:23:06 +00:00
|
|
|
Cypress.Commands.add('waitUntil', { prevSubject: 'optional' }, require('./waitUntil'));
|
|
|
|
Cypress.Commands.add('resetDB', () => {
|
|
|
|
cy.exec('pnpm run resetDatabase');
|
|
|
|
});
|
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);
|
2024-04-23 11:19:21 +00:00
|
|
|
cy.request({
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/VnUsers/ShareToken',
|
|
|
|
headers: {
|
|
|
|
Authorization: window.localStorage.getItem('token'),
|
|
|
|
},
|
|
|
|
}).then(({ body }) => {
|
|
|
|
window.localStorage.setItem('tokenMultimedia', body.multimediaToken.id);
|
|
|
|
});
|
2022-12-21 08:19:29 +00:00
|
|
|
});
|
|
|
|
});
|
2023-08-21 13:14:19 +00:00
|
|
|
|
2024-10-29 13:23:06 +00:00
|
|
|
Cypress.Commands.add('domContentLoad', (element, timeout = 5000) => {
|
|
|
|
cy.waitUntil(() => cy.document().then((doc) => doc.readyState === 'complete'));
|
|
|
|
});
|
2024-07-02 23:47:14 +00:00
|
|
|
Cypress.Commands.add('waitForElement', (element, timeout = 5000) => {
|
2024-10-29 13:23:06 +00:00
|
|
|
cy.waitUntil(() => cy.get(element).then(($el) => $el.is(':visible')));
|
2023-08-23 13:09:03 +00:00
|
|
|
});
|
|
|
|
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) {
|
2024-03-07 13:54:20 +00:00
|
|
|
return cy
|
|
|
|
.get(
|
|
|
|
selector +
|
|
|
|
'> .q-field > .q-field__inner > .q-field__control > .q-field__control-container > .q-field__native > input'
|
|
|
|
)
|
|
|
|
.invoke('val');
|
2023-08-23 13:09:03 +00:00
|
|
|
}
|
2024-02-15 14:00:30 +00:00
|
|
|
// Si es un QSelect
|
|
|
|
if ($el.find('span').length) {
|
2024-03-07 13:54:20 +00:00
|
|
|
return cy.get(selector + ' span').then(($span) => {
|
|
|
|
return $span[0].innerText;
|
|
|
|
});
|
2024-02-15 14:00:30 +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) => {
|
2024-02-26 11:00:57 +00:00
|
|
|
cy.waitForElement(selector);
|
2024-10-27 12:43:38 +00:00
|
|
|
cy.get(selector).click();
|
2023-08-23 13:09:03 +00:00
|
|
|
cy.get('.q-menu .q-item').contains(option).click();
|
|
|
|
});
|
2024-11-17 11:57:35 +00:00
|
|
|
Cypress.Commands.add('countSelectOptions', (selector, option) => {
|
|
|
|
cy.waitForElement(selector);
|
|
|
|
cy.get(selector).click();
|
|
|
|
cy.get('.q-menu .q-item').should('have.length', option);
|
|
|
|
});
|
2023-08-23 13:09:03 +00:00
|
|
|
|
2024-06-10 11:54:02 +00:00
|
|
|
Cypress.Commands.add('fillInForm', (obj, form = '.q-form > .q-card') => {
|
|
|
|
cy.waitForElement('.q-form > .q-card');
|
|
|
|
cy.get(`${form} input`).each(([el]) => {
|
|
|
|
cy.wrap(el)
|
|
|
|
.invoke('attr', 'aria-label')
|
|
|
|
.then((ariaLabel) => {
|
|
|
|
const field = obj[ariaLabel];
|
|
|
|
if (!field) return;
|
|
|
|
|
2024-07-16 08:42:35 +00:00
|
|
|
const { type, val } = field;
|
2024-06-10 11:54:02 +00:00
|
|
|
switch (type) {
|
|
|
|
case 'select':
|
|
|
|
cy.wrap(el).type(val);
|
|
|
|
cy.get('.q-menu .q-item').contains(val).click();
|
2024-07-05 14:25:49 +00:00
|
|
|
cy.get('body').click();
|
2024-06-10 11:54:02 +00:00
|
|
|
break;
|
|
|
|
case 'date':
|
2024-07-16 08:42:35 +00:00
|
|
|
cy.wrap(el).type(val.split('-').join(''));
|
2024-06-10 11:54:02 +00:00
|
|
|
break;
|
2024-07-15 08:44:28 +00:00
|
|
|
case 'time':
|
|
|
|
cy.wrap(el).click();
|
|
|
|
cy.get('.q-time .q-time__clock').contains(val.h).click();
|
|
|
|
cy.get('.q-time .q-time__clock').contains(val.m).click();
|
|
|
|
cy.get('.q-time .q-time__link').contains(val.x).click();
|
|
|
|
break;
|
2024-06-10 11:54:02 +00:00
|
|
|
default:
|
|
|
|
cy.wrap(el).type(val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-23 13:09:03 +00:00
|
|
|
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', () => {
|
2024-03-07 13:54:20 +00:00
|
|
|
const dropdownArrow = '.q-btn-dropdown__arrow-container > .q-btn__content > .q-icon';
|
|
|
|
cy.get('#st-actions').then(($el) => {
|
|
|
|
if ($el.find(dropdownArrow).length) cy.get(dropdownArrow).click();
|
|
|
|
});
|
2023-08-23 13:09:03 +00:00
|
|
|
cy.get('[title="Save"]').click();
|
|
|
|
});
|
2024-03-07 13:54:20 +00:00
|
|
|
|
2023-08-23 13:09:03 +00:00
|
|
|
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');
|
2024-09-23 09:15:17 +00:00
|
|
|
cy.waitForElement('.q-page-sticky > div > .q-btn');
|
2023-08-23 13:09:03 +00:00
|
|
|
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');
|
2024-02-06 14:11:59 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2024-10-22 11:22:43 +00:00
|
|
|
Cypress.Commands.add('selectRows', (rows) => {
|
|
|
|
rows.forEach((row) => {
|
|
|
|
cy.get('.q-table .q-virtual-scroll__content tr .q-checkbox__inner')
|
|
|
|
.eq(row - 1)
|
|
|
|
.click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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);
|
2024-03-07 13:54:20 +00:00
|
|
|
if (value === undefined) continue;
|
2023-08-23 13:09:03 +00:00
|
|
|
if (typeof value == 'boolean') {
|
|
|
|
const prefix = value ? '' : 'not.';
|
|
|
|
cy.getValue(`:nth-child(${index + 1})`).should(`${prefix}be.checked`);
|
|
|
|
continue;
|
|
|
|
}
|
2024-03-07 13:54:20 +00:00
|
|
|
cy.getValue(`:nth-child(${index + 1})`).should('equal', value);
|
2023-08-23 13:09:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-11-09 09:29:28 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('removeRow', (rowIndex) => {
|
2024-07-05 13:41:53 +00:00
|
|
|
const trEls = 'tbody > tr:visible';
|
2023-11-09 09:29:28 +00:00
|
|
|
let rowsBefore;
|
2024-07-05 13:41:53 +00:00
|
|
|
cy.get('tbody > tr')
|
2023-11-09 09:29:28 +00:00
|
|
|
.its('length')
|
|
|
|
.then((length) => {
|
2024-07-05 13:41:53 +00:00
|
|
|
cy.get(`${trEls} .q-checkbox`)
|
|
|
|
.eq(rowIndex - 1)
|
|
|
|
.click();
|
2023-11-09 09:29:28 +00:00
|
|
|
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)
|
2024-07-05 13:41:53 +00:00
|
|
|
cy.get('tbody > tr').should('have.length', rowsBefore - 1);
|
2024-01-10 13:01:36 +00:00
|
|
|
});
|
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('clearSearchbar', (element) => {
|
|
|
|
if (element) cy.waitForElement(element);
|
2024-06-10 11:54:02 +00:00
|
|
|
cy.get(
|
|
|
|
'#searchbar > form > div:nth-child(1) > label > div:nth-child(1) input'
|
|
|
|
).clear();
|
2024-01-09 11:20:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('writeSearchbar', (value) => {
|
2024-06-10 11:54:02 +00:00
|
|
|
cy.get('#searchbar > form > div:nth-child(1) > label > div:nth-child(1) input').type(
|
|
|
|
value
|
|
|
|
);
|
2024-01-09 11:20:56 +00:00
|
|
|
});
|
2023-10-18 08:18:25 +00:00
|
|
|
Cypress.Commands.add('validateContent', (selector, expectedValue) => {
|
|
|
|
cy.get(selector).should('have.text', expectedValue);
|
|
|
|
});
|
2024-01-11 15:42:41 +00:00
|
|
|
|
2024-10-21 12:31:31 +00:00
|
|
|
Cypress.Commands.add('openActionDescriptor', (opt) => {
|
|
|
|
cy.openActionsDescriptor();
|
|
|
|
const listItem = '[role="menu"] .q-list .q-item';
|
|
|
|
cy.contains(listItem, opt).click();
|
|
|
|
1;
|
|
|
|
});
|
|
|
|
|
2024-02-06 12:19:56 +00:00
|
|
|
Cypress.Commands.add('openActionsDescriptor', () => {
|
2024-10-28 15:21:00 +00:00
|
|
|
cy.get('[data-cy="descriptor-more-opts"]').click();
|
2024-02-06 12:19:56 +00:00
|
|
|
});
|
2024-09-25 08:53:38 +00:00
|
|
|
|
2024-10-29 01:15:02 +00:00
|
|
|
Cypress.Commands.add('clickButtonsDescriptor', (id) => {
|
|
|
|
cy.get(`.actions > .q-card__actions> .q-btn:nth-child(${id})`)
|
|
|
|
.invoke('removeAttr', 'target')
|
|
|
|
.click();
|
2024-02-06 12:19:56 +00:00
|
|
|
});
|
2024-09-25 08:53:38 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('openUserPanel', () => {
|
|
|
|
cy.get(
|
|
|
|
'.column > .q-avatar > .q-avatar__content > .q-img > .q-img__container > .q-img__image'
|
|
|
|
).click();
|
|
|
|
});
|
2024-10-21 12:31:31 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('openActions', (row) => {
|
|
|
|
cy.get('tbody > tr').eq(row).find('.actions > .q-btn').click();
|
|
|
|
});
|
|
|
|
|
2024-10-25 08:53:19 +00:00
|
|
|
Cypress.Commands.add('checkNotification', (text) => {
|
2024-10-22 11:21:16 +00:00
|
|
|
cy.get('.q-notification')
|
|
|
|
.should('be.visible')
|
|
|
|
.last()
|
|
|
|
.then(($lastNotification) => {
|
|
|
|
if (!Cypress.$($lastNotification).text().includes(text))
|
|
|
|
throw new Error(`Notification not found: "${text}"`);
|
|
|
|
});
|
|
|
|
});
|
2024-10-25 08:33:59 +00:00
|
|
|
|
2024-10-29 01:15:02 +00:00
|
|
|
Cypress.Commands.add('checkValueForm', (id, search) => {
|
|
|
|
cy.get(
|
|
|
|
`.grid-create > :nth-child(${id}) > .q-field__inner>.q-field__control> .q-field__control-container>.q-field__native >.q-field__input`
|
|
|
|
).should('have.value', search);
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('checkValueSelectForm', (id, search) => {
|
|
|
|
cy.get(
|
|
|
|
`.grid-create > :nth-child(${id}) > .q-field > .q-field__inner > .q-field__control > .q-field__control-container>.q-field__native>.q-field__input`
|
|
|
|
).should('have.value', search);
|
2024-10-22 11:21:16 +00:00
|
|
|
});
|
2024-10-25 08:33:59 +00:00
|
|
|
|
|
|
|
Cypress.Commands.add('searchByLabel', (label, value) => {
|
|
|
|
cy.get(`[label="${label}"] > .q-field > .q-field__inner`).type(`${value}{enter}`);
|
|
|
|
});
|