Skip to content

Commit e6ebd25

Browse files
authored
feat: add constructor overloads for dashboard widget (#6841)
1 parent 890ffe3 commit e6ebd25

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/main/java/com/vaadin/flow/component/dashboard/DashboardWidget.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,51 @@ public class DashboardWidget extends Component {
3939

4040
private boolean featureFlagEnabled;
4141

42+
/**
43+
* Creates an empty widget.
44+
*/
45+
public DashboardWidget() {
46+
this(null, null);
47+
}
48+
49+
/**
50+
* Creates a widget with the specified title.
51+
*
52+
* @param title
53+
* the title to set
54+
*/
55+
public DashboardWidget(String title) {
56+
this(title, null);
57+
}
58+
59+
/**
60+
* Creates a widget with the specified content.
61+
*
62+
* @param content
63+
* the content to set
64+
*/
65+
public DashboardWidget(Component content) {
66+
this(null, content);
67+
}
68+
69+
/**
70+
* Creates a widget with the specified title and content.
71+
*
72+
* @param title
73+
* the title to set
74+
* @param content
75+
* the content to set
76+
*/
77+
public DashboardWidget(String title, Component content) {
78+
super();
79+
if (title != null) {
80+
setTitle(title);
81+
}
82+
if (content != null) {
83+
setContent(content);
84+
}
85+
}
86+
4287
/**
4388
* Returns the title of the widget.
4489
*

vaadin-dashboard-flow-parent/vaadin-dashboard-flow/src/test/java/com/vaadin/flow/component/dashboard/DashboardWidgetTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public void setTitle_returnsCorrectTitle() {
3030
Assert.assertEquals(valueToSet, widget.getTitle());
3131
}
3232

33+
@Test
34+
public void setTitleInConstructor_returnsCorrectTitle() {
35+
var valueToSet = "New title";
36+
var widget = new DashboardWidget(valueToSet);
37+
widget.setFeatureFlagEnabled(true);
38+
widget.setTitle(valueToSet);
39+
Assert.assertEquals(valueToSet, widget.getTitle());
40+
}
41+
3342
@Test
3443
public void setTitleNull_returnsEmptyTitle() {
3544
DashboardWidget widget = getNewWidget();
@@ -143,6 +152,24 @@ public void setContentToEmptyWidget_correctContentIsSet() {
143152
Assert.assertEquals(content, widget.getContent());
144153
}
145154

155+
@Test
156+
public void setContentInConstructor_correctContentIsSet() {
157+
var content = new Div();
158+
var widget = new DashboardWidget(content);
159+
widget.setFeatureFlagEnabled(true);
160+
Assert.assertEquals(content, widget.getContent());
161+
}
162+
163+
@Test
164+
public void setTitleAndContentInConstructor_correctValuesAreSet() {
165+
var title = "New title";
166+
var content = new Div();
167+
var widget = new DashboardWidget(title, content);
168+
widget.setFeatureFlagEnabled(true);
169+
Assert.assertEquals(title, widget.getTitle());
170+
Assert.assertEquals(content, widget.getContent());
171+
}
172+
146173
@Test
147174
public void setAnotherContentToNonEmptyWidget_correctContentIsSet() {
148175
DashboardWidget widget = getNewWidget();

0 commit comments

Comments
 (0)