mirror of
https://github.com/dotwee/obsidian-raindropio-plugin.git
synced 2026-07-22 06:50:29 +00:00
test: cover show and hide parsing and field resolution
Verify parsing of show and hide block options, including casing, duplicates and unknown field warnings. Verify display field resolution layers show before hide and leaves the defaults untouched. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c12cf641b1
commit
ad2baee012
1 changed files with 62 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { extractFirstRaindropBlock, parseRaindropBlock } from "../src/block-parser";
|
import { extractFirstRaindropBlock, parseRaindropBlock } from "../src/block-parser";
|
||||||
|
import { DEFAULT_DISPLAY_FIELDS, resolveRaindropDisplayFields } from "../src/renderer";
|
||||||
|
|
||||||
describe("parseRaindropBlock", () => {
|
describe("parseRaindropBlock", () => {
|
||||||
it("parses supported key-value options", () => {
|
it("parses supported key-value options", () => {
|
||||||
|
|
@ -41,6 +42,67 @@ describe("parseRaindropBlock", () => {
|
||||||
expect(parsed.options.limit).toBe(1);
|
expect(parsed.options.limit).toBe(1);
|
||||||
expect(parsed.warnings).toEqual(["Invalid `limit`; using the plugin default."]);
|
expect(parsed.warnings).toEqual(["Invalid `limit`; using the plugin default."]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("parses show and hide field lists", () => {
|
||||||
|
const parsed = parseRaindropBlock(`
|
||||||
|
show: collection, cover
|
||||||
|
hide: excerpt, tags
|
||||||
|
`);
|
||||||
|
|
||||||
|
expect(parsed.options.showFields).toEqual(["collection", "cover"]);
|
||||||
|
expect(parsed.options.hideFields).toEqual(["excerpt", "tags"]);
|
||||||
|
expect(parsed.warnings).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("normalizes casing and duplicates in field lists", () => {
|
||||||
|
const parsed = parseRaindropBlock("show: Cover, cover, ,DOMAIN");
|
||||||
|
|
||||||
|
expect(parsed.options.showFields).toEqual(["cover", "domain"]);
|
||||||
|
expect(parsed.warnings).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("warns about unknown field names and keeps valid ones", () => {
|
||||||
|
const parsed = parseRaindropBlock("hide: excerpt, banana");
|
||||||
|
|
||||||
|
expect(parsed.options.hideFields).toEqual(["excerpt"]);
|
||||||
|
expect(parsed.warnings).toEqual([
|
||||||
|
"Unknown field `banana` in `hide`; expected one of cover, domain, created, excerpt, tags, collection.",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("omits field lists when no valid names remain", () => {
|
||||||
|
const parsed = parseRaindropBlock("show: banana");
|
||||||
|
|
||||||
|
expect(parsed.options.showFields).toBeUndefined();
|
||||||
|
expect(parsed.warnings).toHaveLength(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("resolveRaindropDisplayFields", () => {
|
||||||
|
it("returns the defaults when no overrides are given", () => {
|
||||||
|
expect(resolveRaindropDisplayFields(DEFAULT_DISPLAY_FIELDS)).toEqual(DEFAULT_DISPLAY_FIELDS);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("layers show and hide on top of the defaults", () => {
|
||||||
|
const fields = resolveRaindropDisplayFields(DEFAULT_DISPLAY_FIELDS, ["collection", "cover"], ["excerpt", "tags"]);
|
||||||
|
|
||||||
|
expect(fields).toEqual({
|
||||||
|
cover: true,
|
||||||
|
domain: true,
|
||||||
|
created: true,
|
||||||
|
excerpt: false,
|
||||||
|
tags: false,
|
||||||
|
collection: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("applies hide after show and does not mutate the defaults", () => {
|
||||||
|
const defaults = { ...DEFAULT_DISPLAY_FIELDS };
|
||||||
|
const fields = resolveRaindropDisplayFields(defaults, ["excerpt"], ["excerpt"]);
|
||||||
|
|
||||||
|
expect(fields.excerpt).toBe(false);
|
||||||
|
expect(defaults).toEqual(DEFAULT_DISPLAY_FIELDS);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("extractFirstRaindropBlock", () => {
|
describe("extractFirstRaindropBlock", () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue