Skip to content

Commit

Permalink
feat: add constructor overloads for dashboard widget (#6841)
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur-vaadin authored Nov 20, 2024
1 parent 890ffe3 commit e6ebd25
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,51 @@ public class DashboardWidget extends Component {

private boolean featureFlagEnabled;

/**
* Creates an empty widget.
*/
public DashboardWidget() {
this(null, null);
}

/**
* Creates a widget with the specified title.
*
* @param title
* the title to set
*/
public DashboardWidget(String title) {
this(title, null);
}

/**
* Creates a widget with the specified content.
*
* @param content
* the content to set
*/
public DashboardWidget(Component content) {
this(null, content);
}

/**
* Creates a widget with the specified title and content.
*
* @param title
* the title to set
* @param content
* the content to set
*/
public DashboardWidget(String title, Component content) {
super();
if (title != null) {
setTitle(title);
}
if (content != null) {
setContent(content);
}
}

/**
* Returns the title of the widget.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public void setTitle_returnsCorrectTitle() {
Assert.assertEquals(valueToSet, widget.getTitle());
}

@Test
public void setTitleInConstructor_returnsCorrectTitle() {
var valueToSet = "New title";
var widget = new DashboardWidget(valueToSet);
widget.setFeatureFlagEnabled(true);
widget.setTitle(valueToSet);
Assert.assertEquals(valueToSet, widget.getTitle());
}

@Test
public void setTitleNull_returnsEmptyTitle() {
DashboardWidget widget = getNewWidget();
Expand Down Expand Up @@ -143,6 +152,24 @@ public void setContentToEmptyWidget_correctContentIsSet() {
Assert.assertEquals(content, widget.getContent());
}

@Test
public void setContentInConstructor_correctContentIsSet() {
var content = new Div();
var widget = new DashboardWidget(content);
widget.setFeatureFlagEnabled(true);
Assert.assertEquals(content, widget.getContent());
}

@Test
public void setTitleAndContentInConstructor_correctValuesAreSet() {
var title = "New title";
var content = new Div();
var widget = new DashboardWidget(title, content);
widget.setFeatureFlagEnabled(true);
Assert.assertEquals(title, widget.getTitle());
Assert.assertEquals(content, widget.getContent());
}

@Test
public void setAnotherContentToNonEmptyWidget_correctContentIsSet() {
DashboardWidget widget = getNewWidget();
Expand Down

0 comments on commit e6ebd25

Please sign in to comment.