Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions cypress/support/commands/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,32 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
cy.logAndThrowError(errorMessage);
};

// Start the recursive call from the first label in the given path
// If no list items are found initially - wait for them to load and
// then start the recursive call from the first label in the given path
// and from the beginning of the accordion items in the panel
expandAndClickPath(0, 0);
if (listItems.length) {
expandAndClickPath(0, 0);
} else {
Cypress.log({
name: '⚠️ selectAccordionItem',
message: 'No list items found initially - waiting for them to load',
});

cy.get('div.panel-collapse.collapse.in').then((freshAccordion) => {
cy.wrap(freshAccordion)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though freshAccordion was captured once, when we do cy.wrap(freshAccordion).find(), jQuery's .find() method queries the current state of the DOM tree under that element, not a snapshot because jQuery maintains a reference to the DOM elements.

Note: We could also query the whole accordion repeatedly here, but since this approach seems to work, let’s stick with it for now

.find('li.list-group-item')
.should('have.length.greaterThan', 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes Cypress to retry the .find() command until this assertion passes for a minimum time (4Sec here)

.then((loadedListItems) => {
// Update references with the loaded data
expandedAccordion = freshAccordion;
listItems = [...loadedListItems];
Cypress.log({
name: '🟢 selectAccordionItem',
message: `List items loaded - found ${listItems.length} items`,
});
expandAndClickPath(0, 0);
});
});
}
});
});