Skip to content

Commit 065f4ae

Browse files
authored
Merge pull request #169 from gisce/69452/label-date-without-human
Label: add human_date prop
2 parents f38c39b + 875313a commit 065f4ae

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Label.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Field from "./Field";
2+
import { parseBoolAttribute } from "./helpers/nodeParser";
23

34
type LabelType = "secondary" | "success" | "warning" | "danger" | "default";
45
type LabelSize = 1 | 2 | 3 | 4 | 5 | undefined;
@@ -52,6 +53,10 @@ class Label extends Field {
5253
this._labelSize = value;
5354
}
5455

56+
get humanDate(): boolean {
57+
return parseBoolAttribute(this._parsedWidgetProps?.human_date ?? false);
58+
}
59+
5560
/**
5661
* Id of the field that this label goes with. Null if it's an independent label
5762
*/

src/spec/Label.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,43 @@ describe("A Label", () => {
9191
});
9292
});
9393
});
94+
describe("Human date", () => {
95+
it("should have humanDate to false by default", () => {
96+
const widgetFactory = new WidgetFactory();
97+
const props = {
98+
name: "field_label",
99+
string: "Default",
100+
widget_props: "{}",
101+
};
102+
const widget = widgetFactory.createWidget("label", props);
103+
expect(widget.humanDate).toBe(false);
104+
});
105+
it("should parse human_date from widget props", () => {
106+
const widgetFactory = new WidgetFactory();
107+
108+
expect(
109+
widgetFactory.createWidget("label", {
110+
name: "field_label",
111+
string: "Default",
112+
widget_props: "{'human_date': true}",
113+
}).humanDate,
114+
).toBe(true);
115+
116+
expect(
117+
widgetFactory.createWidget("label", {
118+
name: "field_label",
119+
string: "Default",
120+
widget_props: "{'human_date': false}",
121+
}).humanDate,
122+
).toBe(false);
123+
124+
expect(
125+
widgetFactory.createWidget("label", {
126+
name: "field_label",
127+
string: "Default",
128+
widget_props: "{'human_date': '1'}",
129+
}).humanDate,
130+
).toBe(true);
131+
});
132+
});
94133
});

0 commit comments

Comments
 (0)