test: refs #6695 run all e2e (try 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
6fe44481b6
commit
6388d4e0f4
|
@ -7,6 +7,6 @@ describe('Client notes', () => {
|
|||
});
|
||||
it('Should load layout', () => {
|
||||
cy.get('.q-page').should('be.visible');
|
||||
cy.get('.q-page > :nth-child(2) > :nth-child(1)').should('be.visible');
|
||||
cy.get('.q-page').find('.q-card').should('be.visible');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -89,27 +89,74 @@ Cypress.Commands.add('getValue', (selector) => {
|
|||
});
|
||||
|
||||
// Fill Inputs
|
||||
Cypress.Commands.add('selectOption', (selector, option, timeout = 10000) => {
|
||||
cy.waitForElement(selector, timeout); // Esperar a que el selector sea visible
|
||||
cy.get(selector).click();
|
||||
cy.get('.q-item', { timeout: 5000 })
|
||||
Cypress.Commands.add('selectOption', (selector, option, timeout = 2500) => {
|
||||
cy.waitForElement(selector, timeout);
|
||||
|
||||
cy.get(selector, { timeout }) // Selecciona el elemento que tiene el atributo data-cy
|
||||
.should('exist') // Verifica que el input exista
|
||||
.should('be.visible') // Verifica que el input exista
|
||||
.click()
|
||||
.then(($el) => {
|
||||
if ($el.is('input')) {
|
||||
return checkAriaControl($el);
|
||||
}
|
||||
checkAriaControl($el.find('input'));
|
||||
});
|
||||
|
||||
function checkAriaControl(input) {
|
||||
cy.wrap(input)
|
||||
.invoke('attr', 'aria-controls') // Obtiene el valor del atributo aria-controls
|
||||
.then((ariaControl) => {
|
||||
cy.log('ARIA', ariaControl); // Muestra el valor en la consola de Cypress
|
||||
let retries = 0;
|
||||
cy.retryCheckItem(ariaControl, selector, option, retries);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Cypress.Commands.add('retryCheckItem', (ariaControl, selector, option, retries) => {
|
||||
if (retries == 10) throw new Error('Maximum number of retries exceeded → ', option);
|
||||
cy.get('#' + ariaControl)
|
||||
.should('exist')
|
||||
.find('.q-item')
|
||||
.should('exist')
|
||||
.should('be.visible')
|
||||
.then(($items) => {
|
||||
const opcionEncontrada = $items
|
||||
cy.log('ASDASD', $items?.length);
|
||||
if (!$items?.length)
|
||||
return cy
|
||||
.wait(50)
|
||||
.then(() =>
|
||||
cy.retryCheckItem(ariaControl, selector, option, retries + 1),
|
||||
);
|
||||
const data = $items.toArray().map((item) => item.innerText);
|
||||
const dataString = JSON.stringify(data);
|
||||
cy.log('OPTIONS', dataString);
|
||||
if (data[0] == '')
|
||||
return cy
|
||||
.wait(50)
|
||||
.then(() =>
|
||||
cy.retryCheckItem(ariaControl, selector, option, retries + 1),
|
||||
);
|
||||
cy.log('PASSED');
|
||||
const optionFinded = $items
|
||||
.toArray()
|
||||
.some((item) => item.innerText.includes(option));
|
||||
if (opcionEncontrada) {
|
||||
cy.contains('.q-item', option).click();
|
||||
|
||||
if (optionFinded) {
|
||||
const itemAClickear = $items
|
||||
.filter((_, item) => item.innerText.includes(option))
|
||||
.first();
|
||||
cy.wrap(itemAClickear).click(); // Haz clic en el elemento encontrado
|
||||
} else {
|
||||
cy.get(selector).clear().type(option);
|
||||
let retries = 0;
|
||||
retrySelectOption(selector, option, timeout, retries);
|
||||
throw new Error('Option not found → ', option);
|
||||
// cy.get(selector, { timeout }).clear().type(option);
|
||||
// let retries = 0;
|
||||
// cy.retrySelectOption(selector, option, timeout, retries);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function 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 })
|
||||
|
@ -121,14 +168,14 @@ function retrySelectOption(selector, option, timeout, retries) {
|
|||
.should('be.visible')
|
||||
.contains(option)
|
||||
.click();
|
||||
// cy.get(selector).blur();
|
||||
cy.get(selector).blur();
|
||||
} else {
|
||||
cy.wait(100).then(() => {
|
||||
retrySelectOption(selector, option, timeout, retries + 1);
|
||||
cy.retrySelectOption(selector, option, timeout, retries + 1);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Cypress.Commands.add('countSelectOptions', (selector, option) => {
|
||||
cy.waitForElement(selector);
|
||||
|
|
Loading…
Reference in New Issue