/** * @file * * Mock of Obsidian's `App`, the root object that owns the vault, workspace, metadata cache and the other managers. */ import type { App as AppOriginal, DataAdapter as DataAdapterOriginal, UserEvent as UserEventOriginal } from 'obsidian'; import type { AppCreateConfiguredOptions } from '../internal/app-create-configured-options.mjs'; import { Plugins } from '../internal/plugins.mjs'; import { ViewRegistry } from '../internal/views/view-registry.mjs'; import { FileManager } from './FileManager.mjs'; import { Keymap } from './Keymap.mjs'; import { MetadataCache } from './MetadataCache.mjs'; import { RenderContext } from './RenderContext.mjs'; import { Scope } from './Scope.mjs'; import { SecretStorage } from './SecretStorage.mjs'; import { Vault } from './Vault.mjs'; import { Workspace } from './Workspace.mjs'; /** * Mock of Obsidian's `App`, wiring together mocks of the vault, file manager, keymap, metadata cache, plugin * registry, scope, workspace, render context and secret storage. * * Use {@link App.createConfigured__} to get an app over an in-memory vault seeded with files. */ export declare class App { /** * The id that uniquely identifies the vault, for vault-specific storage. */ appId: string; /** * The file manager, which creates, deletes and renames files the way the UI does. */ fileManager: FileManager; /** * The keymap, which manages the lifecycle of keymap scopes. */ keymap: Keymap; /** * The last known user interaction event, which helps commands tell which modifier keys are pressed. `null` in the * mock until a test sets it. */ lastEvent: null | UserEventOriginal; /** * The metadata cache holding each markdown file's parsed links, headings, tags and frontmatter. */ metadataCache: MetadataCache; /** * The community-plugin registry, empty until a test registers a plugin. */ plugins: Plugins; /** * The render context, with helpers for rendering Bases values. */ renderContext: RenderContext; /** * The app-wide root keymap scope. */ scope: Scope; /** * The secret storage, which keeps secrets such as API keys out of plugin data. */ secretStorage: SecretStorage; /** * The vault over the app's data adapter. */ vault: Vault; /** * The registry mapping view types to the creators that build them, and file extensions to view types. It holds * Obsidian's Markdown view from the start; `Plugin.registerView` adds to it. */ viewRegistry: ViewRegistry; /** * The workspace managing leaves, splits and views. */ workspace: Workspace; /** * Whether Obsidian is running on mobile. * * Answers from the mocked `Platform`, so a test that flips `Platform.isMobile` sees the change here * too — the two are the same fact, and Obsidian keeps them consistent as well. * * @returns The current `Platform.isMobile`. */ get isMobile(): boolean; private readonly localStorage; private theme; /** * Creates an app and its managers over a data adapter. * * @param adapter - The data adapter the vault reads and writes through. * @param appId - The id of the vault. */ protected constructor(adapter: DataAdapterOriginal, appId: string); /** * Mock-only factory: creates an app, spyable via `vi.spyOn(App, 'create__')`. * * @param adapter - The data adapter the vault reads and writes through. * @param appId - The id of the vault. * @returns The new app. */ static create__(adapter: DataAdapterOriginal, appId: string): App; /** * Mock-only factory: creates an app with a ready-made vault, as the test setup does for the global `app`. * * Without an adapter, the vault uses a `FileSystemAdapter` mock rooted at `/mock-vault`. Each entry of * `options.files` becomes a file, or a folder when its path ends with `/`; missing parent folders are created first. * * @param options - The adapter or its case sensitivity, the app id (`mock-app-id` by default) and the files to seed. * @returns The new app. * @throws Error when a folder entry has non-empty content. */ static createConfigured__(options?: AppCreateConfiguredOptions): App; /** * Mock-only: views a value typed as Obsidian's `App` as this mock. * * @param value - The value typed as the original `App`. * @returns The same object, typed as the mock. */ static fromOriginalType__(value: AppOriginal): App; /** * Mock-only: views this mock as Obsidian's `App` type. * * @returns The same object, typed as the original `App`. */ asOriginalType__(): AppOriginal; /** * Switches the theme, the way the appearance settings do. * * @param theme - The theme to switch to. */ changeTheme(theme: 'moonstone' | 'obsidian'): void; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(App.prototype, 'constructor__')`. * * @param _adapter - The adapter the app was created with. * @param _appId - The id the app was created with. */ constructor__(_adapter: DataAdapterOriginal, _appId: string): void; /** * Rewrites the `src` of every media element under an element so it loads from the vault, exactly as * Obsidian does after rendering HTML or markdown. Two rewrites, in Obsidian's own order: * * - On the desktop app, a `file:///` src is re-prefixed with `Platform.resourcePathPrefix`. * - An `img`, `audio`, `video` or `source` whose src points inside the vault is resolved through * `MetadataCache.getFirstLinkpathDest` and replaced with `Vault.getResourcePath`. An `iframe` is walked * but never resolved this way, as in Obsidian, and a src that resolves to nothing is left as it is. * * @param element - The element whose media descendants are rewritten. * @param sourcePath - The path of the note the HTML came from, which relative links resolve against. */ fixFileLinks(element: HTMLElement, sourcePath: string): void; /** * The active theme. * * @returns `'moonstone'` for the light theme, `'obsidian'` for the dark one. */ getTheme(): 'moonstone' | 'obsidian'; /** * Checks whether the dark theme is active. * * @returns `true` when the theme is `obsidian`; the mock starts in the light theme. */ isDarkMode(): boolean; /** * Retrieves a vault-specific value from `localStorage`. The mock keeps values in memory, per app instance. * * @param key - The key to read. * @returns The stored value, or `null` when nothing is stored under `key`. */ loadLocalStorage(key: string): unknown; /** * Saves a vault-specific value to `localStorage`; Obsidian clears the entry when `data` is `null`. The mock keeps * values in memory, per app instance, and stores `null` like any other value, which reads back the same as a cleared * entry. * * @param key - The key to write. * @param data - The value to save. */ saveLocalStorage(key: string, data: unknown): void; /** * Records the theme without applying it. * * Obsidian distinguishes this from {@link changeTheme}, which also re-renders; the mock has nothing * to re-render, so both simply store. * * @param theme - The theme to record. */ setTheme(theme: 'moonstone' | 'obsidian'): void; }