MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / ensureSidebarExpanded

Function ensureSidebarExpanded

e2e/tasknotes.spec.ts:29–85  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

27
28// Helper to ensure sidebar is expanded
29async 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

Callers 7

expandViewsFolderFunction · 0.85
tasknotes.spec.tsFile · 0.85
expandViewsFolderFor1328Function · 0.85
expandViewsFolderFor1423Function · 0.85
openCalendarViewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected