mirror of
https://github.com/zadam/trilium.git
synced 2026-02-19 20:24:28 +01:00
test(server): fix test depending on note content
This commit is contained in:
parent
9332b9ca8f
commit
a3fca323c7
@ -3,6 +3,7 @@ import { trimIndentation } from "@triliumnext/commons";
|
|||||||
import becca from "../becca/becca.js";
|
import becca from "../becca/becca.js";
|
||||||
import BBranch from "../becca/entities/bbranch.js";
|
import BBranch from "../becca/entities/bbranch.js";
|
||||||
import BNote from "../becca/entities/bnote.js";
|
import BNote from "../becca/entities/bnote.js";
|
||||||
|
import { buildNote } from "../test/becca_easy_mocking.js";
|
||||||
import { note, NoteBuilder } from "../test/becca_mocking.js";
|
import { note, NoteBuilder } from "../test/becca_mocking.js";
|
||||||
import cls from "./cls.js";
|
import cls from "./cls.js";
|
||||||
import { buildJsx, executeBundle, getScriptBundle } from "./script.js";
|
import { buildJsx, executeBundle, getScriptBundle } from "./script.js";
|
||||||
@ -62,14 +63,15 @@ describe("Script", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("dayjs in backend scripts", () => {
|
describe("dayjs in backend scripts", () => {
|
||||||
const scriptNote = note("dayjs", {
|
const scriptNote = buildNote({
|
||||||
type: "code",
|
type: "code",
|
||||||
mime: "application/javascript;env=backend",
|
mime: "application/javascript;env=backend",
|
||||||
|
content: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
it("dayjs is available", () => {
|
it("dayjs is available", () => {
|
||||||
cls.init(() => {
|
cls.init(() => {
|
||||||
const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs().format("YYYY-MM-DD");`);
|
const bundle = getScriptBundle(scriptNote, true, "backend", [], `return api.dayjs().format("YYYY-MM-DD");`);
|
||||||
expect(bundle).toBeDefined();
|
expect(bundle).toBeDefined();
|
||||||
const result = executeBundle(bundle!);
|
const result = executeBundle(bundle!);
|
||||||
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
||||||
@ -78,7 +80,7 @@ describe("Script", () => {
|
|||||||
|
|
||||||
it("dayjs is-same-or-before plugin exists", () => {
|
it("dayjs is-same-or-before plugin exists", () => {
|
||||||
cls.init(() => {
|
cls.init(() => {
|
||||||
const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-01").isSameOrBefore(api.dayjs("2023-10-02"));`);
|
const bundle = getScriptBundle(scriptNote, true, "backend", [], `return api.dayjs("2023-10-01").isSameOrBefore(api.dayjs("2023-10-02"));`);
|
||||||
expect(bundle).toBeDefined();
|
expect(bundle).toBeDefined();
|
||||||
const result = executeBundle(bundle!);
|
const result = executeBundle(bundle!);
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import utils from "../services/utils.js";
|
import { NoteType } from "@triliumnext/commons";
|
||||||
import BNote from "../becca/entities/bnote.js";
|
|
||||||
import BAttribute from "../becca/entities/battribute.js";
|
import BAttribute from "../becca/entities/battribute.js";
|
||||||
import BBranch from "../becca/entities/bbranch.js";
|
import BBranch from "../becca/entities/bbranch.js";
|
||||||
import { NoteType } from "@triliumnext/commons";
|
import BNote from "../becca/entities/bnote.js";
|
||||||
|
import utils from "../services/utils.js";
|
||||||
|
|
||||||
type AttributeDefinitions = { [key in `#${string}`]: string; };
|
type AttributeDefinitions = { [key in `#${string}`]: string; };
|
||||||
type RelationDefinitions = { [key in `~${string}`]: string; };
|
type RelationDefinitions = { [key in `~${string}`]: string; };
|
||||||
@ -12,6 +13,7 @@ interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {
|
|||||||
title?: string;
|
title?: string;
|
||||||
content?: string;
|
content?: string;
|
||||||
type?: NoteType;
|
type?: NoteType;
|
||||||
|
mime?: string;
|
||||||
children?: NoteDefinition[];
|
children?: NoteDefinition[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,13 +47,13 @@ export function buildNote(noteDef: NoteDefinition) {
|
|||||||
noteId: noteDef.id ?? utils.randomString(12),
|
noteId: noteDef.id ?? utils.randomString(12),
|
||||||
title: noteDef.title ?? "New note",
|
title: noteDef.title ?? "New note",
|
||||||
type: noteDef.type ?? "text",
|
type: noteDef.type ?? "text",
|
||||||
mime: "text/html",
|
mime: noteDef.mime ?? "text/html",
|
||||||
isProtected: false,
|
isProtected: false,
|
||||||
blobId: ""
|
blobId: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle content.
|
// Handle content.
|
||||||
if (noteDef.content) {
|
if (noteDef.content !== undefined) {
|
||||||
note.getContent = () => noteDef.content!;
|
note.getContent = () => noteDef.content!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user