Files
obsidian-remarkable/tests/browser-modal.test.ts
T
fegger 07f4c27d58 Add reMarkable browser modal with import and conversion options
The browser modal allows users to navigate their reMarkable file structure, view documents and folders, and perform
actions on individual files. Users can either import documents directly or convert handwriting to Markdown during
import.

The implementation includes:
- New ribbon icon and command to open the browser
- Modal UI with navigation controls (up/refresh)
- Document listing with folder traversal
- Per-file actions: Import and Handwriting to Markdown
- Proper error handling and user feedback
- Comprehensive tests for the new functionality

The downloader was also enhanced to support the new conversion options through a more flexible interface.
2026-05-31 17:41:40 +02:00

61 lines
1.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { ButtonComponent } from "obsidian";
import { RemarkableBrowserModal } from "../src/ui/browser-modal";
import { RmapiNode } from "../src/types";
function createDocument(name: string): RmapiNode {
return {
id: `id-${name}`,
name,
type: "DocumentType",
version: 1,
modifiedClient: "2026-05-31T10:00:00Z",
currentPage: 0,
parent: "",
tags: [],
starred: false,
};
}
function createPlugin(nodes: RmapiNode[]) {
const calls: any[] = [];
const plugin: any = {
app: {},
rmapi: {
list: async () => nodes,
},
downloader: {
downloadDocument: async (...args: any[]) => {
calls.push(args);
},
},
};
return { calls, plugin };
}
test("RemarkableBrowserModal creates import and handwriting buttons for documents", async () => {
ButtonComponent.instances = [];
const doc = createDocument("Meeting Notes");
const { calls, plugin } = createPlugin([doc]);
const modal = new RemarkableBrowserModal(plugin);
modal.onOpen();
await new Promise((resolve) => setImmediate(resolve));
const importButton = ButtonComponent.instances.find((button) => button.buttonEl.text === "Import");
const markdownButton = ButtonComponent.instances.find((button) => button.buttonEl.text === "Handwriting to Markdown");
assert.ok(importButton);
assert.ok(markdownButton);
await importButton.click();
await markdownButton.click();
assert.deepEqual(calls, [
[{ node: doc, remotePath: "/Meeting Notes" }, { convertToMd: false, forceDownload: true }],
[{ node: doc, remotePath: "/Meeting Notes" }, { convertToMd: true, forceDownload: true }],
]);
});