summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlia Motornyi <elmot@vaadin.com>2018-07-19 15:32:05 +0300
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-07-30 16:45:46 +0300
commitfd271589bc71b5d02e250ef5fb514fea03f9adc8 (patch)
tree8d8eb819d3848b372edfcae0810f4935354a8b86
parentb3e5864793bace6d0b05eef9b736997d045e3541 (diff)
downloadvaadin-framework-fd271589bc71b5d02e250ef5fb514fea03f9adc8.tar.gz
vaadin-framework-fd271589bc71b5d02e250ef5fb514fea03f9adc8.zip
Fix removal tabsheets if last one is selected (#11070)
Fixes #10925 (cherry picked from commit de42456)
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VTabsheet.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetCloseSelectedTabs.java35
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetCloseSelectedTabsTest.java30
3 files changed, 66 insertions, 3 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java
index e77e683d5b..123f89bb36 100644
--- a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java
+++ b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java
@@ -630,7 +630,7 @@ public class VTabsheet extends VTabsheetBase
for (int i = oldPosition - 1; i >= 0; i--) {
Tab tab = getTab(i);
- if (!tab.isHiddenOnServer()) {
+ if (tab != null && !tab.isHiddenOnServer()) {
return i;
}
}
@@ -1584,8 +1584,6 @@ public class VTabsheet extends VTabsheetBase
*
* @param blurSource
* the source.
- * @param focusedTabProvider
- * provides the current focused tab.
*/
public BlurCommand(Tab blurSource) {
this.blurSource = blurSource;
diff --git a/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetCloseSelectedTabs.java b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetCloseSelectedTabs.java
new file mode 100644
index 0000000000..1cfea46201
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetCloseSelectedTabs.java
@@ -0,0 +1,35 @@
+package com.vaadin.tests.components.tabsheet;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.TabSheet;
+
+public class TabsheetCloseSelectedTabs extends AbstractTestUI {
+
+ private TabSheet tabsheet = new TabSheet();
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ generateTabs();
+ tabsheet.setSizeFull();
+ addComponent(tabsheet);
+ addButton("Select last tab", event -> {
+ tabsheet.setSelectedTab(tabsheet.getComponentCount() - 1);
+ });
+ addButton("Remove all tabs", event -> {
+ while (tabsheet.getComponentCount() > 0) {
+ tabsheet.removeTab(tabsheet.getTab(0));
+ }
+ });
+
+ }
+
+ private void generateTabs() {
+ tabsheet.removeAllComponents();
+ for (int i = 0; i < 100; ++i) {
+ tabsheet.addTab(new Panel(), "Tab" + i);
+ }
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetCloseSelectedTabsTest.java b/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetCloseSelectedTabsTest.java
new file mode 100644
index 0000000000..8116548326
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetCloseSelectedTabsTest.java
@@ -0,0 +1,30 @@
+package com.vaadin.tests.components.tabsheet;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TabSheetElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * Tests that tabsheet's scroll button are rendered correctly in Chameleon
+ * theme.
+ *
+ * Ticket #12154
+ *
+ * @author Vaadin Ltd
+ */
+public class TabsheetCloseSelectedTabsTest extends SingleBrowserTest {
+
+ @Test
+ public void deleteSelectedTab() {
+ openTestURL();
+ $(ButtonElement.class).caption("Select last tab").first().click();
+ assertElementPresent(By.className("v-tabsheet-tabitem"));
+ $(TabSheetElement.class).first().waitForVaadin();
+ $(ButtonElement.class).caption("Remove all tabs").first().click();
+ assertElementNotPresent(By.className("v-tabsheet-tabitem"));
+ }
+}