Page MenuHomeSealhub

component-arguments.test.ts
No OneTemporary

component-arguments.test.ts

import assert from "assert";
import { List } from "./list";
import { Image } from "./image";
import { ShortText } from "./short-text";
import { Structured } from "./structured";
import { Enum } from "./enum";
import { MarkdownArgument } from "./markdown";
import { Component } from "../component";
import { ComponentArgument } from "./component-argument";
import { simpleJDDContext } from "../jdd-context";
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(simpleJDDContext);
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(simpleJDDContext);
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(simpleJDDContext),
["a", "b", "c"]
);
});
});
});

File Metadata

Mime Type
text/x-java
Expires
Wed, May 7, 19:49 (22 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
636177
Default Alt Text
component-arguments.test.ts (2 KB)

Event Timeline