summaryrefslogtreecommitdiffstats
path: root/tests/server-side/com/vaadin
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2012-06-11 14:17:13 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2012-06-11 14:17:13 +0300
commit1a5bf24356cbdc347fabcfe6ba92cfbf69df3c02 (patch)
treeeb055a39c6076c4ef54385d1ae508d2bbbf3b56d /tests/server-side/com/vaadin
parent937d371e62fad4fa3bfaeddd6bc64ff9ef7a6dc1 (diff)
parentecd02651e7a27b964515cfd41b956a82f2886f43 (diff)
downloadvaadin-framework-1a5bf24356cbdc347fabcfe6ba92cfbf69df3c02.tar.gz
vaadin-framework-1a5bf24356cbdc347fabcfe6ba92cfbf69df3c02.zip
Merge commit 'ecd026'
Conflicts: src/com/vaadin/ui/TreeTable.java
Diffstat (limited to 'tests/server-side/com/vaadin')
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java b/tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java
index 40d0ffd17d..0ef8ae5a76 100644
--- a/tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java
+++ b/tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java
@@ -2,6 +2,8 @@ package com.vaadin.tests.server.component.tabsheet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import java.util.Iterator;
@@ -158,4 +160,65 @@ public class TestTabSheet {
tabSheet.setSelectedTab(123);
assertEquals(tab1.getComponent(), tabSheet.getSelectedTab());
}
+
+ @Test
+ public void replaceComponent() {
+ TabSheet tabSheet = new TabSheet();
+ Label lbl1 = new Label("aaa");
+ Label lbl2 = new Label("bbb");
+ Label lbl3 = new Label("ccc");
+ Label lbl4 = new Label("ddd");
+
+ Tab tab1 = tabSheet.addTab(lbl1);
+ tab1.setCaption("tab1");
+ tab1.setClosable(true);
+ Tab tab2 = tabSheet.addTab(lbl2);
+ tab2.setDescription("description");
+ tab2.setEnabled(false);
+
+ // Replace component not in tabsheet with one already in tabsheet -
+ // should be no-op
+ tabSheet.replaceComponent(lbl3, lbl2);
+ assertEquals(2, tabSheet.getComponentCount());
+ assertSame(tab1, tabSheet.getTab(lbl1));
+ assertSame(tab2, tabSheet.getTab(lbl2));
+ assertNull(tabSheet.getTab(lbl3));
+
+ // Replace component not in tabsheet with one not in tabsheet either
+ // should add lbl4 as last tab
+ tabSheet.replaceComponent(lbl3, lbl4);
+ assertEquals(3, tabSheet.getComponentCount());
+ assertSame(tab1, tabSheet.getTab(lbl1));
+ assertSame(tab2, tabSheet.getTab(lbl2));
+ assertEquals(2, tabSheet.getTabPosition(tabSheet.getTab(lbl4)));
+
+ // Replace component in tabsheet with another
+ // should swap places, tab association should stay the same but tabs
+ // should swap metadata
+ tabSheet.replaceComponent(lbl1, lbl2);
+ assertSame(tab1, tabSheet.getTab(lbl1));
+ assertSame(tab2, tabSheet.getTab(lbl2));
+ assertEquals(false, tab1.isClosable());
+ assertEquals(true, tab2.isClosable());
+ assertEquals(false, tab1.isEnabled());
+ assertEquals(true, tab2.isEnabled());
+ assertEquals("description", tab1.getDescription());
+ assertEquals(null, tab2.getDescription());
+ assertEquals(3, tabSheet.getComponentCount());
+ assertEquals(1, tabSheet.getTabPosition(tabSheet.getTab(lbl1)));
+ assertEquals(0, tabSheet.getTabPosition(tabSheet.getTab(lbl2)));
+
+ // Replace component in tabsheet with one not in tabsheet
+ // should create a new tab instance for the new component, old tab
+ // instance should become unattached
+ // tab metadata should be copied from old to new
+ tabSheet.replaceComponent(lbl1, lbl3);
+ assertEquals(3, tabSheet.getComponentCount());
+ assertNull(tabSheet.getTab(lbl1));
+ assertNull(tab1.getComponent());
+ assertNotNull(tabSheet.getTab(lbl3));
+ assertEquals(false, tabSheet.getTab(lbl3).isEnabled());
+ assertEquals("description", tab1.getDescription());
+ assertEquals(1, tabSheet.getTabPosition(tabSheet.getTab(lbl3)));
+ }
}