Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F1262301
api.test.ts
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
api.test.ts
View Options
// commented out as we're postponing the pandoc-style primitives based rendering until v2
// import { Registry } from "./registry.js";
// import assert from "assert";
// import { BlockPrimitive } from "./primitives/block.js";
// import { Primitive, PrimitiveJSON } from "./primitives/primitive.js";
// import { HeadingPrimitive } from "./primitives/heading.js";
// import { assertThrowsAsync } from "./utils/assert-throws.js";
// import { parse_primitives } from "./primitives/parse_primitives.js";
// import { resolve_component } from "./pipeline.js";
// import { TextJSON } from "./primitives/text.js";
// describe("api tests", () => {
// it("has ability to add custom components", () => {
// const reg = new Registry();
// reg.register_component(
// "custom",
// (json: Record<string, unknown>): PrimitiveJSON => {
// return {
// type: "text",
// content: json["content"] as string,
// } as TextJSON;
// }
// );
// let primitives: Record<string, unknown> = resolve_component(
// reg,
// "custom",
// {
// type: "custom",
// content: "sample",
// }
// );
// assert.deepEqual(primitives, {
// type: "text",
// content: "sample",
// });
// });
// describe("has ability to extract information from the document", () => {
// let parsed_block: Primitive;
// before(() => {
// parsed_block = parse_primitives([
// {
// type: "block",
// content: [
// {
// type: "heading",
// content: "sampleH",
// level: 1,
// },
// {
// type: "heading",
// content: "sampleH2",
// level: 1,
// },
// {
// type: "image",
// content: "sampleI",
// },
// {
// type: "image",
// content: "sampleI2",
// },
// ],
// },
// ])[0];
// });
// it("extract headings", () => {
// assert.deepEqual(parsed_block.extract_headings(), [
// new HeadingPrimitive({
// type: "heading",
// content: "sampleH",
// level: 1,
// }),
// new HeadingPrimitive({
// type: "heading",
// content: "sampleH2",
// level: 1,
// }),
// ]);
// });
// it("extract images", () => {
// assert.deepEqual(parsed_block.extract_images(), [
// "sampleI",
// "sampleI2",
// ]);
// });
// });
// it("has ability to add a custom output format without changing jdd code itself", () => {
// function render(primitives: Primitive[]): number {
// let counter = 0;
// for (const primitive of primitives) {
// counter += primitive.extract_headings().length;
// }
// return counter;
// }
// assert.strictEqual(
// render([
// new BlockPrimitive({
// type: "block",
// content: [
// {
// type: "heading",
// content: "sample",
// level: 1,
// },
// ],
// }),
// new HeadingPrimitive({ content: "sample1", level: 1 }),
// ]),
// 2
// );
// });
// it("has ability to modify parsed primitives before rendering", () => {
// const parsed_block = parse_primitives([
// {
// type: "block",
// content: [
// {
// type: "block",
// content: [
// {
// type: "heading",
// content: "sampleH",
// level: 1,
// },
// ],
// },
// {
// type: "heading",
// content: "sampleH2",
// level: 2,
// },
// ],
// },
// ])[0] as any;
// for (const heading of parsed_block.extract_headings()) {
// heading.level += 1;
// }
// assert.strictEqual(
// parsed_block["content"][0]["content"][0]["level"],
// 2
// );
// assert.strictEqual(parsed_block["content"][1]["level"], 3);
// });
// // will make it pass when assertShape gets added to ts-predicates
// it.skip("parse_primitives throws when given wrong input", async () => {
// await assertThrowsAsync(
// async () => {
// return parse_primitives([
// {
// type: "block",
// content: [
// {
// type: "heading",
// content: "sampleH",
// },
// ],
// },
// ]);
// },
// (e: unknown) => {
// assert.strictEqual(
// (e as Error).message,
// "Missing 'level attribute' in heading 'sampleH'"
// );
// }
// );
// });
// });
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 23, 19:19 (19 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
600482
Default Alt Text
api.test.ts (4 KB)
Attached To
Mode
rJDD jdd
Attached
Detach File
Event Timeline
Log In to Comment