Skip to content

Commit

Permalink
Merge pull request #169 from gisce/69452/label-date-without-human
Browse files Browse the repository at this point in the history
Label: add human_date prop
  • Loading branch information
ecarreras authored Feb 3, 2025
2 parents f38c39b + 875313a commit 065f4ae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Label.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Field from "./Field";
import { parseBoolAttribute } from "./helpers/nodeParser";

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

get humanDate(): boolean {
return parseBoolAttribute(this._parsedWidgetProps?.human_date ?? false);
}

/**
* Id of the field that this label goes with. Null if it's an independent label
*/
Expand Down
39 changes: 39 additions & 0 deletions src/spec/Label.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,43 @@ describe("A Label", () => {
});
});
});
describe("Human date", () => {
it("should have humanDate to false by default", () => {
const widgetFactory = new WidgetFactory();
const props = {
name: "field_label",
string: "Default",
widget_props: "{}",
};
const widget = widgetFactory.createWidget("label", props);
expect(widget.humanDate).toBe(false);
});
it("should parse human_date from widget props", () => {
const widgetFactory = new WidgetFactory();

expect(
widgetFactory.createWidget("label", {
name: "field_label",
string: "Default",
widget_props: "{'human_date': true}",
}).humanDate,
).toBe(true);

expect(
widgetFactory.createWidget("label", {
name: "field_label",
string: "Default",
widget_props: "{'human_date': false}",
}).humanDate,
).toBe(false);

expect(
widgetFactory.createWidget("label", {
name: "field_label",
string: "Default",
widget_props: "{'human_date': '1'}",
}).humanDate,
).toBe(true);
});
});
});

0 comments on commit 065f4ae

Please sign in to comment.