Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text html editor #63

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Field from "./Field";

export type formatType = "plain" | "html" | "markdown"

/**
* Multiline input with no length limit.
*/
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/spec/Text.spec.ts
Original file line number Diff line number Diff line change
@@ -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");
});

});
Loading