diff --git a/src/Text.ts b/src/Text.ts index 3dd038b..7df45ee 100644 --- a/src/Text.ts +++ b/src/Text.ts @@ -1,5 +1,7 @@ import Field from "./Field"; +export type formatType = "plain" | "html" | "markdown" + /** * Multiline input with no length limit. */ @@ -45,6 +47,14 @@ class Text extends Field { this._translatable = value; } + _format: formatType = "plain"; + get format(): formatType { + return this._format; + } + set format(value: formatType) { + this._format = value; + } + constructor(props: any) { super(props); @@ -69,6 +79,9 @@ class Text extends Field { this.translatable = props.translate === "True" || props.translate === true ? true : false; } + if (this.parsedWidgetProps.hasOwnProperty("format")) { + this._format = this.parsedWidgetProps.format; + } } } } diff --git a/src/spec/Text.spec.ts b/src/spec/Text.spec.ts new file mode 100644 index 0000000..be2767f --- /dev/null +++ b/src/spec/Text.spec.ts @@ -0,0 +1,35 @@ +import WidgetFactory from "../WidgetFactory"; + +describe("A Text widget", () => { + it("should have an id corresponding to field name", () => { + const widgetFactory = new WidgetFactory(); + const props = { + name: "content", + }; + + const widget = widgetFactory.createWidget("text", props); + expect(widget.id).toBe("content"); + }); + + it("should have default format to plain", () => { + const widgetFactory = new WidgetFactory(); + const props = { + name: "content", + }; + const widget = widgetFactory.createWidget("text", props); + + expect(widget.format).toBe("plain"); + }); + + it("should properly set field", () => { + const widgetFactory = new WidgetFactory(); + const props = { + name: "content", + widget_props: "{'format': 'html'}", + }; + const widget = widgetFactory.createWidget("text", props); + + expect(widget.format).toBe("html"); + }); + +});