Skip to content

Commit 1d5b2a8

Browse files
Enhanced accordionItem comand to allow partial match and expand nested options
1 parent 7f79b24 commit 1d5b2a8

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

cypress/support/commands/explorer.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,35 @@ Cypress.Commands.add('accordion', (title) => {
1818
return ret.parents('.panel');
1919
});
2020

21-
// name: String of the record in the accordion panel to click.
22-
Cypress.Commands.add('accordionItem', (name) => {
21+
/**
22+
* name: String of the record in the accordion panel to click.
23+
* partialMatch: Boolean to indicate if the name should be matched partially.
24+
* parentAccordId: Optional ID of the parent accordion to scope the search.
25+
* If provided, the search will be limited to items within that accordion.
26+
*/
27+
Cypress.Commands.add('accordionItem', (name, partialMatch = false, parentAccordId) => {
2328
cy.get('#main-content'); // ensure screen loads first
2429

25-
cy.get('.list-group-item').contains(name).click();
30+
const selector = parentAccordId
31+
? `.sidebar-pf-left #${parentAccordId} .list-group-item`
32+
: '.sidebar-pf-left .list-group-item';
33+
cy.get(selector).each(($el) => {
34+
const text = $el.text().trim();
35+
const isMatch = partialMatch
36+
? text.toLowerCase().includes(name.toLowerCase())
37+
: text === name;
38+
39+
if (isMatch) {
40+
const span = $el.find('span.fa-angle-right');
41+
if (span.length) {
42+
cy.wrap(span).click({ force: true });
43+
} else {
44+
cy.wrap($el).click({ force: true });
45+
}
46+
47+
// Stop looping after finding and clicking the matching item
48+
return false;
49+
}
50+
return true; // continue looping
51+
});
2652
});

0 commit comments

Comments
 (0)