| 1 | /** The desktop ships one workbench layout; this waits for its chrome. */ |
| 2 | export async function chooseAppLayout() { |
| 3 | return undefined; |
| 4 | } |
| 5 | |
| 6 | /** |
| 7 | * Locate a local session through the workbench's ProjectTree navigation. |
| 8 | */ |
| 9 | export function sessionButton(page, label) { |
| 10 | return page.locator(".project-tree__topic-main").filter({ hasText: label }).first(); |
| 11 | } |
| 12 | |
| 13 | export async function revealSession(page, label, projectLabel = "reasonix") { |
| 14 | // Composer readiness and sidebar data readiness are independent. Wait for |
| 15 | // the first projected row before deciding whether the target is truncated. |
| 16 | await page.locator(".project-tree__topic-main").first().waitFor({ state: "visible" }); |
| 17 | const button = sessionButton(page, label); |
| 18 | const showMore = page.getByRole("button", { name: `Show more in ${projectLabel}`, exact: true }); |
| 19 | while (await button.count() === 0 || !await button.isVisible()) { |
| 20 | if (await showMore.count() === 0 || !await showMore.isVisible()) break; |
| 21 | const renderedCount = await page.locator(".project-tree__topic-main").count(); |
| 22 | await showMore.click(); |
| 23 | await page.waitForFunction(({ targetLabel, previousCount }) => { |
| 24 | const rows = [...document.querySelectorAll(".project-tree__topic-main")]; |
| 25 | return rows.some((row) => row.textContent?.includes(targetLabel)) || rows.length > previousCount; |
| 26 | }, { targetLabel: label, previousCount: renderedCount }); |
| 27 | } |
| 28 | await button.waitFor({ state: "visible" }); |
| 29 | return button; |
| 30 | } |
| 31 | |
| 32 | export async function selectSession(page, label) { |
| 33 | const button = await revealSession(page, label); |
| 34 | await button.click(); |
| 35 | } |
| 36 | |
| 37 | /** Return the visible new-session action. */ |
| 38 | export function newSessionButton(page) { |
| 39 | return page.locator(".sidebar__quick-action:visible").first(); |
| 40 | } |
| 41 | |
| 42 | export function activeSessionLabel(page) { |
| 43 | return page.locator('.project-tree__topic--active .project-tree__topic-label').first(); |
| 44 | } |
| 45 | |
| 46 | export async function readActiveSessionLabel(page) { |
| 47 | const label = activeSessionLabel(page); |
| 48 | return await label.count() > 0 ? await label.textContent() ?? "" : ""; |
| 49 | } |
| 50 |