generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add tests for creating new note from template that updates fro…
…ntmatter after creation and tests for properties showing in live preview on insert of template with frontmatter refs: #1253, #1309
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect } from "chai"; | ||
import TestTemplaterPlugin from "../../main.test"; | ||
import { properties_are_visible } from "../utils.test"; | ||
|
||
export function InternalModuleHooksTests(t: TestTemplaterPlugin) { | ||
t.test( | ||
"tp.hooks.on_all_templates_executed shows properties in live preview", | ||
async () => { | ||
const template = `<%* | ||
tp.hooks.on_all_templates_executed(async () => { | ||
const file = tp.file.find_tfile(tp.file.path(true)); | ||
await app.fileManager.processFrontMatter(file, (frontmatter) => { | ||
frontmatter["key"] = "value"; | ||
}); | ||
}); | ||
%> | ||
TEXT THAT SHOULD STAY`; | ||
await t.run_in_new_leaf(template, "", true); | ||
expect(properties_are_visible()).to.be.true; | ||
await expect( | ||
t.run_and_get_output(template, "", true) | ||
).to.eventually.equal("\nTEXT THAT SHOULD STAY"); | ||
await expect( | ||
t.create_new_note_from_template_and_get_output(template) | ||
).to.eventually.equal( | ||
"---\nkey: value\n---\n\nTEXT THAT SHOULD STAY" | ||
); | ||
} | ||
); | ||
} |
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,13 @@ | ||
import { expect } from "chai"; | ||
import TestTemplaterPlugin from "../main.test"; | ||
import { properties_are_visible } from "./utils.test"; | ||
|
||
export function TemplaterTests(t: TestTemplaterPlugin) { | ||
t.test( | ||
"append_template_to_active_file shows properties in live preview", | ||
async () => { | ||
await t.run_in_new_leaf("---\nkey: value\n---\nText"); | ||
expect(properties_are_visible()).to.be.true; | ||
} | ||
); | ||
} |
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