From 6b6863fb45d605d229e7b153220fe44197ed6d4b Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sun, 6 Apr 2014 16:25:21 +0300 Subject: [PATCH] Apply layout after remove tab in Accordion (#11366, #13423) Change-Id: Ia56729d2d533697bea78bdb1de6b2710e166893a --- .../ui/accordion/AccordionConnector.java | 1 + .../accordion/AccordionRemoveTab.java | 78 +++++++++++++++++++ .../accordion/AccordionRemoveTabTest.java | 59 ++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTab.java create mode 100644 uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTabTest.java diff --git a/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java b/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java index ce843dc22f..25c56ab745 100644 --- a/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java +++ b/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java @@ -59,6 +59,7 @@ public class AccordionConnector extends TabsheetBaseConnector implements } else if (getWidget().getOpenStackItem() != null) { getWidget().close(getWidget().getOpenStackItem()); } + getLayoutManager().setNeedsVerticalLayout(this); } @Override diff --git a/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTab.java b/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTab.java new file mode 100644 index 0000000000..86e718596e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTab.java @@ -0,0 +1,78 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.accordion; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Accordion; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet.Tab; +import com.vaadin.ui.VerticalLayout; + +/** + * Test UI for Accordion: tabs should stay selectable after remove tab. + * + * @since 7.2 + * @author Vaadin Ltd + */ +public class AccordionRemoveTab extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Accordion tabs = new Accordion(); + addComponent(tabs); + tabs.setHeight(300, Unit.PIXELS); + final VerticalLayout one = new VerticalLayout(); + one.setCaption("One"); + one.addComponent(new Label("On first tab")); + tabs.addTab(one); + VerticalLayout two = new VerticalLayout(); + two.setCaption("Two"); + two.addComponent(new Label("On second tab")); + tabs.addTab(two); + + tabs.setSelectedTab(two); + + VerticalLayout l = new VerticalLayout(); + l.addComponent(new Label("On third tab")); + Tab last = tabs.addTab(l); + last.setCaption("Three"); + + Button remove = new Button("Remove First"); + remove.addClickListener(new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + tabs.removeComponent(tabs.iterator().next()); + } + }); + + addComponent(remove); + } + + @Override + protected String getTestDescription() { + return "Tabs should stay selectable after remove tab."; + } + + @Override + protected Integer getTicketNumber() { + return 11366; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTabTest.java b/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTabTest.java new file mode 100644 index 0000000000..f5651e0ada --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTabTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.accordion; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for Accordion: tabs should stay selectable after remove tab. + * + * @since 7.2 + * @author Vaadin Ltd + */ +public class AccordionRemoveTabTest extends MultiBrowserTest { + + @Test + public void testRemoveTab() { + openTestURL(); + + WebElement button = driver.findElement(By.className("v-button")); + button.click(); + + checkFirstItemHeight("On second tab"); + + button.click(); + + checkFirstItemHeight("On third tab"); + } + + private void checkFirstItemHeight(String text) { + WebElement firstItem = driver.findElement(By + .className("v-accordion-item-first")); + WebElement label = firstItem.findElement(By.className("v-label")); + Assert.assertEquals("Unexpected text in first item", text, + label.getText()); + int height = firstItem.getSize().getHeight(); + WebElement accordion = driver.findElement(By.className("v-accordion")); + Assert.assertTrue("First item in accordion has unexpected height", + height > accordion.getSize().getHeight() / 2); + } + +} -- 2.39.5