-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from nathonius/test/107/jest
Unit tests
- Loading branch information
Showing
15 changed files
with
5,877 additions
and
1,444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
# vscode | ||
.vscode | ||
|
||
# Intellij | ||
*.iml | ||
.idea | ||
|
||
# npm | ||
node_modules | ||
|
||
# Don't include the compiled main.js file in the repo. | ||
# They should be uploaded to GitHub releases instead. | ||
main.js | ||
|
||
# Exclude sourcemaps | ||
*.map | ||
|
||
# obsidian | ||
data.json | ||
|
||
# Exclude macOS Finder (System Explorer) View States | ||
.DS_Store | ||
# vscode | ||
.vscode | ||
|
||
# Intellij | ||
*.iml | ||
.idea | ||
|
||
# npm | ||
node_modules | ||
|
||
# Don't include the compiled main.js file in the repo. | ||
# They should be uploaded to GitHub releases instead. | ||
main.js | ||
|
||
# Exclude sourcemaps | ||
*.map | ||
|
||
# obsidian | ||
data.json | ||
|
||
# Exclude macOS Finder (System Explorer) View States | ||
.DS_Store | ||
|
||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { AppMock } from "./obsidian/App"; | ||
import { PluginMock } from "./obsidian/Plugin"; | ||
import { ModalMock } from "./obsidian/Modal"; | ||
import { PluginSettingTabMock } from "./obsidian/PluginSettingTab"; | ||
|
||
module.exports = { | ||
App: AppMock, | ||
Plugin: PluginMock, | ||
Modal: ModalMock, | ||
PluginSettingTab: PluginSettingTabMock, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { App, FileManager, Keymap, MetadataCache, Scope, UserEvent, Vault, Workspace } from "obsidian"; | ||
|
||
export class AppMock implements App { | ||
get keymap(): Keymap { | ||
throw new Error("Not implemented."); | ||
} | ||
get scope(): Scope { | ||
throw new Error("Not implemented."); | ||
} | ||
get workspace(): Workspace { | ||
throw new Error("Not implemented."); | ||
} | ||
get vault(): Vault { | ||
throw new Error("Not implemented."); | ||
} | ||
get metadataCache(): MetadataCache { | ||
throw new Error("Not implemented."); | ||
} | ||
get fileManager(): FileManager { | ||
throw new Error("Not implemented."); | ||
} | ||
get lastEvent(): UserEvent | null { | ||
throw new Error("Not implemented."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { App, Scope } from "obsidian"; | ||
import type { Modal } from "obsidian"; | ||
|
||
export class ModalMock implements Modal { | ||
constructor(public app: App) {} | ||
get scope(): Scope { | ||
throw new Error("Not implemented."); | ||
} | ||
get containerEl(): HTMLElement { | ||
throw new Error("Not implemented."); | ||
} | ||
get modalEl(): HTMLElement { | ||
throw new Error("Not implemented."); | ||
} | ||
get titleEl(): HTMLElement { | ||
throw new Error("Not implemented."); | ||
} | ||
get contentEl(): HTMLElement { | ||
throw new Error("Not implemented."); | ||
} | ||
shouldRestoreSelection: boolean = false; | ||
open(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
close(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
onOpen(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
onClose(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* eslint-disable unused-imports/no-unused-vars */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { jest } from "@jest/globals"; | ||
import type { Editor } from "codemirror"; | ||
import type { | ||
App, | ||
Command, | ||
Component, | ||
EditorSuggest, | ||
EventRef, | ||
HoverLinkSource, | ||
ObsidianProtocolHandler, | ||
Plugin, | ||
PluginManifest, | ||
ViewCreator, | ||
} from "obsidian"; | ||
|
||
export class PluginMock implements Plugin { | ||
public data: any = undefined; | ||
public intervals: number[] = []; | ||
public addSettingTab = jest.fn(); | ||
public registerEditorExtension = jest.fn(); | ||
public registerInterval = jest.fn((interval: number) => { | ||
this.intervals.push(interval); | ||
return interval; | ||
}); | ||
public registerMarkdownCodeBlockProcessor = jest.fn(() => { | ||
return jest.fn(() => Promise.resolve()); | ||
}); | ||
public registerMarkdownPostProcessor = jest.fn(() => { | ||
return jest.fn(() => Promise.resolve()); | ||
}); | ||
|
||
constructor( | ||
public app: App, | ||
public manifest: PluginManifest, | ||
) {} | ||
|
||
addRibbonIcon(icon: string, title: string, callback: (evt: MouseEvent) => any): HTMLElement { | ||
throw new Error("Method not implemented."); | ||
} | ||
addStatusBarItem(): HTMLElement { | ||
throw new Error("Method not implemented."); | ||
} | ||
addCommand(command: Command): Command { | ||
throw new Error("Method not implemented."); | ||
} | ||
registerView(type: string, viewCreator: ViewCreator): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
registerHoverLinkSource(id: string, info: HoverLinkSource): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
registerExtensions(extensions: string[], viewType: string): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
|
||
registerCodeMirror(callback: (cm: Editor) => any): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
|
||
registerObsidianProtocolHandler(action: string, handler: ObsidianProtocolHandler): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
registerEditorSuggest(editorSuggest: EditorSuggest<any>): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
loadData(): Promise<any> { | ||
return Promise.resolve(this.data); | ||
} | ||
saveData(data: any): Promise<void> { | ||
this.data = data; | ||
return Promise.resolve(); | ||
} | ||
load(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
onload(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
unload(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
onunload(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
addChild<T extends Component>(component: T): T { | ||
throw new Error("Method not implemented."); | ||
} | ||
removeChild<T extends Component>(component: T): T { | ||
throw new Error("Method not implemented."); | ||
} | ||
register(cb: () => any): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
registerEvent(eventRef: EventRef): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
registerDomEvent<K extends keyof WindowEventMap>( | ||
el: Window, | ||
type: K, | ||
callback: (this: HTMLElement, ev: WindowEventMap[K]) => any, | ||
options?: boolean | AddEventListenerOptions | undefined, | ||
): void; | ||
registerDomEvent<K extends keyof DocumentEventMap>( | ||
el: Document, | ||
type: K, | ||
callback: (this: HTMLElement, ev: DocumentEventMap[K]) => any, | ||
options?: boolean | AddEventListenerOptions | undefined, | ||
): void; | ||
registerDomEvent<K extends keyof HTMLElementEventMap>( | ||
el: HTMLElement, | ||
type: K, | ||
callback: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, | ||
options?: boolean | AddEventListenerOptions | undefined, | ||
): void; | ||
registerDomEvent(el: unknown, type: unknown, callback: unknown, options?: unknown): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { App, PluginSettingTab, Plugin } from "obsidian"; | ||
|
||
export class PluginSettingTabMock implements PluginSettingTab { | ||
constructor( | ||
public app: App, | ||
public plugin: Plugin, | ||
) {} | ||
get containerEl(): HTMLElement { | ||
throw new Error("Not implemented."); | ||
} | ||
display() { | ||
throw new Error("Method not implemented."); | ||
} | ||
hide() { | ||
throw new Error("Method not implemented."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import type { EventListenerOrEventListenerObject, EventsMap, QueueEvent, QueueWorker } from "queue"; | ||
import type Queue from "queue"; | ||
import type { Options } from "queue"; | ||
|
||
export default class QueueMock implements Queue { | ||
concurrency: number; | ||
timeout: number; | ||
autostart: boolean; | ||
results: any[] | null; | ||
length: number = 0; | ||
|
||
constructor(options: Options) { | ||
this.concurrency = options.concurrency ?? 1; | ||
this.timeout = options.timeout ?? -1; | ||
this.autostart = options.autostart ?? false; | ||
this.results = options.results ?? []; | ||
} | ||
|
||
push(...workers: QueueWorker[]): number { | ||
for (const worker of workers) { | ||
void worker(); | ||
} | ||
return 0; | ||
} | ||
unshift(...workers: QueueWorker[]): number { | ||
throw new Error("Method not implemented."); | ||
} | ||
splice(start: number, deleteCount?: number | undefined): Queue; | ||
splice(start: number, deleteCount: number, ...workers: QueueWorker[]): Queue; | ||
splice(start: unknown, deleteCount?: unknown, ...rest: unknown[]): Queue { | ||
throw new Error("Method not implemented."); | ||
} | ||
pop(): QueueWorker | undefined { | ||
throw new Error("Method not implemented."); | ||
} | ||
shift(): QueueWorker | undefined { | ||
throw new Error("Method not implemented."); | ||
} | ||
slice(start?: number | undefined, end?: number | undefined): Queue { | ||
throw new Error("Method not implemented."); | ||
} | ||
reverse(): Queue { | ||
throw new Error("Method not implemented."); | ||
} | ||
indexOf(searchElement: QueueWorker, fromIndex?: number | undefined): number { | ||
throw new Error("Method not implemented."); | ||
} | ||
lastIndexOf(searchElement: QueueWorker, fromIndex?: number | undefined): number { | ||
throw new Error("Method not implemented."); | ||
} | ||
start(callback: (error?: Error | undefined, results?: any[] | null | undefined) => void): void; | ||
start(): Promise<{ error?: Error | undefined; results?: any[] | null | undefined }>; | ||
start(): void; | ||
start(callback?: unknown): void | Promise<{ error?: Error | undefined; results?: any[] | null | undefined }> { | ||
throw new Error("Method not implemented."); | ||
} | ||
stop(): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
end(error?: Error | undefined): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
addEventListener<Event extends keyof EventsMap>( | ||
name: Event, | ||
callback: EventListenerOrEventListenerObject<QueueEvent<Event, EventsMap[Event]>>, | ||
options?: boolean | AddEventListenerOptions | undefined, | ||
): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
dispatchEvent<Event extends keyof EventsMap>(event: QueueEvent<Event, EventsMap[Event]>): boolean { | ||
throw new Error("Method not implemented."); | ||
} | ||
removeEventListener<Event extends keyof EventsMap>( | ||
name: Event, | ||
callback: EventListenerOrEventListenerObject<QueueEvent<Event, EventsMap[Event]>>, | ||
options?: boolean | EventListenerOptions | undefined, | ||
): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.