Skip to content

Commit 482ac10

Browse files
authored
fix(cypress): extend sidebar poll timeout past defaultCommandTimeout (opendatahub-io#7410)
1 parent c47e8d1 commit 482ac10

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

packages/cypress/cypress/utils/oc_commands/genAi.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,31 @@ const waitForGenAiStudioFeatureFlag = (): Cypress.Chainable<Cypress.Exec> => {
8181
});
8282
};
8383

84-
/**
85-
* Check if the Gen AI Studio section exists in the sidebar.
86-
*
87-
* @returns A Cypress chainable resolving to true if the section exists, false otherwise.
88-
*/
8984
/**
9085
* Retry-aware check for an element inside the sidebar.
9186
* See `findNavItemInSidebar` in mlflow.ts for rationale.
87+
*
88+
* After `dashboard-page-main` appears, extension nav items can render asynchronously.
89+
* Poll the live `#page-sidebar` DOM (not only the initial command subject) until the
90+
* selector matches or the settle window elapses.
91+
*
92+
* The inner poll can run up to `NAV_ITEM_SETTLE_MS`; `.then()` must use a longer timeout
93+
* than `defaultCommandTimeout` (10s) or Cypress aborts while the Promise is still pending.
9294
*/
9395
const SIDEBAR_SETTLE_TIMEOUT = 30000;
9496
const NAV_ITEM_SETTLE_MS = 15000;
9597
const NAV_ITEM_POLL_MS = 500;
98+
const NAV_ITEM_FIND_TIMEOUT_MS = NAV_ITEM_SETTLE_MS + 5000;
9699

97100
const findInSidebar = (selector: string): Cypress.Chainable<boolean> =>
98101
appChrome.findSideBar().then(
99-
($sidebar) =>
102+
{ timeout: NAV_ITEM_FIND_TIMEOUT_MS },
103+
() =>
100104
new Cypress.Promise<boolean>((resolve) => {
101105
const deadline = Date.now() + NAV_ITEM_SETTLE_MS;
102106
const poll = () => {
103-
if ($sidebar.find(selector).length > 0) {
107+
const $sidebar = Cypress.$('#page-sidebar');
108+
if ($sidebar.length > 0 && $sidebar.find(selector).length > 0) {
104109
resolve(true);
105110
} else if (Date.now() >= deadline) {
106111
resolve(false);

packages/cypress/cypress/utils/oc_commands/mlflow.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,25 @@ const logSidebarDiagnostics = (): void => {
237237
* yet contain extension items. A one-shot jQuery `.find()` during that gap
238238
* always misses the item, making the outer reload loop retry needlessly.
239239
*
240-
* This helper polls the live jQuery element for up to `NAV_ITEM_SETTLE_MS`
240+
* This helper polls the live `#page-sidebar` DOM for up to `NAV_ITEM_SETTLE_MS`
241241
* so that a single page load is enough once the extensions are ready.
242+
*
243+
* `.then()` must allow longer than `defaultCommandTimeout` (10s) while the inner
244+
* `Cypress.Promise` polls for up to `NAV_ITEM_SETTLE_MS` (15s).
242245
*/
243246
const NAV_ITEM_SETTLE_MS = 15000;
244247
const NAV_ITEM_POLL_MS = 500;
248+
const NAV_ITEM_FIND_TIMEOUT_MS = NAV_ITEM_SETTLE_MS + 5000;
245249

246-
const findNavItemInSidebar = ($sidebar: JQuery, navLabel: string): Cypress.Chainable<boolean> =>
250+
const findNavItemInSidebar = (navLabel: string): Cypress.Chainable<boolean> =>
247251
cy.wrap(null, { log: false }).then(
252+
{ timeout: NAV_ITEM_FIND_TIMEOUT_MS },
248253
() =>
249254
new Cypress.Promise<boolean>((resolve) => {
250255
const deadline = Date.now() + NAV_ITEM_SETTLE_MS;
251256
const poll = () => {
252-
if ($sidebar.find(`a:contains("${navLabel}")`).length > 0) {
257+
const $sidebar = Cypress.$('#page-sidebar');
258+
if ($sidebar.length > 0 && $sidebar.find(`a:contains("${navLabel}")`).length > 0) {
253259
resolve(true);
254260
} else if (Date.now() >= deadline) {
255261
resolve(false);
@@ -278,7 +284,7 @@ const waitForNavItemInSidebar = (navLabel: string): Cypress.Chainable<boolean> =
278284

279285
return appChrome
280286
.findSideBar()
281-
.then(($sidebar) => findNavItemInSidebar($sidebar, navLabel))
287+
.then(() => findNavItemInSidebar(navLabel))
282288
.then((found) => {
283289
const elapsedTime = ((Date.now() - startTime) / 1000).toFixed(1);
284290

0 commit comments

Comments
 (0)