test: refs #6695 e2e better selectOption
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
dbea92cb53
commit
e8788cf2d0
|
@ -108,74 +108,50 @@ Cypress.Commands.add('selectOption', (selector, option, timeout = 2500) => {
|
||||||
.invoke('attr', 'aria-controls') // Obtiene el valor del atributo aria-controls
|
.invoke('attr', 'aria-controls') // Obtiene el valor del atributo aria-controls
|
||||||
.then((ariaControl) => {
|
.then((ariaControl) => {
|
||||||
cy.log('ARIA', ariaControl); // Muestra el valor en la consola de Cypress
|
cy.log('ARIA', ariaControl); // Muestra el valor en la consola de Cypress
|
||||||
let retries = 0;
|
getItems(ariaControl).then((items) => {
|
||||||
cy.retryCheckItem(ariaControl, selector, option, retries);
|
cy.log('items: ', items);
|
||||||
|
const matchingItem = items
|
||||||
|
.toArray()
|
||||||
|
.find((item) => item.innerText.includes(option));
|
||||||
|
if (!matchingItem) return findOption(selector, option, ariaControl);
|
||||||
|
cy.wrap(matchingItem).click();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Cypress.Commands.add('retryCheckItem', (ariaControl, selector, option, retries) => {
|
function getItems(ariaControl, startTime = Cypress._.now(), timeout = 2500) {
|
||||||
if (retries == 10) throw new Error('Maximum number of retries exceeded → ', option);
|
return cy
|
||||||
cy.get('#' + ariaControl)
|
.get('#' + ariaControl, { timeout }) // Se asegura de que el selector aparezca en tiempo razonable
|
||||||
.should('exist')
|
.should('exist')
|
||||||
.find('.q-item')
|
.find('.q-item')
|
||||||
.should('exist')
|
.should('exist')
|
||||||
.then(($items) => {
|
.then(($items) => {
|
||||||
cy.log('ASDASD', $items?.length);
|
if (!$items?.length || $items.first().text().trim() === '') {
|
||||||
if (!$items?.length)
|
// 🔹 Si ha pasado más tiempo que el límite, falla el test
|
||||||
return cy
|
if (Cypress._.now() - startTime > timeout) {
|
||||||
.wait(50)
|
throw new Error(
|
||||||
.then(() =>
|
`getItems: Tiempo de espera (${timeout}ms) excedido.`,
|
||||||
cy.retryCheckItem(ariaControl, selector, option, retries + 1),
|
|
||||||
);
|
);
|
||||||
const data = $items.toArray().map((item) => item.innerText);
|
}
|
||||||
const dataString = JSON.stringify(data);
|
return getItems(ariaControl, startTime, timeout);
|
||||||
cy.log('OPTIONS', dataString);
|
}
|
||||||
if (data[0] == '')
|
|
||||||
return cy
|
return cy.wrap($items);
|
||||||
.wait(50)
|
});
|
||||||
.then(() =>
|
}
|
||||||
cy.retryCheckItem(ariaControl, selector, option, retries + 1),
|
|
||||||
);
|
function findOption(selector, option, ariaControl) {
|
||||||
cy.log('PASSED');
|
cy.get(selector).clear().type(option);
|
||||||
const optionFinded = $items
|
// cy.get('.q-menu').should('not.be.visible');
|
||||||
|
getItems(ariaControl).then((items) => {
|
||||||
|
cy.log('findOption items: ', items);
|
||||||
|
const matchingItem = items
|
||||||
.toArray()
|
.toArray()
|
||||||
.some((item) => item.innerText.includes(option));
|
.find((item) => item.innerText.includes(option));
|
||||||
|
cy.wrap(matchingItem).click();
|
||||||
if (optionFinded) {
|
|
||||||
const itemAClickear = $items
|
|
||||||
.filter((_, item) => item.innerText.includes(option))
|
|
||||||
.first();
|
|
||||||
cy.wrap(itemAClickear).click(); // Haz clic en el elemento encontrado
|
|
||||||
} else {
|
|
||||||
// throw new Error('Option not found → ', option);
|
|
||||||
cy.get(selector, { timeout }).clear().type(option);
|
|
||||||
let retries = 0;
|
|
||||||
cy.retrySelectOption(selector, option, timeout, retries);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
Cypress.Commands.add('retrySelectOption', (selector, option, timeout, retries) => {
|
|
||||||
cy.log('RETRY', retries);
|
|
||||||
if (retries == 10) throw new Error('Maximum number of retries exceeded → ', option);
|
|
||||||
cy.get('.q-menu', { timeout })
|
|
||||||
.should('exist')
|
|
||||||
.then(($menu) => {
|
|
||||||
if ($menu.is(':visible')) {
|
|
||||||
cy.get('.q-item')
|
|
||||||
.should('exist')
|
|
||||||
.should('be.visible')
|
|
||||||
.contains(option)
|
|
||||||
.click();
|
|
||||||
cy.get(selector).blur();
|
|
||||||
} else {
|
|
||||||
cy.wait(100).then(() => {
|
|
||||||
cy.retrySelectOption(selector, option, timeout, retries + 1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
Cypress.Commands.add('countSelectOptions', (selector, option) => {
|
Cypress.Commands.add('countSelectOptions', (selector, option) => {
|
||||||
cy.waitForElement(selector);
|
cy.waitForElement(selector);
|
||||||
|
|
Loading…
Reference in New Issue