From dc196546c6e7de96b6d3027bd3a0509e71090ed9 Mon Sep 17 00:00:00 2001 From: Dmitrij Abolichin Date: Fri, 9 Oct 2015 01:21:44 +0300 Subject: Fix replacing of currently selected Tab (#14252) Change-Id: I49a86d2fceac233fdfd9e31d8ade519b9f8460b6 --- .../server/component/tabsheet/TabSheetTest.java | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'server/tests') diff --git a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetTest.java b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetTest.java index 29f12fa4b6..a45b2c5587 100644 --- a/server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/tabsheet/TabSheetTest.java @@ -12,6 +12,8 @@ import org.junit.Test; import com.vaadin.ui.Component; import com.vaadin.ui.Label; import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.SelectedTabChangeEvent; +import com.vaadin.ui.TabSheet.SelectedTabChangeListener; import com.vaadin.ui.TabSheet.Tab; public class TabSheetTest { @@ -221,4 +223,64 @@ public class TabSheetTest { assertEquals("description", tab1.getDescription()); assertEquals(1, tabSheet.getTabPosition(tabSheet.getTab(lbl3))); } + + @Test + public void testSelectedTabChangeEvent_whenComponentReplaced() { + + // given + final class SelectedTabExpectedComponentListener + implements SelectedTabChangeListener { + + private Component actualComponent; + + @Override + public void selectedTabChange(SelectedTabChangeEvent event) { + actualComponent = event.getTabSheet().getSelectedTab(); + + } + + public void assertActualComponentIs(Component expectedComponent) { + assertEquals(expectedComponent, actualComponent); + actualComponent = null; + } + } + TabSheet tabSheet = new TabSheet(); + final Label lbl1 = new Label("aaa"); + final Label lbl2 = new Label("bbb"); + final Label lbl3 = new Label("ccc"); + final Label lbl4 = new Label("ddd"); + tabSheet.addComponent(lbl1); + tabSheet.addComponent(lbl2); + tabSheet.addComponent(lbl3); + tabSheet.setSelectedTab(lbl2); + SelectedTabExpectedComponentListener listener = new SelectedTabExpectedComponentListener(); + tabSheet.addSelectedTabChangeListener(listener); + + // when selected tab is replaced with new Component + tabSheet.replaceComponent(lbl2, lbl4); + + // then + listener.assertActualComponentIs(lbl4); + assertEquals(lbl4, tabSheet.getSelectedTab()); + + // when not selected tab is replaced with new Component + tabSheet.replaceComponent(lbl1, lbl2); + + // then + assertEquals(lbl4, tabSheet.getSelectedTab()); + + // when not selected tab is replaced with existing Component + tabSheet.replaceComponent(lbl2, lbl3); + + // then + assertEquals(lbl4, tabSheet.getSelectedTab()); + + // when selected tab is replaced with existing Component (locations are + // just swapped) + tabSheet.replaceComponent(lbl4, lbl3); + + // then + listener.assertActualComponentIs(lbl3); + assertEquals(lbl3, tabSheet.getSelectedTab()); + } } -- cgit v1.2.3