File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1
1
import Field from "./Field" ;
2
+ import { parseBoolAttribute } from "./helpers/nodeParser" ;
2
3
3
4
type LabelType = "secondary" | "success" | "warning" | "danger" | "default" ;
4
5
type LabelSize = 1 | 2 | 3 | 4 | 5 | undefined ;
@@ -52,6 +53,10 @@ class Label extends Field {
52
53
this . _labelSize = value ;
53
54
}
54
55
56
+ get humanDate ( ) : boolean {
57
+ return parseBoolAttribute ( this . _parsedWidgetProps ?. human_date ?? false ) ;
58
+ }
59
+
55
60
/**
56
61
* Id of the field that this label goes with. Null if it's an independent label
57
62
*/
Original file line number Diff line number Diff line change @@ -91,4 +91,43 @@ describe("A Label", () => {
91
91
} ) ;
92
92
} ) ;
93
93
} ) ;
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
+ } ) ;
94
133
} ) ;
You can’t perform that action at this time.
0 commit comments