Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178// src/plugin/__tests__/warn-once.test.ts/** * Tests for warn-once instrumentation on stub no-ops. * Covers: foldManager, dragManager, registerObsidianProtocolHandler */
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'import { App, _resetAppWarnedStubs } from '../app'import { Vault } from '../vault'import { Workspace } from '../workspace'import { Plugin, _resetPluginWarnedStubs } from '../plugin'import { FileIndex } from '../../services/file-index'import type { PluginManifest } from '../types'import type { AutomergeUrl } from '@automerge/automerge-repo'
function createMockDocumentManager() { return { createFile: vi.fn(), createFolder: vi.fn(), createFileInFolder: vi.fn().mockImplementation( async () => `automerge:file-${Math.random().toString(36).slice(2)}` as AutomergeUrl ), readText: vi.fn(async (url: AutomergeUrl) => ({ status: 'unavailable' as const, documentId: url })), updateContent: vi.fn(), } as any}
// Helper to create a minimal App for testingfunction createTestApp(): App { const dm = createMockDocumentManager() const vault = new Vault('Test', new FileIndex(dm, 'automerge:root' as any), dm) const workspace = new Workspace(document.createElement('div')) return new App(vault, workspace)}
// Helper to create a test pluginfunction createTestPlugin(app: App): Plugin { const manifest: PluginManifest = { id: 'test-plugin', name: 'Test Plugin', version: '1.0.0', minAppVersion: '1.0.0', author: 'Test', description: 'Test plugin', }
// Create a concrete plugin class class TestPlugin extends Plugin { onload() {} }
return new TestPlugin(app, manifest)}
describe('App stub warn-once', () => { let app: App let warnSpy: ReturnType<typeof vi.spyOn>
beforeEach(() => { _resetAppWarnedStubs() app = createTestApp() warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) })
afterEach(() => { app.destroy() warnSpy.mockRestore() })
describe('foldManager', () => { it('foldManager.save warns once', () => { app.foldManager.save({}) expect(warnSpy).toHaveBeenCalledTimes(1) expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining('foldManager.save') )
// Second call should not warn again app.foldManager.save({}) expect(warnSpy).toHaveBeenCalledTimes(1) })
it('foldManager.load warns once', () => { app.foldManager.load({}) expect(warnSpy).toHaveBeenCalledTimes(1) expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining('foldManager.load') )
// Second call should not warn again const result = app.foldManager.load({}) expect(warnSpy).toHaveBeenCalledTimes(1) expect(result).toBeNull() })
it('foldManager.save and .load have separate warn keys', () => { app.foldManager.save({}) expect(warnSpy).toHaveBeenCalledTimes(1)
app.foldManager.load({}) expect(warnSpy).toHaveBeenCalledTimes(2) }) })
describe('dragManager', () => { it('dragManager.dragFile warns once', () => { app.dragManager.dragFile({} as DragEvent, {}) expect(warnSpy).toHaveBeenCalledTimes(1) expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining('dragManager.dragFile') )
// Second call should not warn again app.dragManager.dragFile({} as DragEvent, {}) expect(warnSpy).toHaveBeenCalledTimes(1) })
it('dragManager.onDragStart warns once', () => { app.dragManager.onDragStart({} as DragEvent, {}) expect(warnSpy).toHaveBeenCalledTimes(1) expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining('dragManager.onDragStart') )
// Second call should not warn again app.dragManager.onDragStart({} as DragEvent, {}) expect(warnSpy).toHaveBeenCalledTimes(1) }) })})
describe('Plugin.registerObsidianProtocolHandler warn-once', () => { let app: App let plugin: Plugin let warnSpy: ReturnType<typeof vi.spyOn>
beforeEach(() => { _resetPluginWarnedStubs() app = createTestApp() plugin = createTestPlugin(app) plugin.load() warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) })
afterEach(() => { plugin.unload() app.destroy() warnSpy.mockRestore() })
it('warns once per action', () => { plugin.registerObsidianProtocolHandler('my-action', () => {}) expect(warnSpy).toHaveBeenCalledTimes(1) expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining("registerObsidianProtocolHandler('my-action')") )
// Same action again should not warn plugin.registerObsidianProtocolHandler('my-action', () => {}) expect(warnSpy).toHaveBeenCalledTimes(1) })
it('warns separately for different actions', () => { plugin.registerObsidianProtocolHandler('action-a', () => {}) expect(warnSpy).toHaveBeenCalledTimes(1)
plugin.registerObsidianProtocolHandler('action-b', () => {}) expect(warnSpy).toHaveBeenCalledTimes(2) })
it('includes message about web app limitation', () => { plugin.registerObsidianProtocolHandler('test', () => {}) expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining('web app') ) })})