Files
obsidian_ollama/__mocks__/obsidian.ts
T
fegger 810676ff21 feat: add Ollama icon and modern chat UI styling
- src/chat-view.ts: Add getIcon() returning 'bot' for the view tab icon.
  Improve render() with role-specific CSS classes (user vs assistant) and
  message header structure for better styling hooks.

- src/main.ts: Add ribbon icon ('bot') in the left sidebar that opens the
  chat view with a single click.

- styles.css (new): Modern chat UI with message bubbles, distinct user and
  assistant themes using Obsidian CSS variables, sticky input bar, styled
  send button with accent color, and emoji role indicators.

- install.sh: Copy styles.css into the plugin directory and verify its
  presence during installation.

- README.md: Include styles.css in manual install instructions.

- __mocks__/obsidian.ts: Add addRibbonIcon() mock for test compatibility.

- tests/chat-view.test.ts: Add getIcon() assertion.
2026-05-19 21:18:56 +02:00

118 lines
2.1 KiB
TypeScript
Executable File

// Enhanced Obsidian mock for testing
// Mock Vault
export class Vault {
getMarkdownFiles: () => any[];
read: (file: any) => Promise<string>;
create: (path: string, content: string) => Promise<any>;
constructor() {
this.getMarkdownFiles = () => [];
this.read = async () => '';
this.create = async () => null;
}
}
// Mock Workspace
export class Workspace {
getLeaf: () => any;
constructor() {
this.getLeaf = () => ({
setViewState: jest.fn(),
revealLeaf: jest.fn(),
});
}
}
// Mock App
export class App {
vault: Vault;
workspace: Workspace;
constructor() {
this.vault = new Vault();
this.workspace = new Workspace();
}
}
// Mock WorkspaceLeaf
export class WorkspaceLeaf {
app: App;
view: any;
setViewState: jest.Mock;
constructor() {
this.app = new App();
this.view = null;
this.setViewState = jest.fn();
}
}
// Mock ItemView - accepts a leaf and derives app from it
export class ItemView {
contentEl: HTMLElement;
app: App;
constructor(leaf?: WorkspaceLeaf) {
this.contentEl = document.createElement('div');
if (leaf && leaf.app) {
this.app = leaf.app;
} else {
this.app = new App();
}
}
}
// Mock Notice - can be called with `new Notice(msg)` or as a function
export class Notice {
message: string;
constructor(message: string) {
this.message = message;
// Also record via jest for testing
(Notice as any).lastMessage = message;
}
}
(Notice as any).lastMessage = '';
// Mock Setting
export class Setting {
containerEl: HTMLElement;
constructor(containerEl: HTMLElement) {
this.containerEl = containerEl;
}
setName(_name: string): this {
return this;
}
setDesc(_desc: string): this {
return this;
}
addText(_callback: (text: any) => void): this {
return this;
}
}
// TFile type
export interface TFile {
basename: string;
path: string;
}
// Plugin class (used by main.ts)
export class Plugin {
app: App;
constructor() {
this.app = new App();
}
addRibbonIcon(_icon: string, _title: string, _callback: () => void): HTMLElement {
return document.createElement('div');
}
}