Skip to content

Commit

Permalink
refactor: throw exception when setting and getting visibility (#6658)
Browse files Browse the repository at this point in the history
* refactor: throw exception when setting and getting visibility

* refactor: always return true when isvisible is called

* refactor: make section and widget return true for isvisible
  • Loading branch information
ugur-vaadin committed Oct 10, 2024
1 parent cd72fd8 commit 6f16553
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,21 @@ public Stream<Component> getChildren() {
return childrenComponents.stream();
}

/**
* @throws UnsupportedOperationException
* Dashboard does not support setting visibility
*/
@Override
public void setVisible(boolean visible) {
throw new UnsupportedOperationException(
"Dashboard does not support setting visibility");
}

@Override
public boolean isVisible() {
return true;
}

@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ public void removeFromParent() {
getParent().ifPresent(parent -> ((Dashboard) parent).remove(this));
}

/**
* @throws UnsupportedOperationException
* Dashboard section does not support setting visibility
*/
@Override
public void setVisible(boolean visible) {
throw new UnsupportedOperationException(
"Dashboard section does not support setting visibility");
}

@Override
public boolean isVisible() {
return true;
}

private void doRemoveAll() {
new ArrayList<>(widgets).forEach(this::doRemoveWidget);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ public void setHeader(Component header) {
SlotUtils.setSlot(this, "header", header);
}

/**
* @throws UnsupportedOperationException
* Dashboard widget does not support setting visibility
*/
@Override
public void setVisible(boolean visible) {
throw new UnsupportedOperationException(
"Dashboard widget does not support setting visibility");
}

@Override
public boolean isVisible() {
return true;
}

private void notifyParentDashboardOrSection() {
getParent().ifPresent(parent -> {
if (parent instanceof Dashboard dashboard) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,34 @@ public void setDashboardEditable_removeWidget_widgetIsRemoved() {
Assert.assertFalse(actualNodeIds.contains(nodeIdToBeRemoved));
}

@Test
public void setDashboardVisibility_exceptionIsThrown() {
Assert.assertThrows(UnsupportedOperationException.class,
() -> dashboard.setVisible(false));
Assert.assertThrows(UnsupportedOperationException.class,
() -> dashboard.setVisible(true));
}

@Test
public void setDashboardSectionVisibility_exceptionIsThrown() {
DashboardSection section = dashboard.addSection();
Assert.assertThrows(UnsupportedOperationException.class,
() -> section.setVisible(false));
Assert.assertThrows(UnsupportedOperationException.class,
() -> section.setVisible(true));
}

@Test
public void getDashboardVisibility_returnsTrue() {
Assert.assertTrue(dashboard.isVisible());
}

@Test
public void getSectionVisibility_returnsTrue() {
DashboardSection section = dashboard.addSection();
Assert.assertTrue(section.isVisible());
}

private void fireItemRemovedEvent(int nodeId) {
ComponentUtil.fireEvent(dashboard,
new DashboardItemRemovedEvent(dashboard, false, nodeId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,19 @@ public void setContentToWidgetWithHeader_contentAndHeaderCorrectlyRetrieved() {
Assert.assertEquals(content, widget.getContent());
Assert.assertEquals(header, widget.getHeader());
}

@Test
public void setWidgetVisibility_exceptionIsThrown() {
DashboardWidget widget = new DashboardWidget();
Assert.assertThrows(UnsupportedOperationException.class,
() -> widget.setVisible(false));
Assert.assertThrows(UnsupportedOperationException.class,
() -> widget.setVisible(true));
}

@Test
public void getWidgetVisibility_returnsTrue() {
DashboardWidget widget = new DashboardWidget();
Assert.assertTrue(widget.isVisible());
}
}

0 comments on commit 6f16553

Please sign in to comment.