Page MenuHomeSealhub

component-arguments.test.ts
No OneTemporary

component-arguments.test.ts

import assert from "assert";
import { List } from "./list.js";
import { Image } from "./image.js";
import { ShortText } from "./short-text.js";
import { Structured } from "./structured.js";
import { Enum } from "./enum.js";
import { MarkdownArgument } from "./markdown.js";
import { Component } from "../component.js";
import { ComponentArgument } from "./component-argument.js";
import { URL } from "./url.js";
import { FileManager } from "@sealcode/file-manager";
import { makeSimpleJDDContext } from "../jdd-context.js";
describe("component arguments", () => {
it("handles nesting objects and arrays", () => {
new List(new ShortText());
new List(
new Structured({ name: new ShortText(), surname: new ShortText() })
);
});
it("handles enums", () => {
new Enum(<const>["hamster", "dentist"]);
});
it("Gives a nice example", async () => {
await new MarkdownArgument().getExampleValue(
makeSimpleJDDContext(new FileManager("/tmp", "/uploaded_files"))
);
const args = <const>{
text: new ShortText(),
markdown: new MarkdownArgument(),
};
const component = new (class testComponent extends Component<
typeof args
> {
getArguments() {
return args;
}
toHTML() {
return "";
}
})();
const example = await component.getExampleValues(
makeSimpleJDDContext(new FileManager("/tmp", "/uploaded_files"))
);
assert(example.text.length > 0);
assert(example.markdown.length > 0);
});
it("allows for chaining methods when setting example values", () => {
const the_argument = new MarkdownArgument().setExampleValues([
"abc1",
"abc2",
]);
assert((the_argument as any) instanceof ComponentArgument);
});
describe("Word counting", () => {
it("Image argument", () => {
assert.strictEqual(new Image().countWords(), 0);
});
it("Enum argument", () => {
assert.strictEqual(
new Enum(<const>["hamster", "dentist"]).countWords(),
0
);
});
it("ShortText argument", () => {
assert.strictEqual(new ShortText().countWords("Test ShortText"), 2);
});
it("ShortText argument", () => {
assert.strictEqual(new ShortText().countWords("Test ShortText"), 2);
});
it("MarkdownArgument argument", () => {
assert.strictEqual(
new MarkdownArgument().countWords(
"*Lorem ipsum* dolor sit amet, **consectetur adipiscing elit**."
),
8
);
});
it("List argument", () => {
assert.strictEqual(
new List(new ShortText()).countWords([
"Test ShortText 1",
"Test ShortText 2",
]),
6
);
});
it("Structured argument", () => {
assert.strictEqual(
new Structured({
fullname: new ShortText(),
age: new ShortText(),
}).countWords({ fullname: "Joe Done", age: "34" }),
3
);
});
});
describe("List argument", () => {
it("Generates example values from provided examples, if they are provided", async () => {
const list = new List(new ShortText()).setExampleValues([
["a", "b", "c"],
]);
assert.deepStrictEqual(
await list.getExampleValue(
makeSimpleJDDContext(
new FileManager("/tmp", "/uploaded_files")
)
),
["a", "b", "c"]
);
});
});
describe("test URL component argument class", () => {
it("allows for chaining methods when setting example values", () => {
const the_argument = new URL("relative").setExampleValues([
"/example",
"https://example.com",
]);
assert((the_argument as any) instanceof ComponentArgument);
});
it("returns example url of type based on specyfic urlType argument", () => {
const relativeUrl = new URL("relative").getExampleValue();
assert(
relativeUrl &&
typeof relativeUrl === "string" &&
!relativeUrl.includes("http")
);
const absoluteUrl = new URL("absolute").getExampleValue();
assert(
absoluteUrl &&
typeof absoluteUrl === "string" &&
absoluteUrl.includes("http")
);
});
it("returns correct component argument type", () => {
const argumentType = new URL("relative");
assert(argumentType instanceof URL);
assert(argumentType.getTypeName() === "url");
const argumentType2 = new URL("absolute");
assert(argumentType2 instanceof URL);
assert(argumentType2.getTypeName() === "url");
});
});
});

File Metadata

Mime Type
text/x-java
Expires
Sun, Jul 13, 06:51 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
804032
Default Alt Text
component-arguments.test.ts (4 KB)

Event Timeline