(page: Page)
| 27 | |
| 28 | // Helper to ensure sidebar is expanded |
| 29 | async function ensureSidebarExpanded(page: Page): Promise<void> { |
| 30 | // Check if file-explorer is already visible |
| 31 | const fileExplorer = page.locator('.nav-files-container'); |
| 32 | if (await fileExplorer.isVisible({ timeout: 1000 }).catch(() => false)) { |
| 33 | return; // Sidebar is already expanded |
| 34 | } |
| 35 | |
| 36 | // Method 1: Look for the "Expand" button which appears when sidebar is collapsed |
| 37 | const expandButtonSelectors = [ |
| 38 | 'button:has-text("Expand")', |
| 39 | '.sidebar-toggle-button', |
| 40 | '[aria-label="Expand"]', |
| 41 | '.mod-left-split .sidebar-toggle-button', |
| 42 | ]; |
| 43 | |
| 44 | for (const selector of expandButtonSelectors) { |
| 45 | const expandButton = page.locator(selector).first(); |
| 46 | if (await expandButton.isVisible({ timeout: 500 }).catch(() => false)) { |
| 47 | await expandButton.click(); |
| 48 | await page.waitForTimeout(500); |
| 49 | if (await fileExplorer.isVisible({ timeout: 500 }).catch(() => false)) { |
| 50 | return; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // Method 2: Use Obsidian command to toggle left sidebar |
| 56 | await page.keyboard.press('Control+p'); |
| 57 | await page.waitForSelector('.prompt', { timeout: 3000 }).catch(() => null); |
| 58 | const promptInput = page.locator('.prompt-input'); |
| 59 | if (await promptInput.isVisible({ timeout: 1000 }).catch(() => false)) { |
| 60 | await promptInput.fill('Toggle left sidebar'); |
| 61 | await page.waitForTimeout(300); |
| 62 | const suggestion = page.locator('.suggestion-item').first(); |
| 63 | if (await suggestion.isVisible({ timeout: 1000 }).catch(() => false)) { |
| 64 | await page.keyboard.press('Enter'); |
| 65 | await page.waitForTimeout(500); |
| 66 | } else { |
| 67 | await page.keyboard.press('Escape'); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // Method 3: Try clicking ribbon icons if sidebar still not visible |
| 72 | if (!await fileExplorer.isVisible({ timeout: 500 }).catch(() => false)) { |
| 73 | const ribbonIcons = page.locator('.side-dock-ribbon-action'); |
| 74 | const count = await ribbonIcons.count(); |
| 75 | for (let i = 0; i < Math.min(count, 5); i++) { |
| 76 | const icon = ribbonIcons.nth(i); |
| 77 | const ariaLabel = await icon.getAttribute('aria-label').catch(() => ''); |
| 78 | if (ariaLabel && (ariaLabel.toLowerCase().includes('file') || ariaLabel.toLowerCase().includes('explorer'))) { |
| 79 | await icon.click(); |
| 80 | await page.waitForTimeout(500); |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 |
no outgoing calls
no test coverage detected