Skip to content

Commit

Permalink
refactor: rename header apis and use header content slot (#6683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur-vaadin committed Oct 10, 2024
1 parent 9ded572 commit c56092b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public DashboardWidgetPage() {
DashboardWidget widget1 = new DashboardWidget();
widget1.setTitle("Widget 1");
widget1.setContent(new Div("Some content"));
widget1.setHeader(new Span("Some header"));
widget1.setHeaderComponent(new Span("Some header"));
widget1.setId("widget-1");

DashboardWidget widget2 = new DashboardWidget();
Expand Down Expand Up @@ -89,7 +89,7 @@ public DashboardWidgetPage() {
updateHeaderOfTheFirstWidget.addClickListener(click -> {
List<DashboardWidget> widgets = dashboard.getWidgets();
if (!widgets.isEmpty()) {
widgets.get(0).setHeader(new Span("Updated header"));
widgets.get(0).setHeaderComponent(new Span("Updated header"));
}
});
updateHeaderOfTheFirstWidget.setId("update-header-of-the-first-widget");
Expand All @@ -99,7 +99,7 @@ public DashboardWidgetPage() {
removeHeaderOfTheFirstWidget.addClickListener(click -> {
List<DashboardWidget> widgets = dashboard.getWidgets();
if (!widgets.isEmpty()) {
widgets.get(0).setHeader(null);
widgets.get(0).setHeaderComponent(null);
}
});
removeHeaderOfTheFirstWidget.setId("remove-header-of-the-first-widget");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,25 @@ public void setContent(Component content) {
}

/**
* Gets the component in the header slot of this widget.
* Gets the component in the header content slot of this widget.
*
* @return the header component of this widget, or {@code null} if no header
* component has been set
*/
public Component getHeader() {
return SlotUtils.getChildInSlot(this, "header");
public Component getHeaderComponent() {
return SlotUtils.getChildInSlot(this, "header-content");
}

/**
* Sets the component in the header slot of this widget, replacing any
* existing header component.
* Sets the component in the header content slot of this widget, replacing
* any existing header component.
*
* @param header
* the component to set, can be {@code null} to remove existing
* header component
*/
public void setHeader(Component header) {
SlotUtils.setSlot(this, "header", header);
public void setHeaderComponent(Component header) {
SlotUtils.setSlot(this, "header-content", header);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,59 +173,59 @@ public void setNullContentToNonEmptyWidget_contentIsRemoved() {
@Test
public void defaultHeaderIsNull() {
DashboardWidget widget = new DashboardWidget();
Assert.assertNull(widget.getHeader());
Assert.assertNull(widget.getHeaderComponent());
}

@Test
public void setHeaderToEmptyWidget_correctHeaderIsSet() {
Div header = new Div();
DashboardWidget widget = new DashboardWidget();
widget.setHeader(header);
Assert.assertEquals(header, widget.getHeader());
widget.setHeaderComponent(header);
Assert.assertEquals(header, widget.getHeaderComponent());
}

@Test
public void setAnotherHeaderToNonEmptyWidget_correctHeaderIsSet() {
DashboardWidget widget = new DashboardWidget();
widget.setHeader(new Div());
widget.setHeaderComponent(new Div());
Span newHeader = new Span();
widget.setHeader(newHeader);
Assert.assertEquals(newHeader, widget.getHeader());
widget.setHeaderComponent(newHeader);
Assert.assertEquals(newHeader, widget.getHeaderComponent());
}

@Test
public void setTheSameHeaderToNonEmptyWidget_correctHeaderIsSet() {
Div header = new Div();
DashboardWidget widget = new DashboardWidget();
widget.setHeader(header);
widget.setHeader(header);
Assert.assertEquals(header, widget.getHeader());
widget.setHeaderComponent(header);
widget.setHeaderComponent(header);
Assert.assertEquals(header, widget.getHeaderComponent());
}

@Test
public void setNullHeaderToNonEmptyWidget_headerIsRemoved() {
DashboardWidget widget = new DashboardWidget();
widget.setHeader(new Div());
widget.setHeader(null);
Assert.assertNull(widget.getHeader());
widget.setHeaderComponent(new Div());
widget.setHeaderComponent(null);
Assert.assertNull(widget.getHeaderComponent());
}

@Test
public void setNullHeaderToWidgetWithContent_contentIsNotRemoved() {
Div content = new Div();
DashboardWidget widget = new DashboardWidget();
widget.setContent(content);
widget.setHeader(null);
widget.setHeaderComponent(null);
Assert.assertEquals(content, widget.getContent());
}

@Test
public void setNullContentToWidgetWithHeader_headerIsNotRemoved() {
Div header = new Div();
DashboardWidget widget = new DashboardWidget();
widget.setHeader(header);
widget.setHeaderComponent(header);
widget.setContent(null);
Assert.assertEquals(header, widget.getHeader());
Assert.assertEquals(header, widget.getHeaderComponent());
}

@Test
Expand All @@ -234,20 +234,20 @@ public void setHeaderToWidgetWithContent_contentAndHeaderCorrectlyRetrieved() {
Span header = new Span();
DashboardWidget widget = new DashboardWidget();
widget.setContent(content);
widget.setHeader(header);
widget.setHeaderComponent(header);
Assert.assertEquals(content, widget.getContent());
Assert.assertEquals(header, widget.getHeader());
Assert.assertEquals(header, widget.getHeaderComponent());
}

@Test
public void setContentToWidgetWithHeader_contentAndHeaderCorrectlyRetrieved() {
Div content = new Div();
Span header = new Span();
DashboardWidget widget = new DashboardWidget();
widget.setHeader(header);
widget.setHeaderComponent(header);
widget.setContent(content);
Assert.assertEquals(content, widget.getContent());
Assert.assertEquals(header, widget.getHeader());
Assert.assertEquals(header, widget.getHeaderComponent());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public TestBenchElement getContent() {
*/
public TestBenchElement getHeader() {
Object header = executeScript(
"return Array.from(arguments[0].children).filter(child => child.slot === 'header')[0]",
"return Array.from(arguments[0].children).filter(child => child.slot === 'header-content')[0]",
this);
return header == null ? null : (TestBenchElement) header;
}
Expand Down

0 comments on commit c56092b

Please sign in to comment.