MCPcopy
hub / github.com/callumalpass/tasknotes / openView

Function openView

e2e/docs-screenshots.spec.ts:78–130  ·  view source on GitHub ↗
(
  page: Page,
  commands: string[],
  sidebarFileHint: string
)

Source from the content-addressed store, hash-verified

76}
77
78async function openView(
79 page: Page,
80 commands: string[],
81 sidebarFileHint: string
82): Promise<void> {
83 for (const command of commands) {
84 try {
85 await runCommand(page, command);
86 await page.waitForTimeout(1200);
87 return;
88 } catch {
89 // Try the next command alias
90 }
91 }
92
93 // Fallback: open default base files directly via Obsidian API.
94 const fileCandidates = [
95 `TaskNotes/Views/${sidebarFileHint}.base`,
96 `${sidebarFileHint}.base`,
97 sidebarFileHint,
98 ];
99 for (const targetPath of fileCandidates) {
100 const opened = await page.evaluate(async (path) => {
101 try {
102 const appAny = (window as any).app;
103 const file = appAny?.vault?.getAbstractFileByPath?.(path);
104 if (file) {
105 await appAny.workspace.getLeaf(true).openFile(file);
106 return true;
107 }
108 await appAny.workspace.openLinkText(path, "", false);
109 return true;
110 } catch {
111 return false;
112 }
113 }, targetPath);
114
115 if (opened) {
116 await page.waitForTimeout(1200);
117 return;
118 }
119 }
120
121 await expandViewsFolder(page);
122 const item = page.locator(`.nav-file-title:has-text("${sidebarFileHint}")`).first();
123 if (await item.isVisible({ timeout: 5000 }).catch(() => false)) {
124 await item.click();
125 await page.waitForTimeout(1500);
126 return;
127 }
128
129 throw new Error(`Could not open view using commands [${commands.join(', ')}] or sidebar hint "${sidebarFileHint}"`);
130}
131
132// Helper to take a screenshot with consistent settings
133async function docScreenshot(

Callers 1

Calls 4

runCommandFunction · 0.90
getAbstractFileByPathMethod · 0.80
getLeafMethod · 0.80
expandViewsFolderFunction · 0.70

Tested by

no test coverage detected